summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEthan Simpson <[email protected]>2023-08-27 00:44:52 +1200
committerGitHub <[email protected]>2023-08-26 14:44:52 +0200
commit828d2736987c280883c9a5082bfd4d1a834de8a9 (patch)
treef21ac3bd10c8cf43d209909b0c04d1b8b827815e
parent21f5482e0d6e935e69118f6028da472065ea8317 (diff)
downloadraylib-828d2736987c280883c9a5082bfd4d1a834de8a9.tar.gz
raylib-828d2736987c280883c9a5082bfd4d1a834de8a9.zip
Add Vector3 Projecting and Rejection to Raymath (#3263)
* Update raymath.h * formatting
-rw-r--r--src/raymath.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/raymath.h b/src/raymath.h
index 86d2c8eb..def8bfd4 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -713,6 +713,32 @@ RMAPI Vector3 Vector3Normalize(Vector3 v)
return result;
}
+//Calculate the projection of the vector v1 on to v2
+RMAPI Vector3 Vector3Project(Vector3 v1, Vector3 v2)
+{
+ float v1dv2 = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
+ float v2dv2 = (v2.x*v2.x + v2.y*v2.y + v2.z*v2.z);
+
+ float mag = v1dv2/v2dv2;
+
+ Vector3 result = { v2.x*mag , v2.y*mag, v2.z*mag };
+
+ return result;
+}
+
+//Calculate the rejection of the vector v1 on to v2
+RMAPI Vector3 Vector3Reject(Vector3 v1, Vector3 v2)
+{
+ float v1dv2 = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
+ float v2dv2 = (v2.x*v2.x + v2.y*v2.y + v2.z*v2.z);
+
+ float mag = v1dv2/v2dv2;
+
+ Vector3 result = { v1.x - (v2.x*mag) , v1.y - (v2.y*mag), v1.z - (v2.z*mag) };
+
+ return result;
+}
+
// Orthonormalize provided vectors
// Makes vectors normalized and orthogonal to each other
// Gram-Schmidt function implementation