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
{
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:
{
if(kb->IsKeyPress('s'))
position += glm::vec3(1.0 * getParent()->getEngine()->deltaTime);
}
Any idea to resolve this?