0

I have a 3D world that works well with a camera and game objects. When the camera 'renders' it positions the matrix in the location of the camera. To do this, I call the following code:

gl.glMultMatrixf(rotationArray,0);
gl.glTranslatef(position.getX(), position.getY(), position.getZ());

Now when each object gets rendered, I call this for each object. (Note that I push and pop the matrices appropriately)

gl.glTranslatef(position.getX(), position.getY(), position.getZ());
gl.glMultMatrixf(rotationArray,0);

Now my question comes into play of when I bring models into the world, I need certain Meshes to pivot not around the 0,0,0 point, but around a different point. I have an object called Mesh that has an ArrayList of submeshes. Each mesh (and submesh) have a pivot point location. (an x,y and z float).

Where do I translate the matricies so I pivot around the designated point? I've tried all sorts of combinations and nothing works!

Example:

gl.glTranslatef(position.getX(), position.getY(), position.getZ());                     
gl.glMultMatrixf(rotationArray,0);
gl.glTranslatef(pivotPoint.getX(),pivotPoint.getY(),pivotPoint.getZ()); 

and I've tried

gl.glTranslatef(pivotPoint.getX(),pivotPoint.getY(),pivotPoint.getZ());                     
gl.glMultMatrixf(rotationArray,0);
gl.glTranslatef(position.getX(), position.getY(), position.getZ());
4

1 回答 1

1

这归结为围绕任意点旋转。传统上,当您旋转对象时,通常会围绕对象的中心旋转它,但在这种情况下,您有一个单独的枢轴点。

围绕任意点旋转物体的过程是:

  1. 翻译者 -(RotationPoint)
  2. 旋转
  3. 翻译 +(RotationPoint)
于 2013-08-15T02:18:06.830 回答