C# XNA Matrices - 使用矩阵计算月球绕轴的旋转
我正在构建 3D 模拟。
我正在使用一个类来显示太阳、行星和行星。具有不同大小、纹理、速度和轨道的月亮。这是我的代码,它执行计算旋转+旋转的神奇工作
world = Matrix.CreateScale(size,size,size) * Matrix.CreateTranslation(0,0,0) *
Matrix.CreateRotationY(rotation) *
Matrix.CreateTranslation(position) *
Matrix.CreateRotationY(revolution);
- 尺寸是我的变量,用于单独缩放对象
- 旋转是我的变量,用于围绕其自己的轴旋转对象
- >position 是我将行星定位在轨道上的变量,new Vector3(240,0,0)
- revolution 是我将行星围绕原点旋转的变量
,现在我想要显示卫星围绕地球和其他行星,但我只是不知道该怎么做。就矩阵乘法而言。
复杂的是月球绕着一颗行星公转,而这颗行星不在原点并且总是在变化。
怎么做?
I am building a 3D simulation.
I am using one class to display sun, planets & moon with different size, texture, speed and orbit. Here's my code which does the magic job of calculating rotation + revolution
world = Matrix.CreateScale(size,size,size) * Matrix.CreateTranslation(0,0,0) *
Matrix.CreateRotationY(rotation) *
Matrix.CreateTranslation(position) *
Matrix.CreateRotationY(revolution);
- size is my variable to scale the object individually
- rotation is my variable to rotate the object around its own axis
- position is my variable to position the planet on orbit, new Vector3(240,0,0)
- revolution is my variable to revolve the planet around the origin
now i want the display the moons around earth and around other planets but i just can't figure out how to do it. In terms of Matrix Multiplication.
The complication is the moon's revolution is around a planet which is not on origin and is always changing.
How to do it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的
Draw
方法中,在绘制了您想要绕其运行的行星/月球之后:因此,在您的
Update
方法中,您可以执行以下操作:将
orbitAxis
定义为Vector3
。orbitDistance
、orbitRotation
、orbitScale
和orbitSpin
作为float
。In your
Draw
method, after you've drawn the planet/moon that you want to orbit around:So, in your
Update
method, you can then do:I've defined
orbitAxis
as aVector3
.orbitDistance
,orbitRotation
,orbitScale
andorbitSpin
asfloat
's.我想通了...
将原点翻译为母行星的当前位置
并在更新方法中继续执行
我在这里所做的是让月球围绕原点(太阳)旋转,但是我将其起源翻译为任何行星的当前位置......这对我有用。
i figured it out...
Translate The Origin to the Parent planet's Current Location
and keep doing it in the update method
what i am doing here is that i m revolving the moon around the origin (Sun) but i translate its origin to any planet's current location... this worked for me.