user8427875
user8427875

Reputation:

How to move an object in LWJGL?

So, ive currently made an LWJGL project and refactored most things the way I want, however now I am looking to move an object the way it should be done. So far the code I have creates a red square to the screen, but its a lot of code just for a square and im looking to do something like, square.moveRight(float x) or something like that, how would i go about this? Here is the code.

// Poll for MyWindow events. The key callback above will only be
        // invoked during this call.
        glfwPollEvents();


        glBegin(GL_QUADS);
        glColor4f(1,0,0,0);
        glVertex2f(-0.5f,0.5f);
        glVertex2f(0.5f,0.5f);
        glVertex2f(0.5f,-0.5f);
        glVertex2f(-0.5f,-0.5f);
        glEnd();

        myWindow.swapBuffers();

Upvotes: 0

Views: 407

Answers (1)

Kugel
Kugel

Reputation: 838

Take a look at model matrices: http://wiki.lwjgl.org/wiki/The_Quad_with_Projection,_View_and_Model_matrices.html below "Moving, rotating and scaling our object". Basically you create a new 4x4 identity matrix, multiply it by a translation matrix and pass it to LWJGL.

Upvotes: 1

Related Questions