实现效果:
一个cube自转,另一个cube自转同时,绕中心轴公转
要点
Transform
平移之后,坐标原点就不在物体的中心了。平移之后一定方向上的旋转就是公转。
两个立方体的transform过程如下:
// 1st Cube: Rotate around the origin
// 绕Y轴旋转即可
g_World1 = XMMatrixRotationY( t );
// 2nd Cube: Rotate around origin
XMMATRIX mScale = XMMatrixScaling( 0.3f, 0.3f, 0.3f );
// 自转
XMMATRIX mSpin = XMMatrixRotationZ( -t );
// 平移
XMMATRIX mTranslate = XMMatrixTranslation( -4.0f, 0.0f, 0.0f );
XMMATRIX mOrbit = XMMatrixRotationY( -t * 2.0f );
// 注意顺序 缩放-自传-平移-公转
g_World2 = mScale * mSpin * mTranslate * mOrbit;
做完transformation,在绘制每个模型之前,update相应的常量缓冲
//
// Update variables for the first cube
//
ConstantBuffer cb1;
cb1.mWorl