Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to rotate an object around its own axis and not around the base coordinate's axis?
    primarykey
    data
    text
    <p>I am following the OpenGL es rotation examples from google to rotate a simple square (not a cube) on my Android App, for example this code: </p> <pre><code>gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f); //Z </code></pre> <p>It works fine if you only rotate around one axis.</p> <p>But if you rotate around one axis, and after that, you rotate around another axis, the rotation is not fair. I mean that the rotation is done around the axes of base (global) coordinate system and not the square's own coordinate system.</p> <p>EDIT with code for <strong>Shahbaz</strong></p> <pre><code>public void onDrawFrame(GL10 gl) { //Limpiamos pantalla y Depth Buffer gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); //Dibujado gl.glTranslatef(0.0f, 0.0f, z); //Move z units into the screen gl.glScalef(0.8f, 0.8f, 0.8f); //Escalamos para que quepa en la pantalla //Rotamos sobre los ejes. gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f); //Z //Dibujamos el cuadrado square.draw(gl); //Factores de rotación. xrot += xspeed; yrot += yspeed; } </code></pre> <p>Draw of the square:</p> <pre><code> public void draw(GL10 gl) { gl.glFrontFace(GL10.GL_CCW); //gl.glEnable(GL10.GL_BLEND); //Bind our only previously generated texture in this case gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); //Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); //Enable vertex buffer gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); //Draw the vertices as triangle strip gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3); //Disable the client state before leaving gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); //gl.glDisable(GL10.GL_BLEND); } </code></pre> <p>VERTEX BUFFER VALUES:</p> <pre><code>private FloatBuffer vertexBuffer; private float vertices[] = { -1.0f, -1.0f, 0.0f, //Bottom Left 1.0f, -1.0f, 0.0f, //Bottom Right -1.0f, 1.0f, 0.0f, //Top Left 1.0f, 1.0f, 0.0f //Top Right }; . . . public Square(int resourceId) { ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4); byteBuf.order(ByteOrder.nativeOrder()); vertexBuffer = byteBuf.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); . . . </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload