Search code examples
androidopengl-estransformcube

OpenGL 3D Cube Rotation


So i have a 3D cube that and I have a matrix 3x3 that i transform to obtain an angle and an axis to use these as parameters in

gl.glRotatef(angle, x, y, z);

However, the cube does not rotate properly and it seems like the method

glTranslatef (float x, float y, float z)

as a huge importance but i dont really know what it does .. Here is the code :

@Override
public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);        
    gl.glLoadIdentity();

    gl.glTranslatef(0.0f, 0.0f, -10.0f);

    gl.glRotatef(angle, x, y, z);

    mCube.draw(gl);

}

angle, x, y and z are the values i get after transforming the matrix.

What am I doin wrong ?

Thank you.


Solution

  • What do you see when you run that program?

    Just to make sure, the definition for glRotatef is here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd368577(v=vs.85).aspx

    The 'angle' portion is in degrees. I've made the mistake of handing it radians a few times, and it appears that my object isn't rotating. Also, glTranslatef will move your object in the +/- xyz direction. Traditionally, +y is up, +x is right, and +z is into the screen. This can all change depending on a few different things, like your view matrix.