summaryrefslogtreecommitdiff
path: root/core/math/transform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/math/transform.cpp')
-rw-r--r--core/math/transform.cpp96
1 files changed, 43 insertions, 53 deletions
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 6d9324c176..d35938e559 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -31,7 +31,6 @@
#include "os/copymem.h"
#include "print_string.h"
-
void Transform::affine_invert() {
basis.invert();
@@ -40,13 +39,11 @@ void Transform::affine_invert() {
Transform Transform::affine_inverse() const {
- Transform ret=*this;
+ Transform ret = *this;
ret.affine_invert();
return ret;
-
}
-
void Transform::invert() {
basis.transpose();
@@ -56,35 +53,34 @@ void Transform::invert() {
Transform Transform::inverse() const {
// FIXME: this function assumes the basis is a rotation matrix, with no scaling.
// Transform::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
- Transform ret=*this;
+ Transform ret = *this;
ret.invert();
return ret;
}
-
-void Transform::rotate(const Vector3& p_axis,real_t p_phi) {
+void Transform::rotate(const Vector3 &p_axis, real_t p_phi) {
*this = rotated(p_axis, p_phi);
}
-Transform Transform::rotated(const Vector3& p_axis,real_t p_phi) const{
+Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const {
- return Transform(Basis( p_axis, p_phi ), Vector3()) * (*this);
+ return Transform(Basis(p_axis, p_phi), Vector3()) * (*this);
}
-void Transform::rotate_basis(const Vector3& p_axis,real_t p_phi) {
+void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) {
- basis.rotate(p_axis,p_phi);
+ basis.rotate(p_axis, p_phi);
}
-Transform Transform::looking_at( const Vector3& p_target, const Vector3& p_up ) const {
+Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const {
Transform t = *this;
- t.set_look_at(origin,p_target,p_up);
+ t.set_look_at(origin, p_target, p_up);
return t;
}
-void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, const Vector3& p_up ) {
+void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up) {
// Reference: MESA source code
Vector3 v_x, v_y, v_z;
@@ -98,23 +94,21 @@ void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, cons
v_y = p_up;
-
- v_x=v_y.cross(v_z);
+ v_x = v_y.cross(v_z);
/* Recompute Y = Z cross X */
- v_y=v_z.cross(v_x);
+ v_y = v_z.cross(v_x);
v_x.normalize();
v_y.normalize();
- basis.set_axis(0,v_x);
- basis.set_axis(1,v_y);
- basis.set_axis(2,v_z);
- origin=p_eye;
-
+ basis.set_axis(0, v_x);
+ basis.set_axis(1, v_y);
+ basis.set_axis(2, v_z);
+ origin = p_eye;
}
-Transform Transform::interpolate_with(const Transform& p_transform, real_t p_c) const {
+Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const {
/* not sure if very "efficient" but good enough? */
@@ -127,45 +121,44 @@ Transform Transform::interpolate_with(const Transform& p_transform, real_t p_c)
Vector3 dst_loc = p_transform.origin;
Transform dst;
- dst.basis=src_rot.slerp(dst_rot,p_c);
- dst.basis.scale(src_scale.linear_interpolate(dst_scale,p_c));
- dst.origin=src_loc.linear_interpolate(dst_loc,p_c);
+ dst.basis = src_rot.slerp(dst_rot, p_c);
+ dst.basis.scale(src_scale.linear_interpolate(dst_scale, p_c));
+ dst.origin = src_loc.linear_interpolate(dst_loc, p_c);
return dst;
}
-void Transform::scale(const Vector3& p_scale) {
+void Transform::scale(const Vector3 &p_scale) {
basis.scale(p_scale);
- origin*=p_scale;
+ origin *= p_scale;
}
-Transform Transform::scaled(const Vector3& p_scale) const {
+Transform Transform::scaled(const Vector3 &p_scale) const {
Transform t = *this;
t.scale(p_scale);
return t;
}
-void Transform::scale_basis(const Vector3& p_scale) {
+void Transform::scale_basis(const Vector3 &p_scale) {
basis.scale(p_scale);
}
-void Transform::translate( real_t p_tx, real_t p_ty, real_t p_tz) {
- translate( Vector3(p_tx,p_ty,p_tz) );
-
+void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) {
+ translate(Vector3(p_tx, p_ty, p_tz));
}
-void Transform::translate( const Vector3& p_translation ) {
+void Transform::translate(const Vector3 &p_translation) {
- for( int i = 0; i < 3; i++ ) {
+ for (int i = 0; i < 3; i++) {
origin[i] += basis[i].dot(p_translation);
}
}
-Transform Transform::translated( const Vector3& p_translation ) const {
+Transform Transform::translated(const Vector3 &p_translation) const {
- Transform t=*this;
+ Transform t = *this;
t.translate(p_translation);
return t;
}
@@ -182,25 +175,25 @@ Transform Transform::orthonormalized() const {
return _copy;
}
-bool Transform::operator==(const Transform& p_transform) const {
+bool Transform::operator==(const Transform &p_transform) const {
- return (basis==p_transform.basis && origin==p_transform.origin);
+ return (basis == p_transform.basis && origin == p_transform.origin);
}
-bool Transform::operator!=(const Transform& p_transform) const {
+bool Transform::operator!=(const Transform &p_transform) const {
- return (basis!=p_transform.basis || origin!=p_transform.origin);
+ return (basis != p_transform.basis || origin != p_transform.origin);
}
-void Transform::operator*=(const Transform& p_transform) {
+void Transform::operator*=(const Transform &p_transform) {
- origin=xform(p_transform.origin);
- basis*=p_transform.basis;
+ origin = xform(p_transform.origin);
+ basis *= p_transform.basis;
}
-Transform Transform::operator*(const Transform& p_transform) const {
+Transform Transform::operator*(const Transform &p_transform) const {
- Transform t=*this;
- t*=p_transform;
+ Transform t = *this;
+ t *= p_transform;
return t;
}
@@ -209,11 +202,8 @@ Transform::operator String() const {
return basis.operator String() + " - " + origin.operator String();
}
+Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) {
-Transform::Transform(const Basis& p_basis, const Vector3& p_origin) {
-
- basis=p_basis;
- origin=p_origin;
+ basis = p_basis;
+ origin = p_origin;
}
-
-