Hey guys, here's a slightly more challenging question out of the usual silly easy questions I usually ask. [smile]
In my 2D game, I have a guy who has things orbiting his body...
0 0
0 0
0 ME 0
0 0
0 0
Currently, the objects rotate around his body like you see in the illustration. The objects rotate the body on the 'z' axis, which simply makes the objects rotate in a clockwise fashion. I'm using a variation of this formula to make the orbit effect happen:
Xnew = Xold*cos(theta) - Yold*sin(theta)
Ynew = Xold*sin(theta) + Yold*cos(theta)
And it looks pretty cool! However, I've enabled z-buffering in my 2D game to let me easily move 2D objects in front or behind other game objects. So what I'd like to do is modify my orbiting code to allow orbit rotation on multiple axis... Imagine the objects orbiting the guy in a clockwise rotation like they currently do, but also the entire rotating 'mass' slowly rotating around the guy along the Y and X axes. I can
almost do that by calling the above formula multiple times, for each axis:
Xnew = Xold*cos(theta) - Yold*sin(theta)
Ynew = Xold*sin(theta) + Yold*cos(theta)
Xnew = Xold*cos(theta) - Zold*sin(theta)
Znew = Xold*sin(theta) + Zold*cos(theta)
Ynew = Yold*cos(theta) - Zold*sin(theta)
Znew = Yold*sin(theta) + Zold*cos(theta)
The folly with the above method is that the orbiting mass starts rotating clockwise, but as the other axes are rotated the orbiting mass slows and sometimes starts to rotate in the opposite direction. It's a cool effect too, I guess, but not the effect I want.
Would any of you kind guys and gals help this poor programmer to consolidate the above method into one formula, and help me to get the entities to orbit at a constant speed as the other axes are modified? Thanks in advance for the help! [smile]