Skip to content

Commit

Permalink
fixed inverted transform
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Nov 16, 2024
1 parent 6998511 commit ff4cc74
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,7 @@ Transform::Transform(const DVec3& pos, const Quat& rot, Vec3 scale)
, rot(rot)
, scale(scale) {}

Transform Transform::operator*(const Transform& rhs) const { return {rot.rotate(rhs.pos * scale) + pos, rot * rhs.rot, scale * rhs.scale}; }

Transform Transform::operator*(const LocalRigidTransform& rhs) const { return {pos + rot.rotate(rhs.pos * scale), rot * rhs.rot, scale}; }
Transform Transform::operator*(const LocalRigidTransform& rhs) const { return {pos + rot.rotate(rhs.pos) * scale, rot * rhs.rot, scale}; }

DVec3 Transform::transform(const Vec3& value) const { return pos + rot.rotate(value) * scale; }

Expand All @@ -769,10 +767,18 @@ Vec3 Transform::transformVector(const Vec3& value) const { return rot.rotate(val

RigidTransform Transform::getRigidPart() const { return {pos, rot}; }

Transform Transform::operator*(const Transform& rhs) const {
return {
rot.rotate(rhs.pos) * scale + pos,
rot * rhs.rot,
scale * rhs.scale
};
}

Transform Transform::inverted() const {
Transform result;
result.rot = rot.conjugated();
result.pos = result.rot.rotate(-pos / scale);
result.pos = result.rot.rotate(-pos) / scale;
result.scale = Vec3(1.0f) / scale;
return result;
}
Expand All @@ -786,13 +792,13 @@ LocalTransform::LocalTransform(const Vec3& pos, const Quat& rot, float scale)
LocalTransform LocalTransform::inverted() const {
LocalTransform result;
result.rot = rot.conjugated();
result.pos = result.rot.rotate(-pos / scale);
result.pos = result.rot.rotate(-pos) / scale;
result.scale = 1.0f / scale;
return result;
}

LocalTransform LocalTransform::operator*(const LocalTransform& rhs) const {
return {pos + rot.rotate(rhs.pos * scale), rot * rhs.rot, scale};
return {pos + rot.rotate(rhs.pos) * scale, rot * rhs.rot, scale};
}

LocalRigidTransform LocalRigidTransform::inverted() const {
Expand Down

0 comments on commit ff4cc74

Please sign in to comment.