How does one go about implementing continuous movement with OpenGL, using something like SFML
So far I have managed to make my square object translate by 0.1. The square can translate to the left and to the right, but it can not move in either direction continuously, only once per key press. How can I make it so that the square can move continuously in one direction, if the user presses either the left or right key. Is a model matrix required? (Pretty new at this, so I do not know when one should use a model matrix)
C++ Code:
GLint trans_location = shader.getUniformLocation();
glm::vec3 Velocity;
glm::mat4x4 Identity(1.0f);
//Necessary Buffers are created
Main Loop:
shader.Use();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
Velocity = glm::vec3(0.1f, 0.0f, 0.0f);
glm::mat4 trans_matrix = glm::translate(Identity, Velocity);
glUniformMatrix4fv(trans_location, 1, GL_FALSE, glm::value_ptr(trans_matrix));
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
Velocity = glm::vec3(-0.1f, 0.0f, 0.0f);
glm::mat4 trans_matrix = glm::translate(Identity, Velocity);
glUniformMatrix4fv(trans_location, 1, GL_FALSE, glm::value_ptr(trans_matrix));
}
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
GLSL Vertex Shader:
#version 400 core
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;
out vec4 out_color;
uniform mat4 trans_matrix;
void main()
{
out_color = color;
gl_Position = trans_matrix * position ;
}