Jump to content

  • Log In with Google      Sign In   
  • Create Account


glutKeyboardFunc takes 5 frames to update state


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 15 March 2013 - 05:27 AM

Hi!
I have the keyboard class that initialize the glutKeyboards functions. When I release a key, the program takes five frames to detect. I have another class that when I push the key 's', it add a vec3(1.0,1.0,1.0) to the variable position. The problem is that in each frame from that I press key 's' until it detects that I released it adds to the variable position the vector vec3(1.0,1.0,1.0). The update() function is called before the Draw () function in the render method

KeyboardDevice.cpp

 

 

void KeyboardDevice::keySpecialUp(int key, int x, int y)
{
keySpecialStates[key] = false;
timeReleased = clock();
keySpecialReleaseStates[key] = true; // Set the state of the current special key recently pressed
}
 
bool KeyboardDevice::IsKeyPress(unsigned char key)
{
return keyStates[key];
}
bool KeyboardDevice::IsKeyUp(unsigned char key)
{
double now = clock()/(double)CLOCKS_PER_SEC;
double last = timeReleased /(double)CLOCKS_PER_SEC;
if(now-last < 1 && keyReleaseStates[key] == true)
{
keyReleaseStates[key] = false;
return true;
}
return false;
}

Actor.cpp:

void Cube::Update(void)
{
if(kb->IsKeyPress('s'))
position += glm::vec3(1.0 * getParent()->getEngine()->deltaTime);
}

Any idea to resolve this?



Sponsor:

#2 blueshogun96   Crossbones+   -  Reputation: 818

Like
0Likes
Like

Posted 15 March 2013 - 08:09 PM

GLUT's keyboard input functions are generally too slow for game related purposes.  You'd be best off using your OS specific input APIs which are much faster and reliable.  Assuming you're using Windows, try using GetAsyncKeyState.  I personally recommend using SDL over GLUT when necessary, especially when it comes to input.

 

Shogun.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


#3 EddieV223   Members   -  Reputation: 1394

Like
0Likes
Like

Posted 16 March 2013 - 12:08 AM

Are you using GLUT or freeGLUT?  If your using GLUT, cease and desist.  GLUT is old and not supported and not free.  Start using freeGLUT immediately.  


If this post or signature was helpful and/or constructive please give rep.

 

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

 

// Easy to learn 2D Game Library c++

SFML2.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

 


#4 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 16 March 2013 - 05:18 AM

I am using Freeglut.



#5 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 16 March 2013 - 05:20 AM

I am thinking to change to GLFW. Is reading inputs faster?



#6 EddieV223   Members   -  Reputation: 1394

Like
0Likes
Like

Posted 16 March 2013 - 08:55 AM

I use glfw it seems to work fine.  


If this post or signature was helpful and/or constructive please give rep.

 

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

 

// Easy to learn 2D Game Library c++

SFML2.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

 


#7 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 17 March 2013 - 06:40 AM

Ok, thanks for your answers






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS