Skip to content

Commit

Permalink
Merge pull request #310 from rocktavious/kr/vector_rotate
Browse files Browse the repository at this point in the history
Add method to rotate vector by quaternion
  • Loading branch information
gen2brain authored Nov 11, 2023
2 parents a79a9b9 + 94a602d commit 44e78ec
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions raylib/raymath.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ func Vector3Transform(v Vector3, mat Matrix) Vector3 {
return result
}

// Vector3RotateByQuaternion - Transform a vector by quaternion rotation
func Vector3RotateByQuaternion(v Vector3, q Quaternion) Vector3 {
var result Vector3

result.X = v.X*(q.X*q.X+q.W*q.W-q.Y*q.Y-q.Z*q.Z) + v.Y*(2*q.X*q.Y-2*q.W*q.Z) + v.Z*(2*q.X*q.Z+2*q.W*q.Y)
result.Y = v.X*(2*q.W*q.Z+2*q.X*q.Y) + v.Y*(q.W*q.W-q.X*q.X+q.Y*q.Y-q.Z*q.Z) + v.Z*(-2*q.W*q.X+2*q.Y*q.Z)
result.Z = v.X*(-2*q.W*q.Y+2*q.X*q.Z) + v.Y*(2*q.W*q.X+2*q.Y*q.Z) + v.Z*(q.W*q.W-q.X*q.X-q.Y*q.Y+q.Z*q.Z)

return result
}

// Vector3RotateByAxisAngle - Rotates a vector around an axis
func Vector3RotateByAxisAngle(v Vector3, axis Vector3, angle float32) Vector3 {
// Using Euler-Rodrigues Formula
Expand Down

0 comments on commit 44e78ec

Please sign in to comment.