subpixel
Re: 3D orientation/rotation 101 help
Reply #4 - Feb 8th , 2010, 9:45am
This is an interesting question - one that I'm sure I'll want to answer for myself when as I start doing more 3D stuff. Not wanting to frustrate you any further, but have you considered that for an object to be "pointing" in the direction of its velocity, it can also spin around on that velocity-direction-axis and still be pointing in that direction? Which of those orientations do you want? Here's an idea: think of the earth, and how we typically divide it up; latitude (the flat slices stacked on top of each other) and longitude (the beachball or orange segments that run through the poles). Now, imagine a "unit sphere" (or earth with radius 1 unit). Your velocity vector can be normalised to be length 1 in the same direction. If we root this at the centre of the earth, our normalised velocity vector reaches to a point on the surface of the earth/sphere. If we look at the Earth side-on, we can imagine a unit circle centred on X-Y axes. We know what the Y-value is (it is the Y value of our normalised vector) and we need to work out what the "latitude" (angle from the equator) is. If you draw a sketch, you can probably figure this out. Then another step to work out what angle to rotate around the Y axis to get to the point on the latitude circle for the Z coordinate. Well, that may or may not work, and may also involve doing some tests to check which quadrant of various circles you're looking at... and since it isn't an 'elegant' way using vector maths, probably isn't the best! Your notion about V1 and V2 sounds reasonable (assuming your object is originally oriented "pointing" towards what you call "up"). The question is, though, how to use the quaternion (axis of rotation and angle of rotation) that you find? rotateX(), rotate(Y), rotate(Z) are (I think) implemented using a rotation axis vector with some lower-level call - eg OpenGL's glRotatef(angle, x, y, z) - which isn't mentioned in the usual Processing methods. -spxl