Rotation around non-origin
I''ve been trying to figure this question out for a few days now. I''m making a simple universe and I want to have the moon rotate around the earth. But with the D3DXMatrixRotationY() function, it rotates around the origin (I do believe). Do I have to translate to origin.x/y/z - position.x/y/z, rotate, and then translate back or can I do something else. Thanks in advance!
/*
I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/
You might be able to use the position of the moon relative to the earth as an equation instead of using the matrices to change the position?? I don''t know how much math you have but if you use polar coords you can set it up with
r = radius from earth center to moon center
moon x = r*Math.Cos(radians)
moon y = r*Math.Sin(radians)
If the moon is moving horizontally relative to the world coords then you''d use z instead of y for the second coord. You could also set it up to have motion vectors like particle systems use. If you have taken Calculus you will surely understand those ideas better. If you want more detail about that just ask.
r = radius from earth center to moon center
moon x = r*Math.Cos(radians)
moon y = r*Math.Sin(radians)
If the moon is moving horizontally relative to the world coords then you''d use z instead of y for the second coord. You could also set it up to have motion vectors like particle systems use. If you have taken Calculus you will surely understand those ideas better. If you want more detail about that just ask.
To rotate an object in place, translate it to the origin, rotate, and translate back to original pos. Assuming the earth is rotating around the sun, and the moon around the earth ... to rotate the moon, move earth to the origin (dragging moon with it), rotate moon around earth, and move both back.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement