Jump to content
  • Advertisement
Sign in to follow this  
Nevadaes

Best input system

This topic is 3535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I'm currently working on a small 3D application to know where I am with my programming skill. I want to make a box move by using the arrow keys, around in a 3D environement. To move the cube, I am currently using code like that:
if(keys[VK_UP])
{
	//forward
	z -= (float)cos(yrot * 0.017453292f) * 0.05f; 
	x -= (float)sin(yrot * 0.017453292f) * 0.05f;
}

where keys is an array to hold every key. It's working fine, but I was wondering, if I want to make a real game, should I use this method or use another one like DirectInput? If I need to use DirectInput, why do I need to use it? Is it for performance cost, or it just have more features? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Don't use direct input. It's slow, a pain to use and it doesn't offer any advantage over using windows messages manually.
You may later want to put your in a class to abstract the code, but the principle looks perfectly fine :)

Share this post


Link to post
Share on other sites
Telepathy would be ideal.

However, I tend to use the same approach as you, only my keys[] array would be stored in a class along with mouse input etc. By using a class you write yourself, you can keep platform/api-specific code outside of unrelated modules. That way, if you ever need to, you could switch the input backend to DirectInput, SDL, etc without affecting any other code. As a side note, Ive had nothing but trouble with SDL input so I recommend sticking with GetKeyboardState if thats what youre using.

Share this post


Link to post
Share on other sites
ok thanks a lot guys. Anyway I don't think I'm going to use DirectInput as I program in OpenGL :P Well then, going to write a class for it and see how it works.

Share this post


Link to post
Share on other sites
you could try writing an input manager that sits in your WinMain(), pass a pointer to your WndProc using a custom message, and on a WM_KEYDOWN or WM_KEYUP, pass the keycode to the input manager and handle the input in your main loop.

In fact you wouldn't even have to deal with it through the WndProc if you didn't want, just catch the message with your input manager just before before the dispatchmessage() call in your loop

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!