summaryrefslogtreecommitdiffstats
path: root/core/math/vector3.h
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-01-10 22:27:32 -0300
committerGitHub <noreply@github.com>2017-01-10 22:27:32 -0300
commit710692278d1353aad08bc7bceb655afc1d6c950c (patch)
treebaa41e8373b6a686baa7de4d14d1630b4ab1d3e0 /core/math/vector3.h
parent6671670e8162bc2dba1382a7b50f1c089ca3df17 (diff)
parent2e38b32e0f261445c2d0b095c1822fbe6df16e25 (diff)
downloadredot-engine-710692278d1353aad08bc7bceb655afc1d6c950c.tar.gz
Merge pull request #7426 from m4nu3lf/bugfix/physics
Fixed inertia tensor computation and center of mass
Diffstat (limited to 'core/math/vector3.h')
-rw-r--r--core/math/vector3.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 14cf1bc6ca..f1f34ce318 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -34,6 +34,7 @@
#include "math_funcs.h"
#include "ustring.h"
+class Matrix3;
struct Vector3 {
@@ -92,6 +93,8 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3& p_b) const;
+ _FORCE_INLINE_ Matrix3 outer(const Vector3& p_b) const;
+ _FORCE_INLINE_ Matrix3 to_diagonal_matrix() const;
_FORCE_INLINE_ Vector3 abs() const;
_FORCE_INLINE_ Vector3 floor() const;
@@ -144,6 +147,8 @@ struct Vector3 {
#else
+#include "matrix3.h"
+
Vector3 Vector3::cross(const Vector3& p_b) const {
Vector3 ret (
@@ -160,6 +165,21 @@ real_t Vector3::dot(const Vector3& p_b) const {
return x*p_b.x + y*p_b.y + z*p_b.z;
}
+Matrix3 Vector3::outer(const Vector3& p_b) const {
+
+ Vector3 row0(x*p_b.x, x*p_b.y, x*p_b.z);
+ Vector3 row1(y*p_b.x, y*p_b.y, y*p_b.z);
+ Vector3 row2(z*p_b.x, z*p_b.y, z*p_b.z);
+
+ return Matrix3(row0, row1, row2);
+}
+
+Matrix3 Vector3::to_diagonal_matrix() const {
+ return Matrix3(x, 0, 0,
+ 0, y, 0,
+ 0, 0, z);
+}
+
Vector3 Vector3::abs() const {
return Vector3( Math::abs(x), Math::abs(y), Math::abs(z) );