summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-08-23 08:59:26 +0200
committerGitHub <noreply@github.com>2018-08-23 08:59:26 +0200
commit1e729630d6bff3a32751a1850271b080494373ba (patch)
tree14f29a26bb9733b5094a2ec41cf1efa8fe29516c
parenta2acbb0bfb547f893f9d84cfde4957fdc4791dae (diff)
parent434973fb83ce8add0a235fd5895acaf730857a08 (diff)
Merge pull request #21240 from aaronfranke/mono-project-vector
[Mono] Vector2/3 Project methods
-rw-r--r--core/math/vector2.cpp2
-rw-r--r--core/math/vector3.h2
-rw-r--r--modules/mono/glue/cs_files/Vector2.cs5
-rw-r--r--modules/mono/glue/cs_files/Vector3.cs5
4 files changed, 12 insertions, 2 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 75d9b8b311..84c9f0fca6 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -122,7 +122,7 @@ Vector2 Vector2::rotated(real_t p_by) const {
}
Vector2 Vector2::project(const Vector2 &p_b) const {
- return p_b * (dot(p_b) / p_b.dot(p_b));
+ return p_b * (dot(p_b) / p_b.length_squared());
}
Vector2 Vector2::snapped(const Vector2 &p_by) const {
diff --git a/core/math/vector3.h b/core/math/vector3.h
index a719e3965d..5f0e8919ff 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -241,7 +241,7 @@ real_t Vector3::distance_squared_to(const Vector3 &p_b) const {
}
Vector3 Vector3::project(const Vector3 &p_b) const {
- return p_b * (dot(p_b) / p_b.dot(p_b));
+ return p_b * (dot(p_b) / p_b.length_squared());
}
real_t Vector3::angle_to(const Vector3 &p_b) const {
diff --git a/modules/mono/glue/cs_files/Vector2.cs b/modules/mono/glue/cs_files/Vector2.cs
index 14c8de6986..080b8802ba 100644
--- a/modules/mono/glue/cs_files/Vector2.cs
+++ b/modules/mono/glue/cs_files/Vector2.cs
@@ -184,6 +184,11 @@ namespace Godot
return result;
}
+ public Vector2 Project(Vector2 onNormal)
+ {
+ return onNormal * (Dot(onNormal) / onNormal.LengthSquared());
+ }
+
public Vector2 Reflect(Vector2 n)
{
return 2.0f * n * Dot(n) - this;
diff --git a/modules/mono/glue/cs_files/Vector3.cs b/modules/mono/glue/cs_files/Vector3.cs
index 861d9c54d9..6fffe5e4d6 100644
--- a/modules/mono/glue/cs_files/Vector3.cs
+++ b/modules/mono/glue/cs_files/Vector3.cs
@@ -210,6 +210,11 @@ namespace Godot
);
}
+ public Vector3 Project(Vector3 onNormal)
+ {
+ return onNormal * (Dot(onNormal) / onNormal.LengthSquared());
+ }
+
public Vector3 Reflect(Vector3 n)
{
#if DEBUG