Skip to content

Commit

Permalink
Add new math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2brain committed Nov 9, 2023
1 parent f953e65 commit 3274fb5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions raylib/raymath.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 3274fb5

Please sign in to comment.