Is it possible to rotate an object around its own axis and not around the base coordinate's axis?

后端 未结 4 1424
难免孤独
难免孤独 2020-12-02 13:49

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:

gl.glRotatef(xro         


        
4条回答
  •  时光取名叫无心
    2020-12-02 14:24

    I know next-to-nothing about openGL, but I imagine translating to 0, rotating and then translating back should work...

    gl.glTranslatef(-x, -y, -z);
    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
    gl.glTranslatef(x, y, z);
    

提交回复
热议问题