Cilenco
Cilenco

Reputation: 7117

OpenGL ES move object

I'm writing an Android OpenGL ES 1.0 game. In this I want to move an object in the game with this method:

public void move(float dx, float dy, float dz)
{
    for(int i=0; i < objectVerts.length; i+=3)
    {
        objectVerts[i + 0] += dx;
        objectVerts[i + 1] += dy;
        objectVerts[i + 2] += dz;
    }
}

My render method looks like this:

gl.glViewport(0, 0, getViewportWidth(), getViewportHeight());
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
float aspectRatio = (float)activity.getViewportWidth() / activity.getViewportHeight();
GLU.gluPerspective(gl, 67, aspectRatio, 1, 100);

gl.glMatrixMode( GL10.GL_MODELVIEW );
gl.glLoadIdentity();
GLU.gluLookAt(gl, 0, 0, 1.5f, 0, 0, 0, 0, 1, 0);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, objectVerts.length / 3);

But if I call the moves method the object does not move or change its position. Any ideas why?

Upvotes: 1

Views: 715

Answers (1)

Prabindh
Prabindh

Reputation: 3504

You will have to re-upload the new vertices to the GL engine (using glVertexPointer and redraw using glDrawArrays). The move function runs on the CPU, and the GL engine has no way to know that the vertices have changed.

Upvotes: 1

Related Questions