[英]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;
}
我將不勝感激,謝謝。
沒關系,問題在於這三個功能:縮放,旋轉,平移錯誤的地方以及混亂的一切。 我根據lwjgl Matrix4f類修復了它們,現在一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.