PDA

View Full Version : Matrix rotation with offset

NecroDOME
21-02-2007, 01:30 PM
So I have 2 objects I want to rotate. from 1 I only know the D3DMatrix and position. Now I want the other mesh to "Stick" to it on my update function with an offset. So when object 1 is 40 units away on the X axis and I rotate object 2 90 degrees, object 1 should be 40 units on the y axis. (know what I mean?)

Huehnerschaender
21-02-2007, 02:06 PM
It seems to be the typical planet orbit problem :)

Lets say, the sun is the middle of your universe... so it's at 0,0,0

rotating the sun would be

clear worldmatrix
rotate worldmatrix // turn sun
draw sun

to let the earth turn around the sun it would be

clear the worldmatrix
translate worldmatrix // move earth to its distance from the sun
rotate worldmatrix // rotate the world around the sun
draw earth

letting the earth turn on it's own axis would be
clear the worldmatrix
rotate worldmatrix // rotate earth around its axis
translate worldmatrix // move world in position
draw earth

letting the earth turn around the sun, while its turning around its own axis would be
clear the worldmatrix
rotate worldmatrix // rotate world around its axis
translate worldmatrix // move it to distance
rotate worldmatrix // turn it around sun
draw earth

Now, if the sun is not at 0,0,0 but at 40,0,0

then according to the last step it would be
clear the worldmatrix
rotate worldmatrix // rotate world around its axis
translate worldmatrix // move it to distance
rotate worldmatrix // turn it around sun
translate worldmatrix(40,0,0) // move it to the sun
draw earth

It's all just a matter of the order in which you manipulate the worldmatrix.

Hope I understood your question right :)

Nitrogen
21-02-2007, 07:49 PM
Hey, nice explanation! Think you got the nail on the head there :)

WILL
21-02-2007, 09:30 PM
This would work great as a tutorial on 3D graphics with illustrations. :)

NecroDOME
22-02-2007, 07:57 AM
great explanation... but I wanna know how to calculate those things...

I already can position and rotate stuff... but I need to position the "earth" with an offset to the "sun" (and + rotation from the sun, like they are welded together)

Huehnerschaender
26-02-2007, 05:47 PM
Hmmm.... I think I don't understand you :)

The "earth" rotates around the sun... but with the rotation of the sun? Is this correct? Like a, lets say mountain on the earth?

It's all the same... No matter if things are "welded together or not.."

You know the position and rotation of "sun"... You need to know this, because you want your earth to move there and rotate exactly the same...

So what you need to do is:

ClearWorldMatrix;
Rotate matrix with SUNs rotation
Translate Matrix to suns position.
draw sun
ClearWorldMatrix;
Translate Matrix to the distance earth has from sun
Rotate matrix with SUNs rotation
Translate Matrix to suns position.
draw earth