From b9d921b533e473a7df239d4f5683bc8aef804e76 Mon Sep 17 00:00:00 2001 From: Human Gamer <39096122+HumanGamer@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:32:36 -0600 Subject: [PATCH] Fixed item rotation from TrenchBroom for Interior Test --- engine/source/interior/interiorInstance.cpp | 10 ++---- engine/source/math/mMatrix.h | 39 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/engine/source/interior/interiorInstance.cpp b/engine/source/interior/interiorInstance.cpp index 2c5b002e..97f4c76a 100644 --- a/engine/source/interior/interiorInstance.cpp +++ b/engine/source/interior/interiorInstance.cpp @@ -1428,9 +1428,7 @@ void InteriorInstance::addChildren() { if (dStricmp(entry.name, "angles") == 0) { - // TrenchBroom uses X, -Z, Y. Torque uses X, Y, Z - dSscanf(entry.value, "%g %g %g", &angles.x, &angles.z, &angles.y); - angles.z *= -1; // flipped in trench broom + dSscanf(entry.value, "%g %g %g", &angles.x, &angles.y, &angles.z); } else { @@ -1446,10 +1444,8 @@ void InteriorInstance::addChildren() angles.y = mDegToRad(angles.y); angles.z = mDegToRad(angles.z); - MatrixF rotMat(angles); - - //AngAxisF rot(Point3F(0.0f, 0.0f, 1.0f), mDegToRad(angle)); - //rot.setMatrix(&rotMat); + MatrixF rotMat(true); + rotMat.setEulerFromTrenchbroom(angles); MatrixF trans = this->getTransform(); trans.mulP(origin); diff --git a/engine/source/math/mMatrix.h b/engine/source/math/mMatrix.h index 55d07e7a..58395dc9 100644 --- a/engine/source/math/mMatrix.h +++ b/engine/source/math/mMatrix.h @@ -44,6 +44,8 @@ class MatrixF /// Initialize matrix to rotate about origin by e. MatrixF& set(const EulerF& e); + MatrixF& setEulerFromTrenchbroom(const EulerF& e); + /// Initialize matrix to rotate about p by e. MatrixF& set(const EulerF& e, const Point3F& p); @@ -188,6 +190,43 @@ inline MatrixF& MatrixF::set(const EulerF& e) return (*this); } +inline MatrixF& MatrixF::setEulerFromTrenchbroom(const EulerF& e) +{ + auto pitch = e.x; + auto yaw = e.y; + auto roll = e.z; + + constexpr auto I = 1.0f; + constexpr auto O = 0.0f; + + const auto Cr = mCos(roll); + const auto Sr = mSin(roll); + MatrixF R; + R.m[0] = +I; R.m[1] = +O; R.m[2] = +O; R.m[3] = +O; + R.m[4] = +O; R.m[5] = +Cr; R.m[6] = -Sr; R.m[7] = +O; + R.m[8] = +O; R.m[9] = +Sr; R.m[10] = +Cr; R.m[11] = +O; + R.m[12] = +O; R.m[13] = +O; R.m[14] = +O; R.m[15] = +I; + + const auto Cp = mCos(pitch); + const auto Sp = mSin(pitch); + MatrixF P; + P.m[0] = +Cp; P.m[1] = +O; P.m[2] = +Sp; P.m[3] = +O; + P.m[4] = +O; P.m[5] = +I; P.m[6] = +O; P.m[7] = +O; + P.m[8] = -Sp; P.m[9] = +O; P.m[10] = +Cp; P.m[11] = +O; + P.m[12] = +O; P.m[13] = +O; P.m[14] = +O; P.m[15] = +I; + + const auto Cy = mCos(yaw); + const auto Sy = mSin(yaw); + MatrixF Y; + Y.m[0] = +Cy; Y.m[1] = -Sy; Y.m[2] = +O; Y.m[3] = +O; + Y.m[4] = +Sy; Y.m[5] = +Cy; Y.m[6] = +O; Y.m[7] = +O; + Y.m[8] = +O; Y.m[9] = +O; Y.m[10] = +I; Y.m[11] = +O; + Y.m[12] = +O; Y.m[13] = +O; Y.m[14] = +O; Y.m[15] = +I; + + *this = Y * P * R; + + return (*this); +} inline MatrixF& MatrixF::set(const EulerF& e, const Point3F& p) {