mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Add angle_between and matrix2_rotate
This commit is contained in:
@@ -267,6 +267,31 @@ to_ptr :: proc{vector_to_ptr, matrix_to_ptr}
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vector_angle_between :: proc "contextless" (a, b: $V/[$N]$E) -> E {
|
||||||
|
a0 := normalize0(a)
|
||||||
|
b0 := normalize0(b)
|
||||||
|
return math.acos(dot(a0, b0))
|
||||||
|
}
|
||||||
|
quaternion64_angle_between :: proc "contextless" (a, b: $Q/quaternion64) -> f16 {
|
||||||
|
c := normalize0(conj(a) * b)
|
||||||
|
return math.acos(c.w)
|
||||||
|
}
|
||||||
|
quaternion128_angle_between :: proc "contextless" (a, b: $Q/quaternion128) -> f32 {
|
||||||
|
c := normalize0(conj(a) * b)
|
||||||
|
return math.acos(c.w)
|
||||||
|
}
|
||||||
|
quaternion256_angle_between :: proc "contextless" (a, b: $Q/quaternion256) -> f64 {
|
||||||
|
c := normalize0(conj(a) * b)
|
||||||
|
return math.acos(c.w)
|
||||||
|
}
|
||||||
|
angle_between :: proc{
|
||||||
|
vector_angle_between,
|
||||||
|
quaternion64_angle_between,
|
||||||
|
quaternion128_angle_between,
|
||||||
|
quaternion256_angle_between,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Splines
|
// Splines
|
||||||
|
|
||||||
|
|||||||
@@ -1270,6 +1270,43 @@ matrix2_adjoint :: proc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@(require_results)
|
||||||
|
matrix2_rotate_f16 :: proc "contextless" (angle_radians: f16) -> Matrix2f16 {
|
||||||
|
c := math.cos(angle_radians)
|
||||||
|
s := math.sin(angle_radians)
|
||||||
|
|
||||||
|
return Matrix2f16{
|
||||||
|
c, -s,
|
||||||
|
s, c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@(require_results)
|
||||||
|
matrix2_rotate_f32 :: proc "contextless" (angle_radians: f32) -> Matrix2f32 {
|
||||||
|
c := math.cos(angle_radians)
|
||||||
|
s := math.sin(angle_radians)
|
||||||
|
|
||||||
|
return Matrix2f32{
|
||||||
|
c, -s,
|
||||||
|
s, c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@(require_results)
|
||||||
|
matrix2_rotate_f64 :: proc "contextless" (angle_radians: f64) -> Matrix2f64 {
|
||||||
|
c := math.cos(angle_radians)
|
||||||
|
s := math.sin(angle_radians)
|
||||||
|
|
||||||
|
return Matrix2f64{
|
||||||
|
c, -s,
|
||||||
|
s, c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matrix2_rotate :: proc{
|
||||||
|
matrix2_rotate_f16,
|
||||||
|
matrix2_rotate_f32,
|
||||||
|
matrix2_rotate_f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix3f16) {
|
matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix3f16) {
|
||||||
qxx := q.x * q.x
|
qxx := q.x * q.x
|
||||||
|
|||||||
Reference in New Issue
Block a user