Sunday, March 22, 2009

Sphere Rotation

The first thing I did after getting all the Papervision and general project setup is creating a Sphere and make it rotate based on users input (Mouse RollOver) over the same Sphere surface.

Using InteractiveScene3DEvent.renderHitData object we can tell the X and Y values of where the mouse hit on the surface of the sphere. These values are then used to affect the rotationX and rotationY properties of the Sphere.

In the MouseOver and/or MouseMove handler:

var locX:Number = e.renderHitData.x-x;
var locY:Number = e.renderHitData.y-y;

sphere.rotationX -= locY/10;
sphere.rotationY += locX/10;

Divided by 10 just because the values are too big otherwise.




You'll recognize a problem with this way of doing this though. Rotations are done around the sphere's local axis X & Y. and what I really need is a rotation over a global axis based on a vertex defined by the user interaction with the surface of the sphere. This is what I'll work on next.

No comments:

Post a Comment