Skip to content

Commit

Permalink
Fixed item rotation from TrenchBroom for Interior Test
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Mar 5, 2024
1 parent 1e7dfba commit b9d921b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
10 changes: 3 additions & 7 deletions engine/source/interior/interiorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions engine/source/math/mMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit b9d921b

Please sign in to comment.