使对象轨道成为DirectX中的固定点? [英] Making an object orbit a fixed point in directx?

查看:186
本文介绍了使对象轨道成为DirectX中的固定点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使一个非常简单的对象围绕3dspace中的固定点旋转。

I am trying to make a very simple object rotate around a fixed point in 3dspace.

基本上,我的对象是从单个D3DXVECTOR3创建的,该D3DXVECTOR3指示对象相对于单个常数点的当前位置。让我们说0,0,0。

Basically my object is created from a single D3DXVECTOR3, which indicates the current position of the object, relative to a single constant point. Lets just say 0,0,0.

我已经根据当天的比赛时间计算了角度。

I already calculate my angle based on the current in game time of the day.

但是我该如何将该角度应用于该位置,以便它旋转呢?

But how can i apply that angle to the position, so it will rotate?

:(?

抱歉,对于Directx来说还很陌生。

Sorry im pretty new to Directx.

推荐答案

所以您在尝试吗?

如果是,那么就假设您的天体是一个以(0,0,0)为中心的球体。

If so then one assumes your celestial object is something like a sphere that has (0,0,0) as its center point.

可能将其旋转到最简单的位置是执行以下操作

Probably the easiest way to rotate it into position is to do something like the following

D3DXMATRIX matRot;
D3DXMATRIX matTrans;
D3DXMatrixRotationX( &matRot, angle );
D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, orbitRadius );
D3DXMATRIX matFinal = matTrans * matRot;

然后将该矩阵设置为您的世界矩阵。

Then Set that matrix as your world matrix.

它的作用是创建一个旋转矩阵,使对象绕XAxis(即,在YZ平面中)旋转角度;然后创建一个矩阵,将其推出到适当的解放军ce在0角处(orbitRadius作为平移调用中的第三个参数可能更好,具体取决于您的零点位置)。最后一行将这两个矩阵相乘。矩阵乘法是不可交换的(即M1 * M2!= M2 * M1)。上面所做的就是沿Z轴移动对象orbitRadius单位,然后绕着点(0,0,0)旋转。您可以考虑旋转手中的对象。如果orbitRadius是从肘部到手的距离,则绕肘部的任何旋转(在0,0,0处)都会在空中形成弧形。

What it does is it creates a rotation matrix to rotate the object by "angle" around the XAxis (ie in the Y-Z plane); It then creates a matrix that pushes it out to the appropriate place at the 0 angle (orbitRadius may be better off as the 3rd parameter in the translation call, depending on where your zero point is). The final line multiplies these 2 matrices together. Matrix multiplications are non commutative (ie M1 * M2 != M2 * M1). What the above does is move the object orbitRadius units along the Z-axis and then it rotates that around the point (0, 0, 0). You can think of rotating an object that is held in your hand. If orbitRadius is the distance from your elbow to your hand then any rotation around your elbow (at 0,0,0) is going to form an arc through the air.

我希望能有所帮助,但我真的建议您认真阅读线性代数。您越了解,这样的问题就越容易解决:)

I hope that helps, but I would really recommend doing some serious reading up on Linear Algebra. The more you know the easier questions like this will be to solve yourself :)

这篇关于使对象轨道成为DirectX中的固定点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆