开发者

Android OpenGL ES rotate a cube on x, y, z points, and the cube's center

开发者 https://www.devze.com 2023-02-05 14:25 出处:网络
I want to: rotate my cube on a x,y,z center point. And t开发者_StackOverflow中文版he second way: i want to rotate my cube on my cube\'s center points. How i can do this?Assuming you have a OpenGL ES G

I want to: rotate my cube on a x,y,z center point. And t开发者_StackOverflow中文版he second way: i want to rotate my cube on my cube's center points. How i can do this?


Assuming you have a OpenGL ES GL10 object called gl, in your ondraw or similar:

  // Push matrix so we can pop later
  gl.glPushMatrix();

  // Translate to the center of your cube
  // Or to whatever xyz point you want
  glTranslatef(centreX, centreY, 0);

  // rotation = degrees to rotate
  // x,y,z are unit vectors for rotation to take place
  // I.E  x=0.0 y=0.0 z=0.0 would rotate around the z-axis
  gl.glRotatef(rotation, x, y, z);


  // CUBE DRAWING FUNCTION HERE


  // Popmatrix so we undo translation and rotation for
  // rest of opengl calls
  gl.glPopMatrix();

I suggest looking at the android ports of the nehe opengl tutorials as they are brilliant guides to starting opengl with android.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号