Rotate 3D cube so side is facing user

How do I figure out the new angle and rotation vectors for the most visible side of the cube?

Why: The user can rotate cube, but when finished I'd like the cube to snap to a side facing the user.

What: I'm currently using CoreAnimation in iOS to do the rotation with CATransform3D. I have the current angle and the rotation vectors so I can do this:

CATransform3DMakeRotation(angle, rotationVector[0], rotationVector[1], rotationVector[2]);

Additional Info: I'm currently using Bill Dudney's Trackball code to generate movement and calculate angle and rotation vector.

我需要立方体旋转,以便紫色的一面朝向用户


Your camera's lookAt vector - probably {0, 0, 1} - determines what side is closer to user.

You need to create normal for every side of the cube. Then rotate them in same way as cube. After that, calculate the angle between every normal vector and the camera lookAt vector using a dot product. Whichever normal has the largest dot product is the side closest to the camera.

链接地址: http://www.djcxy.com/p/81806.html

上一篇: 方向矢量的旋转矩阵(向前,向上,向右)

下一篇: 旋转3D立方体,使其面向用户