Merge pull request #850 from Zylann/transform_local

Add Transform3D `translated_local`, `rotated_local`, `scaled_local`
pull/853/head
Rémi Verschelde 2022-09-19 09:30:11 +02:00
commit 03d1120d6a
2 changed files with 26 additions and 7 deletions

View File

@ -55,6 +55,7 @@ public:
Transform3D affine_inverse() const;
Transform3D rotated(const Vector3 &p_axis, real_t p_phi) const;
Transform3D rotated_local(const Vector3 &p_axis, real_t p_angle) const;
void rotate(const Vector3 &p_axis, real_t p_phi);
void rotate_basis(const Vector3 &p_axis, real_t p_phi);
@ -64,10 +65,12 @@ public:
void scale(const Vector3 &p_scale);
Transform3D scaled(const Vector3 &p_scale) const;
Transform3D scaled_local(const Vector3 &p_scale) const;
void scale_basis(const Vector3 &p_scale);
void translate(real_t p_tx, real_t p_ty, real_t p_tz);
void translate(const Vector3 &p_translation);
Transform3D translated(const Vector3 &p_translation) const;
Transform3D translated_local(const Vector3 &p_translation) const;
const Basis &get_basis() const { return basis; }
void set_basis(const Basis &p_basis) { basis = p_basis; }

View File

@ -63,7 +63,15 @@ void Transform3D::rotate(const Vector3 &p_axis, real_t p_phi) {
}
Transform3D Transform3D::rotated(const Vector3 &p_axis, real_t p_phi) const {
return Transform3D(Basis(p_axis, p_phi), Vector3()) * (*this);
// Equivalent to left multiplication
Basis p_basis(p_axis, p_phi);
return Transform3D(p_basis * basis, p_basis.xform(origin));
}
Transform3D Transform3D::rotated_local(const Vector3 &p_axis, real_t p_angle) const {
// Equivalent to right multiplication
Basis p_basis(p_axis, p_angle);
return Transform3D(basis * p_basis, origin);
}
void Transform3D::rotate_basis(const Vector3 &p_axis, real_t p_phi) {
@ -133,9 +141,13 @@ void Transform3D::scale(const Vector3 &p_scale) {
}
Transform3D Transform3D::scaled(const Vector3 &p_scale) const {
Transform3D t = *this;
t.scale(p_scale);
return t;
// Equivalent to left multiplication
return Transform3D(basis.scaled(p_scale), origin * p_scale);
}
Transform3D Transform3D::scaled_local(const Vector3 &p_scale) const {
// Equivalent to right multiplication
return Transform3D(basis.scaled_local(p_scale), origin);
}
void Transform3D::scale_basis(const Vector3 &p_scale) {
@ -153,9 +165,13 @@ void Transform3D::translate(const Vector3 &p_translation) {
}
Transform3D Transform3D::translated(const Vector3 &p_translation) const {
Transform3D t = *this;
t.translate(p_translation);
return t;
// Equivalent to left multiplication
return Transform3D(basis, origin + p_translation);
}
Transform3D Transform3D::translated_local(const Vector3 &p_translation) const {
// Equivalent to right multiplication
return Transform3D(basis, origin + basis.xform(p_translation));
}
void Transform3D::orthonormalize() {