0

我按以下顺序进行了 3 次转换,并使用以下变量:

glTranslate(dirX, dirY, dirZ);
glRotate(angleX, 1, 0, 0);
glRotate(angleY, 0, 1, 0);

有了这些,我可以在 3D 中转换我的 ModelView,实现多种效果(围绕空间平移对象、围绕其中心旋转对象、从原点放大和缩小)。

使用相同的变量,并使用gluLookAt(),我想实现最后两个(围绕对象中心旋转,从原点缩放

4

1 回答 1

1
target = object_position
pos.x = zoom * sin(phi) * cos(theta);
pos.y = zoom * cos(phi);
pos.z = zoom * sin(phi) * sin(theta);

pos += target;

gluLookAt(pos, target, vec3(0, 1, 0)); // up vector is fixed...

上面的代码创建了一个“相机”,它正在查看对象中心并且可以旋转(使用球面坐标)。

http://mathworld.wolfram.com/SphericalCoordinates.html

于 2013-05-08T06:56:36.233 回答