From 3274fb58ea9bdd498dfdbd258153bb863261d215 Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Thu, 9 Nov 2023 09:22:41 +0100 Subject: [PATCH] Add new math functions --- raylib/raymath.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/raylib/raymath.go b/raylib/raymath.go index c616d16..6caf2fb 100644 --- a/raylib/raymath.go +++ b/raylib/raymath.go @@ -241,6 +241,38 @@ func Vector3Normalize(v Vector3) Vector3 { return result } +// Vector3Project - Calculate the projection of the vector v1 on to v2 +func Vector3Project(v1, v2 Vector3) Vector3 { + result := Vector3{} + + v1dv2 := (v1.X*v2.X + v1.Y*v2.Y + v1.Z*v2.Z) + v2dv2 := (v2.X*v2.X + v2.Y*v2.Y + v2.Z*v2.Z) + + mag := v1dv2 / v2dv2 + + result.X = v2.X * mag + result.Y = v2.Y * mag + result.Z = v2.Z * mag + + return result +} + +// Vector3Reject - Calculate the rejection of the vector v1 on to v2 +func Vector3Reject(v1, v2 Vector3) Vector3 { + result := Vector3{} + + v1dv2 := (v1.X*v2.X + v1.Y*v2.Y + v1.Z*v2.Z) + v2dv2 := (v2.X*v2.X + v2.Y*v2.Y + v2.Z*v2.Z) + + mag := v1dv2 / v2dv2 + + result.X = v1.X - (v2.X * mag) + result.Y = v1.Y - (v2.Y * mag) + result.Z = v1.Z - (v2.Z * mag) + + return result +} + // Vector3Transform - Transforms a Vector3 by a given Matrix func Vector3Transform(v Vector3, mat Matrix) Vector3 { result := Vector3{}