Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char** argv)
- {
- /*
- INIT AND OTHER STUFF SNIPPED OUT
- */
- double currentFrame = glfwGetTime();
- double lastFrame = currentFrame;
- double deltaTime;
- double a=0;
- double speed = 0.6;
- //Main loop
- while(true)
- {
- a++;
- currentFrame = glfwGetTime();
- deltaTime = currentFrame - lastFrame;
- lastFrame = currentFrame;
- /** I know that delta time is around 0.016 at my framerate **/
- //deltaTime = 0.016;
- x = sin( a * deltaTime * speed ) * 0.8f;
- y = cos( a * deltaTime * speed ) * 0.8f;
- display();
- if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
- break;
- }
- glfwTerminate();
- return 0;
- }
- void display()
- {
- glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- glUseProgram(playerProgram);
- glUniform3f(playerLocationUniform,x,y,z);
- glBindBuffer(GL_ARRAY_BUFFER, playerVertexBufferObject);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(0);
- glUseProgram(0);
- glfwSwapBuffers();
- }
- #define TAU (M_PI * 2.0)
- currentFrame = glfwGetTime();
- deltaTime = currentFrame - lastFrame;
- lastFrame = currentFrame;
- a += deltaTime * speed;
- // Optional, keep the cycle bounded to reduce precision errors
- // if you plan to leave this running for a long time...
- if( a > TAU ) a -= TAU;
- x = sin( a ) * 0.8f;
- y = cos( a ) * 0.8f;
Add Comment
Please, Sign In to add comment