首页 > 解决方案 > DirectX 11 - 轴旋转

问题描述

我很难沿着世界上的一个轴旋转我的立方体。

XMMatrixTranslation用来在场景中定位对象并沿轴移动它。

此外,尝试使用XMMatrixRotationRollPitchYaw来管理对象围绕轴的旋转。

到目前为止,对象围绕轴旋转,但按下按钮时它不会沿轴移动。

Cube1 代码:

    cube1 = XMMatrixIdentity();

//Move the cube along the axis
cube1 = XMMatrixTranslation(input[0].xPos, input[0].yPos, 0.0f);

//Rotate the cube around the axis
cube1 = XMMatrixRotationRollPitchYaw(input[0].rotation, 0.0f, 0.0f);

//Control Cube 1
if (input[0].isMovingRight == true) {
    input[0].xPos += 0.001f;
}
if (input[0].isMovingLeft == true) {
    input[0].xPos -= 0.001f;
}
if (input[0].isMovingUp == true) {
    input[0].yPos += 0.001f;
}
if (input[0].isMovingDown == true) {
    input[0].yPos -= 0.001f;
}
if (input[0].isMovingCloser == true) {
    input[0].zPos += 0.001f;
}
if (input[0].isMovingFurther == true) {
    input[0].zPos -= 0.001f;
}
if (input[0].isRotating == true) {
    input[0].rotation += 0.0005f;
}

我试过颠倒它们被调用的顺序,但立方体会沿着所说的轴移动,但不会旋转。

(另外,我知道代码可能会优化很多,这只是为了练习。)

标签: c++

解决方案


推荐阅读