Skip to content

Commit

Permalink
SetBakedMatrix --> SetBakedTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
lhog committed Dec 14, 2024
1 parent 6d5a469 commit 2c1b21f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
7 changes: 3 additions & 4 deletions rts/Rendering/Models/3DModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,9 @@ struct S3DModelPiece {
void Shatter(float, int, int, int, const float3, const float3, const CMatrix44f&) const;

void SetPieceTransform(const Transform& parentTra);
void SetBakedMatrix(const CMatrix44f& m) {
bakedTransform = Transform::FromMatrix(m);
hasBakedTra = !m.IsIdentity();
assert(m.IsOrthoNormal());
void SetBakedTransform(const Transform& tra) {
bakedTransform = tra;
hasBakedTra = !tra.IsIdentity();
}

Transform ComposeTransform(const float3& t, const float3& r, float s) const;
Expand Down
17 changes: 11 additions & 6 deletions rts/Rendering/Models/AssParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ struct SPseudoAssPiece {

bool hasBakedTra;

// copy of S3DModelPiece::SetBakedMatrix()
void SetBakedMatrix(const CMatrix44f& m) {
bakedTransform = Transform::FromMatrix(m);
hasBakedTra = !m.IsIdentity();
assert(m.IsOrthoNormal());
// copy of S3DModelPiece::SetBakedTransform()
void SetBakedTransform(const Transform& tra) {
hasBakedTra = !tra.IsIdentity();
}

// copy of S3DModelPiece::ComposeTransform()
Expand Down Expand Up @@ -518,7 +516,14 @@ namespace {
// and <scales> so the baked part reduces to R
//
// note: for all non-AssImp models this is identity!
piece->SetBakedMatrix(bakedMatrix.RotateEulerYXZ(-bakedRotAngles));

Transform bakedTransform(CQuaternion::FromEulerYPRNeg(-bakedRotAngles) * CQuaternion(aiRotateQuat.x, aiRotateQuat.y, aiRotateQuat.z, aiRotateQuat.w), ZeroVector, 1.0f);
piece->SetBakedTransform(bakedTransform);
#ifdef _DEBUG
Transform bakedTransform2 = Transform::FromMatrix(bakedMatrix);
assert(bakedTransform.equals(bakedTransform2));
#endif // _DEBUG

}
}

Expand Down
6 changes: 6 additions & 0 deletions rts/System/Transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ CR_REG_METADATA(Transform, (
static_assert(sizeof (Transform) == 2 * 4 * sizeof(float));
static_assert(alignof(Transform) == alignof(decltype(Transform::r)));

bool Transform::IsIdentity() const
{
static constexpr Transform Identity;
return this->equals(Identity);
}

Transform Transform::FromMatrix(const CMatrix44f& mat)
{
Transform tra;
Expand Down
2 changes: 2 additions & 0 deletions rts/System/Transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct Transform {
s = 1.0f;
}

bool IsIdentity() const;

static Transform FromMatrix(const CMatrix44f& mat);
CMatrix44f ToMatrix() const;

Expand Down

0 comments on commit 2c1b21f

Please sign in to comment.