2
votes

i am making 3D Simulation of Solar System

for every planet i have an instance of class Celestial Body. I am using the following code for revolution and rotation of sun, planets & their moons.

world = Matrix.CreateTranslation(0,0,0) * Matrix.CreateRotationY(rotation) * Matrix.CreateTranslation(position) * Matrix.CreateRotationY(revolution); 
  • rotation is my float variable for rotation of planet around its own axis
  • revolution is my float variable for revolution of planet in orbit
  • position is to my vector3 variable to put the body in orbit or at its radius from center e.g postion = new Vector3(70,0,0)

Now it works really fine.

But the problem is i need to locate \ get the position of my planet, to where it has been translated after the Matrix multiplication literally in x,y,x co-ordinates.

How To ? get the current X , Y , Z coordinates of my planet

the other option for me would be to use some maths formula that calculates a 2D circle for me.

1
i am sorry i am unaware of world.Translation i.e Matrix.translation... please teachMoon
I added an answer with a few more details. Let me know if you need more.fire.eagle

1 Answers

5
votes

I think what you're looking for is Matrix.Translation. This gives you the x, y, z co-odinates of the matrix that it's called on in a Vector3.

So, to get the new position, you should use

Vector3 newPosition = world.Translation;

after your calculations.