矩阵 4 旋转不会在 x 和 y 周围工作,但会在 z 周围工作
Matrix4 rotation won't work around x and y but works around z
我正在尝试制作一个立方体以正确绕所有轴旋转。我可以移动立方体,视图是透视的,但是当我尝试旋转它时,旋转仅在z轴上工作。
即使我要考虑到X和Y轴旋转也没有效果。我的旋转方法:
void Matrix4::rotate(float degrees, Vector3 axis)
{
float c = cos(Common::degreesToRadians(degrees));
float s = sin(Common::degreesToRadians(degrees));
values[0] = (axis.x * axis.x) * (1.0f - c) + c;
values[1] = (axis.y * axis.x) * (1.0f - c) + (axis.z * s);
values[2] = (axis.z * axis.x) * (1.0f - c) - (axis.y * s);
values[4] = (axis.x * axis.y) * (1.0f - c) - (axis.z * s);
values[5] = (axis.y * axis.y) * (1.0f - c) + c;
values[6] = (axis.z * axis.y) * (1.0f - c) + (axis.x * s);
values[8] = (axis.x * axis.z) * (1.0f - c) + (axis.y * s);
values[9] = (axis.y * axis.z) * (1.0f - c) - (axis.x * s);
values[10] = (axis.z * axis.z) * (1.0f - c) + c;
}
我的CreateTransFormationMatrix函数:
Matrix4 Matrix4::createTransformationMatrix(Vector3 position, Vector3 rotation, Vector3 scale)
{
Matrix4 result;
result.translate(position);
result.rotate(rotation.x, Vector3(1, 0, 0));
result.rotate(rotation.y, Vector3(0, 1, 0));
result.rotate(rotation.z, Vector3(0, 0, 1));
result.scale(scale);
return result;
}
我感谢任何帮助,谢谢。
没关系,问题是所有3个函数:缩放,旋转,翻译错误的位置,然后弄乱了。我根据lwjgl matrix4f类修复了它们,现在一切正常。
相关文章:
- QSqlquery prepare()和bindvalue()不工作
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- 有人能解释一下为什么下界是这样工作的吗C++的
- ExtractIconEx:可以工作,但偶尔会崩溃
- C++中的memset函数工作不正常
- 矩阵 4 旋转不会在 x 和 y 周围工作,但会在 z 周围工作
- msvc++说变量周围的堆栈正在损坏,但程序工作
- LPTSTR失去作用域,工作周围不工作(c++)