简体   繁体   English

C# XNA 矩阵 - 找出矩阵乘法后的当前位置

[英]C# XNA Matrices - find out the current locatin after matrix multiplication

i am making 3D Simulation of Solar System我正在制作 3D 模拟太阳系

for every planet i have an instance of class Celestial Body .对于每个行星,我都有一个 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 eg postion = new Vector3(70,0,0) position 是我的 vector3 变量,用于将物体置于轨道或距中心的半径处,例如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.但问题是我需要找到\得到我星球的position,在矩阵乘法之后,它在x,y,x坐标中被翻译到那里。

How To?如何? get the current X, Y, Z coordinates of my planet获取我星球的当前 X、Y、Z 坐标

the other option for me would be to use some maths formula that calculates a 2D circle for me.对我来说,另一个选择是使用一些数学公式为我计算二维圆。

I think what you're looking for is Matrix.Translation .我认为您正在寻找的是Matrix.Translation This gives you the x, y, z co-odinates of the matrix that it's called on in a Vector3 .这为您提供了在Vector3中调用的矩阵的 x、y、z 坐标。

So, to get the new position, you should use因此,要获得新的 position,您应该使用

Vector3 newPosition = world.Translation;

after your calculations.在你的计算之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM