I'm using glfw's glfwGetTime() function to calculate my time between frames i.e deltaT but when I multiply my desired movement speed by deltaT, and subsequently put that product into my translate vector it moves the character extremely slow.
My fps is right now is around 1300fps average so deltaT should be around 800 microsecond, times my desired speed of 128 units/second I should be able to move my character from 0 to 336 in about 2.6 seconds. But for reference that operation is taking about 20 seconds at the moment.
glfwGetTime() returns a timestamp in seconds... never really seen this happen before if anyone has any idea or further insight about using deltas for input smoothing I would much appreciate.
This is the implementation function for taking a key event and updating the transform matrix.
void Layer::update(std::deque<Event>* eventStack, double deltaT) { float Vy{0.0f}; float Vx{0.0f}; std::deque<Event>::iterator it = eventStack->begin(); while(it != eventStack->end()) { if((*it).getKey() == GLFW_KEY_UP && ((*it).getAction() == GLFW_PRESS || (*it).getAction() == GLFW_REPEAT)) { Vy += 16.0f;//if specified key event is in stack, do something it = eventStack->erase(it++); //then erase the event from the stack, it's been handled } else if((*it).getKey() == GLFW_KEY_RIGHT && ((*it).getAction() == GLFW_PRESS || (*it).getAction() == GLFW_REPEAT)) { Vx += 16.0f;//if specified key event is in stack, do something it = eventStack->erase(it++); //then erase the event from the stack, it's been handled } else { it++; } } transformation = glm::translate(transformation, glm::vec3(Vx * deltaT, Vy * deltaT, 0.0f)); Vy = 0.0f; Vx = 0.0f; } And here is where I calculate my fps and deltaT
void Window::update() { glfwSwapBuffers(_window); glfwPollEvents(); double thisTime = glfwGetTime(); _deltaT = thisTime - _lastTime; _lastTime = thisTime; _elapsedTime += _deltaT; if(_elapsedTime >= 1) { std::stringstream ss; ss << "FPS: " << _frames; glfwSetWindowTitle(_window, ss.str().c_str()); _frames = 0; _elapsedTime = 0; } else { _frames++; } }
glfwGetTimereturns timestamps in seconds, yet you calculate a 800usdeltaT? Also, did you try writing down alldeltaTduring one second and see how they sum up? \$\endgroup\$