1
votes

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.

I need the cube to rotate so the purple side is facing user

1
If you don't get an answer here, you might consider the Game Development Stack Exchange--they're good at iOS and graphics math.sblom
Good idea. I'll post there if I don't get any leads here.Steven Baughman
No, haven't touched the camera (and not sure it's even available with CoreAnimation).Steven Baughman

1 Answers

1
votes

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.