c++ - 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;
}
我试过颠倒它们被调用的顺序,但立方体会沿着所说的轴移动,但不会旋转。
(另外,我知道代码可能会优化很多,这只是为了练习。)
解决方案
推荐阅读
- python - 在 QGIS 3.4 Python 控制台中使用字段计算器
- python - 具有加州住房数据的神经网络
- wso2 - WSO2 Enterprise Integrator Sequence - 异步调用后的轮询结果
- sql - 根据其中的行和其他表更新表
- beeline - 错误:编译语句时出错:FAILED: SemanticException Error when getting current notification event ID (state=42000,code=40000)
- typescript - Atom 编辑器关闭 TypeScript 的相同术语突出显示
- python-3.x - Flask-SQLalchemy 一对一关系:将子级关联到已经存在的父级?
- r - 在函数内声明要在函数外使用的变量(但不全局声明)
- powershell - 从 Powershell 获得的 Sum 参数
- java - JButton ActionListeners 每个循环中的不同变量