mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 11:22:22 -07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -492,7 +492,6 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
case:
|
||||
return UNSUPPORTED_TYPE
|
||||
}
|
||||
|
||||
@@ -172,13 +172,23 @@ projection :: proc "contextless" (x, normal: $T/[$N]$E) -> T where IS_NUMERIC(E)
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
identity :: proc "contextless" ($T: typeid/[$N][N]$E) -> (m: T) #no_bounds_check {
|
||||
identity_array_based_matrix :: proc "contextless" ($T: typeid/[$N][N]$E) -> (m: T) #no_bounds_check {
|
||||
for i in 0..<N {
|
||||
m[i][i] = E(1)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
identity_matrix :: proc "contextless" ($T: typeid/matrix[$N, N]$E) -> T #no_bounds_check {
|
||||
return 1
|
||||
}
|
||||
|
||||
identity :: proc{
|
||||
identity_array_based_matrix,
|
||||
identity_matrix,
|
||||
}
|
||||
|
||||
transpose :: intrinsics.transpose
|
||||
|
||||
@(require_results)
|
||||
@@ -296,7 +306,7 @@ angle_between :: proc{
|
||||
// Splines
|
||||
|
||||
@(require_results)
|
||||
vector_slerp :: proc "contextless" (x, y: $T/[$N]$E, a: E) -> T {
|
||||
vector_slerp :: proc "contextless" (x, y: $T/[$N]$E, a: E) -> T #no_bounds_check {
|
||||
cos_alpha := dot(x, y)
|
||||
alpha := math.acos(cos_alpha)
|
||||
sin_alpha := math.sin(alpha)
|
||||
@@ -308,7 +318,7 @@ vector_slerp :: proc "contextless" (x, y: $T/[$N]$E, a: E) -> T {
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
catmull_rom :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T {
|
||||
catmull_rom :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T #no_bounds_check {
|
||||
s2 := s*s
|
||||
s3 := s2*s
|
||||
|
||||
@@ -321,7 +331,7 @@ catmull_rom :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T {
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
hermite :: proc "contextless" (v1, t1, v2, t2: $T/[$N]$E, s: E) -> T {
|
||||
hermite :: proc "contextless" (v1, t1, v2, t2: $T/[$N]$E, s: E) -> T #no_bounds_check {
|
||||
s2 := s*s
|
||||
s3 := s2*s
|
||||
|
||||
@@ -334,7 +344,7 @@ hermite :: proc "contextless" (v1, t1, v2, t2: $T/[$N]$E, s: E) -> T {
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
cubic :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T {
|
||||
cubic :: proc "contextless" (v1, v2, v3, v4: $T/[$N]$E, s: E) -> T #no_bounds_check {
|
||||
return ((v1 * s + v2) * s + v3) * s + v4
|
||||
}
|
||||
|
||||
@@ -415,12 +425,12 @@ inverse :: proc{
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
hermitian_adjoint :: proc "contextless" (m: $M/matrix[$N, N]$T) -> M where intrinsics.type_is_complex(T), N >= 1 {
|
||||
hermitian_adjoint :: proc "contextless" (m: $M/matrix[$N, N]$T) -> M where intrinsics.type_is_complex(T), N >= 1 #no_bounds_check {
|
||||
return conj(transpose(m))
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
trace :: proc "contextless" (m: $M/matrix[$N, N]$T) -> (trace: T) {
|
||||
trace :: proc "contextless" (m: $M/matrix[$N, N]$T) -> (trace: T) #no_bounds_check {
|
||||
for i in 0..<N {
|
||||
trace += m[i, i]
|
||||
}
|
||||
@@ -428,7 +438,7 @@ trace :: proc "contextless" (m: $M/matrix[$N, N]$T) -> (trace: T) {
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix_minor :: proc "contextless" (m: $M/matrix[$N, N]$T, #any_int row, column: int) -> (minor: T) where N > 1 {
|
||||
matrix_minor :: proc "contextless" (m: $M/matrix[$N, N]$T, #any_int row, column: int) -> (minor: T) where N > 1 #no_bounds_check {
|
||||
K :: int(N-1)
|
||||
cut_down: matrix[K, K]T
|
||||
for col_idx in 0..<K {
|
||||
@@ -444,25 +454,25 @@ matrix_minor :: proc "contextless" (m: $M/matrix[$N, N]$T, #any_int row, column:
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix1x1_determinant :: proc "contextless" (m: $M/matrix[1, 1]$T) -> (det: T) {
|
||||
matrix1x1_determinant :: proc "contextless" (m: $M/matrix[1, 1]$T) -> (det: T) #no_bounds_check {
|
||||
return m[0, 0]
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix2x2_determinant :: proc "contextless" (m: $M/matrix[2, 2]$T) -> (det: T) {
|
||||
matrix2x2_determinant :: proc "contextless" (m: $M/matrix[2, 2]$T) -> (det: T) #no_bounds_check {
|
||||
return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
}
|
||||
@(require_results)
|
||||
matrix3x3_determinant :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (det: T) {
|
||||
matrix3x3_determinant :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (det: T) #no_bounds_check {
|
||||
a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1])
|
||||
b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0])
|
||||
c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0])
|
||||
return a + b + c
|
||||
}
|
||||
@(require_results)
|
||||
matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) {
|
||||
matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) #no_bounds_check {
|
||||
a := adjugate(m)
|
||||
#no_bounds_check for i in 0..<4 {
|
||||
for i in 0..<4 {
|
||||
det += m[0, i] * a[0, i]
|
||||
}
|
||||
return
|
||||
@@ -472,13 +482,13 @@ matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) {
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix1x1_adjugate :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) {
|
||||
matrix1x1_adjugate :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) #no_bounds_check {
|
||||
y = x
|
||||
return
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix2x2_adjugate :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) {
|
||||
matrix2x2_adjugate :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) #no_bounds_check {
|
||||
y[0, 0] = +x[1, 1]
|
||||
y[0, 1] = -x[1, 0]
|
||||
y[1, 0] = -x[0, 1]
|
||||
@@ -487,7 +497,7 @@ matrix2x2_adjugate :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) {
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix3x3_adjugate :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (y: M) {
|
||||
matrix3x3_adjugate :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (y: M) #no_bounds_check {
|
||||
y[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2])
|
||||
y[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2])
|
||||
y[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1])
|
||||
@@ -502,7 +512,7 @@ matrix3x3_adjugate :: proc "contextless" (m: $M/matrix[3, 3]$T) -> (y: M) {
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4x4_adjugate :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) {
|
||||
matrix4x4_adjugate :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) #no_bounds_check {
|
||||
for i in 0..<4 {
|
||||
for j in 0..<4 {
|
||||
sign: T = 1 if (i + j) % 2 == 0 else -1
|
||||
@@ -513,13 +523,13 @@ matrix4x4_adjugate :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) {
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix1x1_inverse_transpose :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) {
|
||||
matrix1x1_inverse_transpose :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) #no_bounds_check {
|
||||
y[0, 0] = 1/x[0, 0]
|
||||
return
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix2x2_inverse_transpose :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) {
|
||||
matrix2x2_inverse_transpose :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) #no_bounds_check {
|
||||
d := x[0, 0]*x[1, 1] - x[0, 1]*x[1, 0]
|
||||
when intrinsics.type_is_integer(T) {
|
||||
y[0, 0] = +x[1, 1] / d
|
||||
@@ -582,13 +592,13 @@ matrix4x4_inverse_transpose :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y:
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix1x1_inverse :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) {
|
||||
matrix1x1_inverse :: proc "contextless" (x: $M/matrix[1, 1]$T) -> (y: M) #no_bounds_check {
|
||||
y[0, 0] = 1/x[0, 0]
|
||||
return
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
matrix2x2_inverse :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) {
|
||||
matrix2x2_inverse :: proc "contextless" (x: $M/matrix[2, 2]$T) -> (y: M) #no_bounds_check {
|
||||
d := x[0, 0]*x[1, 1] - x[0, 1]*x[1, 0]
|
||||
when intrinsics.type_is_integer(T) {
|
||||
y[0, 0] = +x[1, 1] / d
|
||||
|
||||
+101
-101
@@ -584,7 +584,7 @@ angle_axis_from_quaternion :: proc {
|
||||
|
||||
|
||||
@(require_results)
|
||||
quaternion_from_forward_and_up_f16 :: proc "contextless" (forward, up: Vector3f16) -> Quaternionf16 {
|
||||
quaternion_from_forward_and_up_f16 :: proc "contextless" (forward, up: Vector3f16) -> Quaternionf16 #no_bounds_check {
|
||||
f := normalize(forward)
|
||||
s := normalize(cross(f, up))
|
||||
u := cross(s, f)
|
||||
@@ -628,7 +628,7 @@ quaternion_from_forward_and_up_f16 :: proc "contextless" (forward, up: Vector3f1
|
||||
return normalize(q)
|
||||
}
|
||||
@(require_results)
|
||||
quaternion_from_forward_and_up_f32 :: proc "contextless" (forward, up: Vector3f32) -> Quaternionf32 {
|
||||
quaternion_from_forward_and_up_f32 :: proc "contextless" (forward, up: Vector3f32) -> Quaternionf32 #no_bounds_check {
|
||||
f := normalize(forward)
|
||||
s := normalize(cross(f, up))
|
||||
u := cross(s, f)
|
||||
@@ -672,7 +672,7 @@ quaternion_from_forward_and_up_f32 :: proc "contextless" (forward, up: Vector3f3
|
||||
return normalize(q)
|
||||
}
|
||||
@(require_results)
|
||||
quaternion_from_forward_and_up_f64 :: proc "contextless" (forward, up: Vector3f64) -> Quaternionf64 {
|
||||
quaternion_from_forward_and_up_f64 :: proc "contextless" (forward, up: Vector3f64) -> Quaternionf64 #no_bounds_check {
|
||||
f := normalize(forward)
|
||||
s := normalize(cross(f, up))
|
||||
u := cross(s, f)
|
||||
@@ -886,7 +886,7 @@ quaternion_squad :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
quaternion_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (q: Quaternionf16) {
|
||||
quaternion_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (q: Quaternionf16) #no_bounds_check {
|
||||
m3: Matrix3f16 = ---
|
||||
m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0]
|
||||
m3[0, 1], m3[1, 1], m3[2, 1] = m[0, 1], m[1, 1], m[2, 1]
|
||||
@@ -894,7 +894,7 @@ quaternion_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (q: Quatern
|
||||
return quaternion_from_matrix3(m3)
|
||||
}
|
||||
@(require_results)
|
||||
quaternion_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (q: Quaternionf32) {
|
||||
quaternion_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (q: Quaternionf32) #no_bounds_check {
|
||||
m3: Matrix3f32 = ---
|
||||
m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0]
|
||||
m3[0, 1], m3[1, 1], m3[2, 1] = m[0, 1], m[1, 1], m[2, 1]
|
||||
@@ -902,7 +902,7 @@ quaternion_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (q: Quatern
|
||||
return quaternion_from_matrix3(m3)
|
||||
}
|
||||
@(require_results)
|
||||
quaternion_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (q: Quaternionf64) {
|
||||
quaternion_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (q: Quaternionf64) #no_bounds_check {
|
||||
m3: Matrix3f64 = ---
|
||||
m3[0, 0], m3[1, 0], m3[2, 0] = m[0, 0], m[1, 0], m[2, 0]
|
||||
m3[0, 1], m3[1, 1], m3[2, 1] = m[0, 1], m[1, 1], m[2, 1]
|
||||
@@ -917,7 +917,7 @@ quaternion_from_matrix4 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
quaternion_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (q: Quaternionf16) {
|
||||
quaternion_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (q: Quaternionf16) #no_bounds_check {
|
||||
four_x_squared_minus_1 := m[0, 0] - m[1, 1] - m[2, 2]
|
||||
four_y_squared_minus_1 := m[1, 1] - m[0, 0] - m[2, 2]
|
||||
four_z_squared_minus_1 := m[2, 2] - m[0, 0] - m[1, 1]
|
||||
@@ -967,7 +967,7 @@ quaternion_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (q: Quatern
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
quaternion_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (q: Quaternionf32) {
|
||||
quaternion_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (q: Quaternionf32) #no_bounds_check {
|
||||
four_x_squared_minus_1 := m[0, 0] - m[1, 1] - m[2, 2]
|
||||
four_y_squared_minus_1 := m[1, 1] - m[0, 0] - m[2, 2]
|
||||
four_z_squared_minus_1 := m[2, 2] - m[0, 0] - m[1, 1]
|
||||
@@ -1017,7 +1017,7 @@ quaternion_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (q: Quatern
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
quaternion_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (q: Quaternionf64) {
|
||||
quaternion_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (q: Quaternionf64) #no_bounds_check {
|
||||
four_x_squared_minus_1 := m[0, 0] - m[1, 1] - m[2, 2]
|
||||
four_y_squared_minus_1 := m[1, 1] - m[0, 0] - m[2, 2]
|
||||
four_z_squared_minus_1 := m[2, 2] - m[0, 0] - m[1, 1]
|
||||
@@ -1147,7 +1147,7 @@ quaternion_between_two_vector3 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_inverse_transpose_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) {
|
||||
matrix2_inverse_transpose_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) #no_bounds_check {
|
||||
d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
id := 1.0/d
|
||||
c[0, 0] = +m[1, 1] * id
|
||||
@@ -1157,7 +1157,7 @@ matrix2_inverse_transpose_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matri
|
||||
return c
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_inverse_transpose_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) {
|
||||
matrix2_inverse_transpose_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) #no_bounds_check {
|
||||
d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
id := 1.0/d
|
||||
c[0, 0] = +m[1, 1] * id
|
||||
@@ -1167,7 +1167,7 @@ matrix2_inverse_transpose_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matri
|
||||
return c
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_inverse_transpose_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) {
|
||||
matrix2_inverse_transpose_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) #no_bounds_check {
|
||||
d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
id := 1.0/d
|
||||
c[0, 0] = +m[1, 1] * id
|
||||
@@ -1184,15 +1184,15 @@ matrix2_inverse_transpose :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_determinant_f16 :: proc "contextless" (m: Matrix2f16) -> f16 {
|
||||
matrix2_determinant_f16 :: proc "contextless" (m: Matrix2f16) -> f16 #no_bounds_check {
|
||||
return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_determinant_f32 :: proc "contextless" (m: Matrix2f32) -> f32 {
|
||||
matrix2_determinant_f32 :: proc "contextless" (m: Matrix2f32) -> f32 #no_bounds_check {
|
||||
return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_determinant_f64 :: proc "contextless" (m: Matrix2f64) -> f64 {
|
||||
matrix2_determinant_f64 :: proc "contextless" (m: Matrix2f64) -> f64 #no_bounds_check {
|
||||
return m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
}
|
||||
matrix2_determinant :: proc{
|
||||
@@ -1203,7 +1203,7 @@ matrix2_determinant :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_inverse_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) {
|
||||
matrix2_inverse_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) #no_bounds_check {
|
||||
d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
id := 1.0/d
|
||||
c[0, 0] = +m[1, 1] * id
|
||||
@@ -1213,7 +1213,7 @@ matrix2_inverse_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) {
|
||||
return c
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_inverse_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) {
|
||||
matrix2_inverse_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) #no_bounds_check {
|
||||
d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
id := 1.0/d
|
||||
c[0, 0] = +m[1, 1] * id
|
||||
@@ -1223,7 +1223,7 @@ matrix2_inverse_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) {
|
||||
return c
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_inverse_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) {
|
||||
matrix2_inverse_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) #no_bounds_check {
|
||||
d := m[0, 0]*m[1, 1] - m[0, 1]*m[1, 0]
|
||||
id := 1.0/d
|
||||
c[0, 0] = +m[1, 1] * id
|
||||
@@ -1240,7 +1240,7 @@ matrix2_inverse :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_adjoint_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) {
|
||||
matrix2_adjoint_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) #no_bounds_check {
|
||||
c[0, 0] = +m[1, 1]
|
||||
c[1, 0] = -m[0, 1]
|
||||
c[0, 1] = -m[1, 0]
|
||||
@@ -1248,7 +1248,7 @@ matrix2_adjoint_f16 :: proc "contextless" (m: Matrix2f16) -> (c: Matrix2f16) {
|
||||
return c
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_adjoint_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) {
|
||||
matrix2_adjoint_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) #no_bounds_check {
|
||||
c[0, 0] = +m[1, 1]
|
||||
c[1, 0] = -m[0, 1]
|
||||
c[0, 1] = -m[1, 0]
|
||||
@@ -1256,7 +1256,7 @@ matrix2_adjoint_f32 :: proc "contextless" (m: Matrix2f32) -> (c: Matrix2f32) {
|
||||
return c
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_adjoint_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) {
|
||||
matrix2_adjoint_f64 :: proc "contextless" (m: Matrix2f64) -> (c: Matrix2f64) #no_bounds_check {
|
||||
c[0, 0] = +m[1, 1]
|
||||
c[1, 0] = -m[0, 1]
|
||||
c[0, 1] = -m[1, 0]
|
||||
@@ -1308,7 +1308,7 @@ matrix2_rotate :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix3f16) {
|
||||
matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix3f16) #no_bounds_check {
|
||||
qxx := q.x * q.x
|
||||
qyy := q.y * q.y
|
||||
qzz := q.z * q.z
|
||||
@@ -1333,7 +1333,7 @@ matrix3_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matr
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix3f32) {
|
||||
matrix3_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix3f32) #no_bounds_check {
|
||||
qxx := q.x * q.x
|
||||
qyy := q.y * q.y
|
||||
qzz := q.z * q.z
|
||||
@@ -1358,7 +1358,7 @@ matrix3_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matr
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix3f64) {
|
||||
matrix3_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix3f64) #no_bounds_check {
|
||||
qxx := q.x * q.x
|
||||
qyy := q.y * q.y
|
||||
qzz := q.z * q.z
|
||||
@@ -1409,21 +1409,21 @@ matrix3_inverse :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_determinant_f16 :: proc "contextless" (m: Matrix3f16) -> f16 {
|
||||
matrix3_determinant_f16 :: proc "contextless" (m: Matrix3f16) -> f16 #no_bounds_check {
|
||||
a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1])
|
||||
b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0])
|
||||
c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0])
|
||||
return a + b + c
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_determinant_f32 :: proc "contextless" (m: Matrix3f32) -> f32 {
|
||||
matrix3_determinant_f32 :: proc "contextless" (m: Matrix3f32) -> f32 #no_bounds_check {
|
||||
a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1])
|
||||
b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0])
|
||||
c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0])
|
||||
return a + b + c
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_determinant_f64 :: proc "contextless" (m: Matrix3f64) -> f64 {
|
||||
matrix3_determinant_f64 :: proc "contextless" (m: Matrix3f64) -> f64 #no_bounds_check {
|
||||
a := +m[0, 0] * (m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1])
|
||||
b := -m[0, 1] * (m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0])
|
||||
c := +m[0, 2] * (m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0])
|
||||
@@ -1437,7 +1437,7 @@ matrix3_determinant :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_adjoint_f16 :: proc "contextless" (m: Matrix3f16) -> (adjoint: Matrix3f16) {
|
||||
matrix3_adjoint_f16 :: proc "contextless" (m: Matrix3f16) -> (adjoint: Matrix3f16) #no_bounds_check {
|
||||
adjoint[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2])
|
||||
adjoint[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2])
|
||||
adjoint[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1])
|
||||
@@ -1450,7 +1450,7 @@ matrix3_adjoint_f16 :: proc "contextless" (m: Matrix3f16) -> (adjoint: Matrix3f1
|
||||
return adjoint
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_adjoint_f32 :: proc "contextless" (m: Matrix3f32) -> (adjoint: Matrix3f32) {
|
||||
matrix3_adjoint_f32 :: proc "contextless" (m: Matrix3f32) -> (adjoint: Matrix3f32) #no_bounds_check {
|
||||
adjoint[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2])
|
||||
adjoint[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2])
|
||||
adjoint[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1])
|
||||
@@ -1463,7 +1463,7 @@ matrix3_adjoint_f32 :: proc "contextless" (m: Matrix3f32) -> (adjoint: Matrix3f3
|
||||
return adjoint
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_adjoint_f64 :: proc "contextless" (m: Matrix3f64) -> (adjoint: Matrix3f64) {
|
||||
matrix3_adjoint_f64 :: proc "contextless" (m: Matrix3f64) -> (adjoint: Matrix3f64) #no_bounds_check {
|
||||
adjoint[0, 0] = +(m[1, 1] * m[2, 2] - m[2, 1] * m[1, 2])
|
||||
adjoint[0, 1] = -(m[1, 0] * m[2, 2] - m[2, 0] * m[1, 2])
|
||||
adjoint[0, 2] = +(m[1, 0] * m[2, 1] - m[2, 0] * m[1, 1])
|
||||
@@ -1503,21 +1503,21 @@ matrix3_inverse_transpose :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_scale_f16 :: proc "contextless" (s: Vector3f16) -> (m: Matrix3f16) {
|
||||
matrix3_scale_f16 :: proc "contextless" (s: Vector3f16) -> (m: Matrix3f16) #no_bounds_check {
|
||||
m[0, 0] = s[0]
|
||||
m[1, 1] = s[1]
|
||||
m[2, 2] = s[2]
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_scale_f32 :: proc "contextless" (s: Vector3f32) -> (m: Matrix3f32) {
|
||||
matrix3_scale_f32 :: proc "contextless" (s: Vector3f32) -> (m: Matrix3f32) #no_bounds_check {
|
||||
m[0, 0] = s[0]
|
||||
m[1, 1] = s[1]
|
||||
m[2, 2] = s[2]
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_scale_f64 :: proc "contextless" (s: Vector3f64) -> (m: Matrix3f64) {
|
||||
matrix3_scale_f64 :: proc "contextless" (s: Vector3f64) -> (m: Matrix3f64) #no_bounds_check {
|
||||
m[0, 0] = s[0]
|
||||
m[1, 1] = s[1]
|
||||
m[2, 2] = s[2]
|
||||
@@ -1531,7 +1531,7 @@ matrix3_scale :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> (rot: Matrix3f16) {
|
||||
matrix3_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> (rot: Matrix3f16) #no_bounds_check {
|
||||
c := math.cos(angle_radians)
|
||||
s := math.sin(angle_radians)
|
||||
|
||||
@@ -1553,7 +1553,7 @@ matrix3_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) ->
|
||||
return rot
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> (rot: Matrix3f32) {
|
||||
matrix3_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> (rot: Matrix3f32) #no_bounds_check {
|
||||
c := math.cos(angle_radians)
|
||||
s := math.sin(angle_radians)
|
||||
|
||||
@@ -1644,7 +1644,7 @@ matrix3_look_at :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix4f16) {
|
||||
matrix4_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matrix4f16) #no_bounds_check {
|
||||
qxx := q.x * q.x
|
||||
qyy := q.y * q.y
|
||||
qzz := q.z * q.z
|
||||
@@ -1672,7 +1672,7 @@ matrix4_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> (m: Matr
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix4f32) {
|
||||
matrix4_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matrix4f32) #no_bounds_check {
|
||||
qxx := q.x * q.x
|
||||
qyy := q.y * q.y
|
||||
qzz := q.z * q.z
|
||||
@@ -1700,7 +1700,7 @@ matrix4_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> (m: Matr
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix4f64) {
|
||||
matrix4_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (m: Matrix4f64) #no_bounds_check {
|
||||
qxx := q.x * q.x
|
||||
qyy := q.y * q.y
|
||||
qzz := q.z * q.z
|
||||
@@ -1783,7 +1783,7 @@ matrix4_inverse :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_minor_f16 :: proc "contextless" (m: Matrix4f16, c, r: int) -> f16 {
|
||||
matrix4_minor_f16 :: proc "contextless" (m: Matrix4f16, c, r: int) -> f16 #no_bounds_check {
|
||||
cut_down: Matrix3f16
|
||||
for i in 0..<3 {
|
||||
col := i if i < c else i+1
|
||||
@@ -1795,7 +1795,7 @@ matrix4_minor_f16 :: proc "contextless" (m: Matrix4f16, c, r: int) -> f16 {
|
||||
return matrix3_determinant(cut_down)
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_minor_f32 :: proc "contextless" (m: Matrix4f32, c, r: int) -> f32 {
|
||||
matrix4_minor_f32 :: proc "contextless" (m: Matrix4f32, c, r: int) -> f32 #no_bounds_check {
|
||||
cut_down: Matrix3f32
|
||||
for i in 0..<3 {
|
||||
col := i if i < c else i+1
|
||||
@@ -1807,7 +1807,7 @@ matrix4_minor_f32 :: proc "contextless" (m: Matrix4f32, c, r: int) -> f32 {
|
||||
return matrix3_determinant(cut_down)
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_minor_f64 :: proc "contextless" (m: Matrix4f64, c, r: int) -> f64 {
|
||||
matrix4_minor_f64 :: proc "contextless" (m: Matrix4f64, c, r: int) -> f64 #no_bounds_check {
|
||||
cut_down: Matrix3f64
|
||||
for i in 0..<3 {
|
||||
col := i if i < c else i+1
|
||||
@@ -1854,7 +1854,7 @@ matrix4_cofactor :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_adjoint_f16 :: proc "contextless" (m: Matrix4f16) -> (adjoint: Matrix4f16) {
|
||||
matrix4_adjoint_f16 :: proc "contextless" (m: Matrix4f16) -> (adjoint: Matrix4f16) #no_bounds_check {
|
||||
for i in 0..<4 {
|
||||
for j in 0..<4 {
|
||||
adjoint[i][j] = matrix4_cofactor(m, i, j)
|
||||
@@ -1863,7 +1863,7 @@ matrix4_adjoint_f16 :: proc "contextless" (m: Matrix4f16) -> (adjoint: Matrix4f1
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_adjoint_f32 :: proc "contextless" (m: Matrix4f32) -> (adjoint: Matrix4f32) {
|
||||
matrix4_adjoint_f32 :: proc "contextless" (m: Matrix4f32) -> (adjoint: Matrix4f32) #no_bounds_check {
|
||||
for i in 0..<4 {
|
||||
for j in 0..<4 {
|
||||
adjoint[i][j] = matrix4_cofactor(m, i, j)
|
||||
@@ -1872,7 +1872,7 @@ matrix4_adjoint_f32 :: proc "contextless" (m: Matrix4f32) -> (adjoint: Matrix4f3
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_adjoint_f64 :: proc "contextless" (m: Matrix4f64) -> (adjoint: Matrix4f64) {
|
||||
matrix4_adjoint_f64 :: proc "contextless" (m: Matrix4f64) -> (adjoint: Matrix4f64) #no_bounds_check {
|
||||
for i in 0..<4 {
|
||||
for j in 0..<4 {
|
||||
adjoint[i][j] = matrix4_cofactor(m, i, j)
|
||||
@@ -1888,7 +1888,7 @@ matrix4_adjoint :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_determinant_f16 :: proc "contextless" (m: Matrix4f16) -> (determinant: f16) {
|
||||
matrix4_determinant_f16 :: proc "contextless" (m: Matrix4f16) -> (determinant: f16) #no_bounds_check {
|
||||
adjoint := matrix4_adjoint(m)
|
||||
for i in 0..<4 {
|
||||
determinant += m[i][0] * adjoint[i][0]
|
||||
@@ -1896,7 +1896,7 @@ matrix4_determinant_f16 :: proc "contextless" (m: Matrix4f16) -> (determinant: f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_determinant_f32 :: proc "contextless" (m: Matrix4f32) -> (determinant: f32) {
|
||||
matrix4_determinant_f32 :: proc "contextless" (m: Matrix4f32) -> (determinant: f32) #no_bounds_check {
|
||||
adjoint := matrix4_adjoint(m)
|
||||
for i in 0..<4 {
|
||||
determinant += m[i][0] * adjoint[i][0]
|
||||
@@ -1904,7 +1904,7 @@ matrix4_determinant_f32 :: proc "contextless" (m: Matrix4f32) -> (determinant: f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_determinant_f64 :: proc "contextless" (m: Matrix4f64) -> (determinant: f64) {
|
||||
matrix4_determinant_f64 :: proc "contextless" (m: Matrix4f64) -> (determinant: f64) #no_bounds_check {
|
||||
adjoint := matrix4_adjoint(m)
|
||||
for i in 0..<4 {
|
||||
determinant += m[i][0] * adjoint[i][0]
|
||||
@@ -1919,7 +1919,7 @@ matrix4_determinant :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_inverse_transpose_f16 :: proc "contextless" (m: Matrix4f16) -> (inverse_transpose: Matrix4f16) {
|
||||
matrix4_inverse_transpose_f16 :: proc "contextless" (m: Matrix4f16) -> (inverse_transpose: Matrix4f16) #no_bounds_check {
|
||||
adjoint := matrix4_adjoint(m)
|
||||
determinant: f16 = 0
|
||||
for i in 0..<4 {
|
||||
@@ -1934,7 +1934,7 @@ matrix4_inverse_transpose_f16 :: proc "contextless" (m: Matrix4f16) -> (inverse_
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_inverse_transpose_f32 :: proc "contextless" (m: Matrix4f32) -> (inverse_transpose: Matrix4f32) {
|
||||
matrix4_inverse_transpose_f32 :: proc "contextless" (m: Matrix4f32) -> (inverse_transpose: Matrix4f32) #no_bounds_check {
|
||||
adjoint := matrix4_adjoint(m)
|
||||
determinant: f32 = 0
|
||||
for i in 0..<4 {
|
||||
@@ -1949,7 +1949,7 @@ matrix4_inverse_transpose_f32 :: proc "contextless" (m: Matrix4f32) -> (inverse_
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_inverse_transpose_f64 :: proc "contextless" (m: Matrix4f64) -> (inverse_transpose: Matrix4f64) {
|
||||
matrix4_inverse_transpose_f64 :: proc "contextless" (m: Matrix4f64) -> (inverse_transpose: Matrix4f64) #no_bounds_check {
|
||||
adjoint := matrix4_adjoint(m)
|
||||
determinant: f64 = 0
|
||||
for i in 0..<4 {
|
||||
@@ -1971,7 +1971,7 @@ matrix4_inverse_transpose :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_translate_f16 :: proc "contextless" (v: Vector3f16) -> Matrix4f16 {
|
||||
matrix4_translate_f16 :: proc "contextless" (v: Vector3f16) -> Matrix4f16 #no_bounds_check {
|
||||
m := MATRIX4F16_IDENTITY
|
||||
m[3][0] = v[0]
|
||||
m[3][1] = v[1]
|
||||
@@ -1979,7 +1979,7 @@ matrix4_translate_f16 :: proc "contextless" (v: Vector3f16) -> Matrix4f16 {
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_translate_f32 :: proc "contextless" (v: Vector3f32) -> Matrix4f32 {
|
||||
matrix4_translate_f32 :: proc "contextless" (v: Vector3f32) -> Matrix4f32 #no_bounds_check {
|
||||
m := MATRIX4F32_IDENTITY
|
||||
m[3][0] = v[0]
|
||||
m[3][1] = v[1]
|
||||
@@ -1987,7 +1987,7 @@ matrix4_translate_f32 :: proc "contextless" (v: Vector3f32) -> Matrix4f32 {
|
||||
return m
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_translate_f64 :: proc "contextless" (v: Vector3f64) -> Matrix4f64 {
|
||||
matrix4_translate_f64 :: proc "contextless" (v: Vector3f64) -> Matrix4f64 #no_bounds_check {
|
||||
m := MATRIX4F64_IDENTITY
|
||||
m[3][0] = v[0]
|
||||
m[3][1] = v[1]
|
||||
@@ -2002,7 +2002,7 @@ matrix4_translate :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> Matrix4f16 {
|
||||
matrix4_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) -> Matrix4f16 #no_bounds_check {
|
||||
c := math.cos(angle_radians)
|
||||
s := math.sin(angle_radians)
|
||||
|
||||
@@ -2029,7 +2029,7 @@ matrix4_rotate_f16 :: proc "contextless" (angle_radians: f16, v: Vector3f16) ->
|
||||
return rot
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> Matrix4f32 {
|
||||
matrix4_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) -> Matrix4f32 #no_bounds_check {
|
||||
c := math.cos(angle_radians)
|
||||
s := math.sin(angle_radians)
|
||||
|
||||
@@ -2056,7 +2056,7 @@ matrix4_rotate_f32 :: proc "contextless" (angle_radians: f32, v: Vector3f32) ->
|
||||
return rot
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_rotate_f64 :: proc "contextless" (angle_radians: f64, v: Vector3f64) -> Matrix4f64 {
|
||||
matrix4_rotate_f64 :: proc "contextless" (angle_radians: f64, v: Vector3f64) -> Matrix4f64 #no_bounds_check {
|
||||
c := math.cos(angle_radians)
|
||||
s := math.sin(angle_radians)
|
||||
|
||||
@@ -2090,7 +2090,7 @@ matrix4_rotate :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_scale_f16 :: proc "contextless" (v: Vector3f16) -> (m: Matrix4f16) {
|
||||
matrix4_scale_f16 :: proc "contextless" (v: Vector3f16) -> (m: Matrix4f16) #no_bounds_check {
|
||||
m[0][0] = v[0]
|
||||
m[1][1] = v[1]
|
||||
m[2][2] = v[2]
|
||||
@@ -2098,7 +2098,7 @@ matrix4_scale_f16 :: proc "contextless" (v: Vector3f16) -> (m: Matrix4f16) {
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_scale_f32 :: proc "contextless" (v: Vector3f32) -> (m: Matrix4f32) {
|
||||
matrix4_scale_f32 :: proc "contextless" (v: Vector3f32) -> (m: Matrix4f32) #no_bounds_check {
|
||||
m[0][0] = v[0]
|
||||
m[1][1] = v[1]
|
||||
m[2][2] = v[2]
|
||||
@@ -2106,7 +2106,7 @@ matrix4_scale_f32 :: proc "contextless" (v: Vector3f32) -> (m: Matrix4f32) {
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_scale_f64 :: proc "contextless" (v: Vector3f64) -> (m: Matrix4f64) {
|
||||
matrix4_scale_f64 :: proc "contextless" (v: Vector3f64) -> (m: Matrix4f64) #no_bounds_check {
|
||||
m[0][0] = v[0]
|
||||
m[1][1] = v[1]
|
||||
m[2][2] = v[2]
|
||||
@@ -2225,7 +2225,7 @@ matrix4_look_at_from_fru :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_perspective_f16 :: proc "contextless" (fovy, aspect, near, far: f16, flip_z_axis := true) -> (m: Matrix4f16) {
|
||||
matrix4_perspective_f16 :: proc "contextless" (fovy, aspect, near, far: f16, flip_z_axis := true) -> (m: Matrix4f16) #no_bounds_check {
|
||||
tan_half_fovy := math.tan(0.5 * fovy)
|
||||
m[0, 0] = 1 / (aspect*tan_half_fovy)
|
||||
m[1, 1] = 1 / (tan_half_fovy)
|
||||
@@ -2240,7 +2240,7 @@ matrix4_perspective_f16 :: proc "contextless" (fovy, aspect, near, far: f16, fli
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_perspective_f32 :: proc "contextless" (fovy, aspect, near, far: f32, flip_z_axis := true) -> (m: Matrix4f32) {
|
||||
matrix4_perspective_f32 :: proc "contextless" (fovy, aspect, near, far: f32, flip_z_axis := true) -> (m: Matrix4f32) #no_bounds_check {
|
||||
tan_half_fovy := math.tan(0.5 * fovy)
|
||||
m[0, 0] = 1 / (aspect*tan_half_fovy)
|
||||
m[1, 1] = 1 / (tan_half_fovy)
|
||||
@@ -2255,7 +2255,7 @@ matrix4_perspective_f32 :: proc "contextless" (fovy, aspect, near, far: f32, fli
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_perspective_f64 :: proc "contextless" (fovy, aspect, near, far: f64, flip_z_axis := true) -> (m: Matrix4f64) {
|
||||
matrix4_perspective_f64 :: proc "contextless" (fovy, aspect, near, far: f64, flip_z_axis := true) -> (m: Matrix4f64) #no_bounds_check {
|
||||
tan_half_fovy := math.tan(0.5 * fovy)
|
||||
m[0, 0] = 1 / (aspect*tan_half_fovy)
|
||||
m[1, 1] = 1 / (tan_half_fovy)
|
||||
@@ -2278,7 +2278,7 @@ matrix4_perspective :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix_ortho3d_f16 :: proc "contextless" (left, right, bottom, top, near, far: f16, flip_z_axis := true) -> (m: Matrix4f16) {
|
||||
matrix_ortho3d_f16 :: proc "contextless" (left, right, bottom, top, near, far: f16, flip_z_axis := true) -> (m: Matrix4f16) #no_bounds_check {
|
||||
m[0, 0] = +2 / (right - left)
|
||||
m[1, 1] = +2 / (top - bottom)
|
||||
m[2, 2] = +2 / (far - near)
|
||||
@@ -2294,7 +2294,7 @@ matrix_ortho3d_f16 :: proc "contextless" (left, right, bottom, top, near, far: f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix_ortho3d_f32 :: proc "contextless" (left, right, bottom, top, near, far: f32, flip_z_axis := true) -> (m: Matrix4f32) {
|
||||
matrix_ortho3d_f32 :: proc "contextless" (left, right, bottom, top, near, far: f32, flip_z_axis := true) -> (m: Matrix4f32) #no_bounds_check {
|
||||
m[0, 0] = +2 / (right - left)
|
||||
m[1, 1] = +2 / (top - bottom)
|
||||
m[2, 2] = +2 / (far - near)
|
||||
@@ -2310,7 +2310,7 @@ matrix_ortho3d_f32 :: proc "contextless" (left, right, bottom, top, near, far: f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix_ortho3d_f64 :: proc "contextless" (left, right, bottom, top, near, far: f64, flip_z_axis := true) -> (m: Matrix4f64) {
|
||||
matrix_ortho3d_f64 :: proc "contextless" (left, right, bottom, top, near, far: f64, flip_z_axis := true) -> (m: Matrix4f64) #no_bounds_check {
|
||||
m[0, 0] = +2 / (right - left)
|
||||
m[1, 1] = +2 / (top - bottom)
|
||||
m[2, 2] = +2 / (far - near)
|
||||
@@ -2334,7 +2334,7 @@ matrix_ortho3d :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_infinite_perspective_f16 :: proc "contextless" (fovy, aspect, near: f16, flip_z_axis := true) -> (m: Matrix4f16) {
|
||||
matrix4_infinite_perspective_f16 :: proc "contextless" (fovy, aspect, near: f16, flip_z_axis := true) -> (m: Matrix4f16) #no_bounds_check {
|
||||
tan_half_fovy := math.tan(0.5 * fovy)
|
||||
m[0, 0] = 1 / (aspect*tan_half_fovy)
|
||||
m[1, 1] = 1 / (tan_half_fovy)
|
||||
@@ -2349,7 +2349,7 @@ matrix4_infinite_perspective_f16 :: proc "contextless" (fovy, aspect, near: f16,
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_infinite_perspective_f32 :: proc "contextless" (fovy, aspect, near: f32, flip_z_axis := true) -> (m: Matrix4f32) {
|
||||
matrix4_infinite_perspective_f32 :: proc "contextless" (fovy, aspect, near: f32, flip_z_axis := true) -> (m: Matrix4f32) #no_bounds_check {
|
||||
tan_half_fovy := math.tan(0.5 * fovy)
|
||||
m[0, 0] = 1 / (aspect*tan_half_fovy)
|
||||
m[1, 1] = 1 / (tan_half_fovy)
|
||||
@@ -2364,7 +2364,7 @@ matrix4_infinite_perspective_f32 :: proc "contextless" (fovy, aspect, near: f32,
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_infinite_perspective_f64 :: proc "contextless" (fovy, aspect, near: f64, flip_z_axis := true) -> (m: Matrix4f64) {
|
||||
matrix4_infinite_perspective_f64 :: proc "contextless" (fovy, aspect, near: f64, flip_z_axis := true) -> (m: Matrix4f64) #no_bounds_check {
|
||||
tan_half_fovy := math.tan(0.5 * fovy)
|
||||
m[0, 0] = 1 / (aspect*tan_half_fovy)
|
||||
m[1, 1] = 1 / (tan_half_fovy)
|
||||
@@ -2387,19 +2387,19 @@ matrix4_infinite_perspective :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix2f16) {
|
||||
matrix2_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix2f16) #no_bounds_check {
|
||||
m[0, 0], m[1, 0] = f, 0
|
||||
m[0, 1], m[1, 1] = 0, f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix2f32) {
|
||||
matrix2_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix2f32) #no_bounds_check {
|
||||
m[0, 0], m[1, 0] = f, 0
|
||||
m[0, 1], m[1, 1] = 0, f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_from_scalar_f64 :: proc "contextless" (f: f64) -> (m: Matrix2f64) {
|
||||
matrix2_from_scalar_f64 :: proc "contextless" (f: f64) -> (m: Matrix2f64) #no_bounds_check {
|
||||
m[0, 0], m[1, 0] = f, 0
|
||||
m[0, 1], m[1, 1] = 0, f
|
||||
return
|
||||
@@ -2412,21 +2412,21 @@ matrix2_from_scalar :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix3f16) {
|
||||
matrix3_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix3f16) #no_bounds_check {
|
||||
m[0, 0], m[1, 0], m[2, 0] = f, 0, 0
|
||||
m[0, 1], m[1, 1], m[2, 1] = 0, f, 0
|
||||
m[0, 2], m[1, 2], m[2, 2] = 0, 0, f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix3f32) {
|
||||
matrix3_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix3f32) #no_bounds_check {
|
||||
m[0, 0], m[1, 0], m[2, 0] = f, 0, 0
|
||||
m[0, 1], m[1, 1], m[2, 1] = 0, f, 0
|
||||
m[0, 2], m[1, 2], m[2, 2] = 0, 0, f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_scalar_f64 :: proc "contextless" (f: f64) -> (m: Matrix3f64) {
|
||||
matrix3_from_scalar_f64 :: proc "contextless" (f: f64) -> (m: Matrix3f64) #no_bounds_check {
|
||||
m[0, 0], m[1, 0], m[2, 0] = f, 0, 0
|
||||
m[0, 1], m[1, 1], m[2, 1] = 0, f, 0
|
||||
m[0, 2], m[1, 2], m[2, 2] = 0, 0, f
|
||||
@@ -2440,7 +2440,7 @@ matrix3_from_scalar :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix4f16) {
|
||||
matrix4_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix4f16) #no_bounds_check {
|
||||
m[0, 0], m[1, 0], m[2, 0], m[3, 0] = f, 0, 0, 0
|
||||
m[0, 1], m[1, 1], m[2, 1], m[3, 1] = 0, f, 0, 0
|
||||
m[0, 2], m[1, 2], m[2, 2], m[3, 2] = 0, 0, f, 0
|
||||
@@ -2448,7 +2448,7 @@ matrix4_from_scalar_f16 :: proc "contextless" (f: f16) -> (m: Matrix4f16) {
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix4f32) {
|
||||
matrix4_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix4f32) #no_bounds_check {
|
||||
m[0, 0], m[1, 0], m[2, 0], m[3, 0] = f, 0, 0, 0
|
||||
m[0, 1], m[1, 1], m[2, 1], m[3, 1] = 0, f, 0, 0
|
||||
m[0, 2], m[1, 2], m[2, 2], m[3, 2] = 0, 0, f, 0
|
||||
@@ -2456,7 +2456,7 @@ matrix4_from_scalar_f32 :: proc "contextless" (f: f32) -> (m: Matrix4f32) {
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_scalar_f64 :: proc "contextless" (f: f64) -> (m: Matrix4f64) {
|
||||
matrix4_from_scalar_f64 :: proc "contextless" (f: f64) -> (m: Matrix4f64) #no_bounds_check {
|
||||
m[0, 0], m[1, 0], m[2, 0], m[3, 0] = f, 0, 0, 0
|
||||
m[0, 1], m[1, 1], m[2, 1], m[3, 1] = 0, f, 0, 0
|
||||
m[0, 2], m[1, 2], m[2, 2], m[3, 2] = 0, 0, f, 0
|
||||
@@ -2471,19 +2471,19 @@ matrix4_from_scalar :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix2f16) {
|
||||
matrix2_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix2f16) #no_bounds_check {
|
||||
r[0, 0], r[1, 0] = m[0, 0], m[1, 0]
|
||||
r[0, 1], r[1, 1] = m[0, 1], m[1, 1]
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix2f32) {
|
||||
matrix2_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix2f32) #no_bounds_check {
|
||||
r[0, 0], r[1, 0] = m[0, 0], m[1, 0]
|
||||
r[0, 1], r[1, 1] = m[0, 1], m[1, 1]
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix2f64) {
|
||||
matrix2_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix2f64) #no_bounds_check {
|
||||
r[0, 0], r[1, 0] = m[0, 0], m[1, 0]
|
||||
r[0, 1], r[1, 1] = m[0, 1], m[1, 1]
|
||||
return
|
||||
@@ -2496,19 +2496,19 @@ matrix2_from_matrix3 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (r: Matrix2f16) {
|
||||
matrix2_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (r: Matrix2f16) #no_bounds_check {
|
||||
r[0, 0], r[1, 0] = m[0, 0], m[1, 0]
|
||||
r[0, 1], r[1, 1] = m[0, 1], m[1, 1]
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (r: Matrix2f32) {
|
||||
matrix2_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (r: Matrix2f32) #no_bounds_check {
|
||||
r[0, 0], r[1, 0] = m[0, 0], m[1, 0]
|
||||
r[0, 1], r[1, 1] = m[0, 1], m[1, 1]
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (r: Matrix2f64) {
|
||||
matrix2_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (r: Matrix2f64) #no_bounds_check {
|
||||
r[0, 0], r[1, 0] = m[0, 0], m[1, 0]
|
||||
r[0, 1], r[1, 1] = m[0, 1], m[1, 1]
|
||||
return
|
||||
@@ -2521,21 +2521,21 @@ matrix2_from_matrix4 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_from_matrix2_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix3f16) {
|
||||
matrix3_from_matrix2_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix3f16) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], 0
|
||||
r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], 0
|
||||
r[0, 2], r[1, 2], r[2, 2] = 0, 0, 1
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_matrix2_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix3f32) {
|
||||
matrix3_from_matrix2_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix3f32) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], 0
|
||||
r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], 0
|
||||
r[0, 2], r[1, 2], r[2, 2] = 0, 0, 1
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_matrix2_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix3f64) {
|
||||
matrix3_from_matrix2_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix3f64) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], 0
|
||||
r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], 0
|
||||
r[0, 2], r[1, 2], r[2, 2] = 0, 0, 1
|
||||
@@ -2549,21 +2549,21 @@ matrix3_from_matrix2 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (r: Matrix3f16) {
|
||||
matrix3_from_matrix4_f16 :: proc "contextless" (m: Matrix4f16) -> (r: Matrix3f16) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], m[2, 0]
|
||||
r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], m[2, 1]
|
||||
r[0, 2], r[1, 2], r[2, 2] = m[0, 2], m[1, 2], m[2, 2]
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (r: Matrix3f32) {
|
||||
matrix3_from_matrix4_f32 :: proc "contextless" (m: Matrix4f32) -> (r: Matrix3f32) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], m[2, 0]
|
||||
r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], m[2, 1]
|
||||
r[0, 2], r[1, 2], r[2, 2] = m[0, 2], m[1, 2], m[2, 2]
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (r: Matrix3f64) {
|
||||
matrix3_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (r: Matrix3f64) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0] = m[0, 0], m[1, 0], m[2, 0]
|
||||
r[0, 1], r[1, 1], r[2, 1] = m[0, 1], m[1, 1], m[2, 1]
|
||||
r[0, 2], r[1, 2], r[2, 2] = m[0, 2], m[1, 2], m[2, 2]
|
||||
@@ -2577,7 +2577,7 @@ matrix3_from_matrix4 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_from_matrix2_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix4f16) {
|
||||
matrix4_from_matrix2_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix4f16) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], 0, 0
|
||||
r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], 0, 0
|
||||
r[0, 2], r[1, 2], r[2, 2], r[3, 2] = 0, 0, 1, 0
|
||||
@@ -2585,7 +2585,7 @@ matrix4_from_matrix2_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix4f16
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_matrix2_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix4f32) {
|
||||
matrix4_from_matrix2_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix4f32) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], 0, 0
|
||||
r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], 0, 0
|
||||
r[0, 2], r[1, 2], r[2, 2], r[3, 2] = 0, 0, 1, 0
|
||||
@@ -2593,7 +2593,7 @@ matrix4_from_matrix2_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix4f32
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_matrix2_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix4f64) {
|
||||
matrix4_from_matrix2_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix4f64) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], 0, 0
|
||||
r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], 0, 0
|
||||
r[0, 2], r[1, 2], r[2, 2], r[3, 2] = 0, 0, 1, 0
|
||||
@@ -2608,7 +2608,7 @@ matrix4_from_matrix2 :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix4_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix4f16) {
|
||||
matrix4_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix4f16) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], m[2, 0], 0
|
||||
r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], m[2, 1], 0
|
||||
r[0, 2], r[1, 2], r[2, 2], r[3, 2] = m[0, 2], m[1, 2], m[2, 2], 0
|
||||
@@ -2616,7 +2616,7 @@ matrix4_from_matrix3_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix4f16
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix4f32) {
|
||||
matrix4_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix4f32) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], m[2, 0], 0
|
||||
r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], m[2, 1], 0
|
||||
r[0, 2], r[1, 2], r[2, 2], r[3, 2] = m[0, 2], m[1, 2], m[2, 2], 0
|
||||
@@ -2624,7 +2624,7 @@ matrix4_from_matrix3_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix4f32
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix4_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix4f64) {
|
||||
matrix4_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix4f64) #no_bounds_check {
|
||||
r[0, 0], r[1, 0], r[2, 0], r[3, 0] = m[0, 0], m[1, 0], m[2, 0], 0
|
||||
r[0, 1], r[1, 1], r[2, 1], r[3, 1] = m[0, 1], m[1, 1], m[2, 1], 0
|
||||
r[0, 2], r[1, 2], r[2, 2], r[3, 2] = m[0, 2], m[1, 2], m[2, 2], 0
|
||||
@@ -2710,7 +2710,7 @@ to_quaternion :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix2_orthonormalize_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix2f16) {
|
||||
matrix2_orthonormalize_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix2f16) #no_bounds_check {
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2720,7 +2720,7 @@ matrix2_orthonormalize_f16 :: proc "contextless" (m: Matrix2f16) -> (r: Matrix2f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_orthonormalize_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix2f32) {
|
||||
matrix2_orthonormalize_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix2f32) #no_bounds_check {
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2730,7 +2730,7 @@ matrix2_orthonormalize_f32 :: proc "contextless" (m: Matrix2f32) -> (r: Matrix2f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix2_orthonormalize_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix2f64) {
|
||||
matrix2_orthonormalize_f64 :: proc "contextless" (m: Matrix2f64) -> (r: Matrix2f64) #no_bounds_check {
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2747,7 +2747,7 @@ matrix2_orthonormalize :: proc{
|
||||
|
||||
|
||||
@(require_results)
|
||||
matrix3_orthonormalize_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix3f16) {
|
||||
matrix3_orthonormalize_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix3f16) #no_bounds_check {
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2762,7 +2762,7 @@ matrix3_orthonormalize_f16 :: proc "contextless" (m: Matrix3f16) -> (r: Matrix3f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_orthonormalize_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix3f32) {
|
||||
matrix3_orthonormalize_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix3f32) #no_bounds_check {
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
@@ -2777,7 +2777,7 @@ matrix3_orthonormalize_f32 :: proc "contextless" (m: Matrix3f32) -> (r: Matrix3f
|
||||
return
|
||||
}
|
||||
@(require_results)
|
||||
matrix3_orthonormalize_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix3f64) {
|
||||
matrix3_orthonormalize_f64 :: proc "contextless" (m: Matrix3f64) -> (r: Matrix3f64) #no_bounds_check {
|
||||
r[0] = normalize(m[0])
|
||||
|
||||
d0 := dot(r[0], r[1])
|
||||
|
||||
@@ -834,3 +834,23 @@ choice :: proc(array: $T/[]$E, r: ^Rand = nil) -> (res: E) {
|
||||
}
|
||||
return array[int63_max(n, r)]
|
||||
}
|
||||
|
||||
|
||||
@(require_results)
|
||||
choice_enum :: proc($T: typeid, r: ^Rand = nil) -> T
|
||||
where
|
||||
intrinsics.type_is_enum(T),
|
||||
size_of(T) <= 8,
|
||||
len(T) == cap(T) /* Only allow contiguous enum types */
|
||||
{
|
||||
when intrinsics.type_is_unsigned(intrinsics.type_core_type(T)) &&
|
||||
u64(max(T)) > u64(max(i64)) {
|
||||
i := uint64(r) % u64(len(T))
|
||||
i += u64(min(T))
|
||||
return T(i)
|
||||
} else {
|
||||
i := int63_max(i64(len(T)), r)
|
||||
i += i64(min(T))
|
||||
return T(i)
|
||||
}
|
||||
}
|
||||
@@ -394,7 +394,8 @@ get_current_directory :: proc(allocator := context.allocator) -> string {
|
||||
}
|
||||
|
||||
set_current_directory :: proc(path: string) -> (err: Errno) {
|
||||
wstr := win32.utf8_to_wstring(path)
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||
wstr := win32.utf8_to_wstring(path, context.temp_allocator)
|
||||
|
||||
win32.AcquireSRWLockExclusive(&cwd_lock)
|
||||
|
||||
@@ -406,18 +407,7 @@ set_current_directory :: proc(path: string) -> (err: Errno) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
change_directory :: proc(path: string) -> (err: Errno) {
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||
wpath := win32.utf8_to_wstring(path, context.temp_allocator)
|
||||
|
||||
if !win32.SetCurrentDirectoryW(wpath) {
|
||||
err = Errno(win32.GetLastError())
|
||||
}
|
||||
return
|
||||
}
|
||||
change_directory :: set_current_directory
|
||||
|
||||
make_directory :: proc(path: string, mode: u32 = 0) -> (err: Errno) {
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||
|
||||
+71
-8
@@ -632,9 +632,6 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *
|
||||
|
||||
scope_reserve(ctx->scope, min_field_count);
|
||||
|
||||
rw_mutex_lock(&struct_type->Struct.fields_mutex);
|
||||
defer (rw_mutex_unlock(&struct_type->Struct.fields_mutex));
|
||||
|
||||
if (st->is_raw_union && min_field_count > 1) {
|
||||
struct_type->Struct.is_raw_union = true;
|
||||
context = str_lit("struct #raw_union");
|
||||
@@ -662,6 +659,7 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *
|
||||
gb_unused(where_clause_ok);
|
||||
}
|
||||
check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context);
|
||||
wait_signal_set(&struct_type->Struct.fields_wait_signal);
|
||||
}
|
||||
|
||||
#define ST_ALIGN(_name) if (st->_name != nullptr) { \
|
||||
@@ -2255,6 +2253,34 @@ gb_internal void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) {
|
||||
if (len_) *len_ = len;
|
||||
}
|
||||
|
||||
gb_internal Type *get_map_cell_type(Type *type) {
|
||||
i64 size, len;
|
||||
i64 elem_size = type_size_of(type);
|
||||
map_cell_size_and_len(type, &size, &len);
|
||||
|
||||
if (size == len*elem_size) {
|
||||
return type;
|
||||
}
|
||||
|
||||
if (is_power_of_two(len)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
i64 padding = size - len*elem_size;
|
||||
GB_ASSERT(padding > 0);
|
||||
|
||||
// Padding exists
|
||||
Type *s = alloc_type_struct();
|
||||
Scope *scope = create_scope(nullptr, nullptr);
|
||||
s->Struct.fields = slice_make<Entity *>(permanent_allocator(), 2);
|
||||
s->Struct.fields[0] = alloc_entity_field(scope, make_token_ident("v"), alloc_type_array(type, len), false, 0, EntityState_Resolved);
|
||||
s->Struct.fields[1] = alloc_entity_field(scope, make_token_ident("_"), alloc_type_array(t_u8, padding), false, 1, EntityState_Resolved);
|
||||
s->Struct.scope = scope;
|
||||
gb_unused(type_size_of(s));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
gb_internal void init_map_internal_types(Type *type) {
|
||||
GB_ASSERT(type->kind == Type_Map);
|
||||
GB_ASSERT(t_allocator != nullptr);
|
||||
@@ -2265,6 +2291,43 @@ gb_internal void init_map_internal_types(Type *type) {
|
||||
GB_ASSERT(key != nullptr);
|
||||
GB_ASSERT(value != nullptr);
|
||||
|
||||
|
||||
|
||||
Type *key_cell = get_map_cell_type(key);
|
||||
Type *value_cell = get_map_cell_type(value);
|
||||
|
||||
Type *metadata_type = alloc_type_struct();
|
||||
Scope *metadata_scope = create_scope(nullptr, nullptr);
|
||||
metadata_type->Struct.fields = slice_make<Entity *>(permanent_allocator(), 5);
|
||||
metadata_type->Struct.fields[0] = alloc_entity_field(metadata_scope, make_token_ident("key"), key, false, 0, EntityState_Resolved);
|
||||
metadata_type->Struct.fields[1] = alloc_entity_field(metadata_scope, make_token_ident("value"), value, false, 1, EntityState_Resolved);
|
||||
metadata_type->Struct.fields[2] = alloc_entity_field(metadata_scope, make_token_ident("hash"), t_uintptr, false, 2, EntityState_Resolved);
|
||||
metadata_type->Struct.fields[3] = alloc_entity_field(metadata_scope, make_token_ident("key_cell"), key_cell, false, 3, EntityState_Resolved);
|
||||
metadata_type->Struct.fields[4] = alloc_entity_field(metadata_scope, make_token_ident("value_cell"), value_cell, false, 4, EntityState_Resolved);
|
||||
metadata_type->Struct.scope = metadata_scope;
|
||||
metadata_type->Struct.node = nullptr;
|
||||
|
||||
gb_unused(type_size_of(metadata_type));
|
||||
|
||||
// NOTE(bill): [0]^struct{key: Key, value: Value, hash: uintptr}
|
||||
// This is a zero array to a pointer to keep the alignment to that of a pointer, and not effective the size of the final struct
|
||||
metadata_type = alloc_type_array(alloc_type_pointer(metadata_type), 0);;
|
||||
|
||||
|
||||
Scope *scope = create_scope(nullptr, nullptr);
|
||||
Type *debug_type = alloc_type_struct();
|
||||
debug_type->Struct.fields = slice_make<Entity *>(permanent_allocator(), 4);
|
||||
debug_type->Struct.fields[0] = alloc_entity_field(scope, make_token_ident("data"), t_uintptr, false, 0, EntityState_Resolved);
|
||||
debug_type->Struct.fields[1] = alloc_entity_field(scope, make_token_ident("len"), t_int, false, 1, EntityState_Resolved);
|
||||
debug_type->Struct.fields[2] = alloc_entity_field(scope, make_token_ident("allocator"), t_allocator, false, 2, EntityState_Resolved);
|
||||
debug_type->Struct.fields[3] = alloc_entity_field(scope, make_token_ident("__metadata"), metadata_type, false, 3, EntityState_Resolved);
|
||||
debug_type->Struct.scope = scope;
|
||||
debug_type->Struct.node = nullptr;
|
||||
|
||||
gb_unused(type_size_of(debug_type));
|
||||
|
||||
type->Map.debug_metadata_type = debug_type;
|
||||
|
||||
type->Map.lookup_result_type = make_optional_ok_type(value);
|
||||
}
|
||||
|
||||
@@ -2488,6 +2551,8 @@ gb_internal Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_e
|
||||
GB_ASSERT(is_type_struct(elem));
|
||||
|
||||
Type *old_struct = base_type(elem);
|
||||
|
||||
wait_signal_until_available(&old_struct->Struct.fields_wait_signal);
|
||||
field_count = old_struct->Struct.fields.count;
|
||||
|
||||
soa_struct = alloc_type_struct();
|
||||
@@ -2528,21 +2593,19 @@ gb_internal Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_e
|
||||
}
|
||||
|
||||
if (soa_kind != StructSoa_Fixed) {
|
||||
Entity *len_field = alloc_entity_field(scope, empty_token, t_int, false, cast(i32)field_count+0);
|
||||
Entity *len_field = alloc_entity_field(scope, make_token_ident("__$len"), t_int, false, cast(i32)field_count+0);
|
||||
soa_struct->Struct.fields[field_count+0] = len_field;
|
||||
add_entity(ctx, scope, nullptr, len_field);
|
||||
add_entity_use(ctx, nullptr, len_field);
|
||||
|
||||
if (soa_kind == StructSoa_Dynamic) {
|
||||
Entity *cap_field = alloc_entity_field(scope, empty_token, t_int, false, cast(i32)field_count+1);
|
||||
Entity *cap_field = alloc_entity_field(scope, make_token_ident("__$cap"), t_int, false, cast(i32)field_count+1);
|
||||
soa_struct->Struct.fields[field_count+1] = cap_field;
|
||||
add_entity(ctx, scope, nullptr, cap_field);
|
||||
add_entity_use(ctx, nullptr, cap_field);
|
||||
|
||||
Token token = {};
|
||||
token.string = str_lit("allocator");
|
||||
init_mem_allocator(ctx->checker);
|
||||
Entity *allocator_field = alloc_entity_field(scope, token, t_allocator, false, cast(i32)field_count+2);
|
||||
Entity *allocator_field = alloc_entity_field(scope, make_token_ident("allocator"), t_allocator, false, cast(i32)field_count+2);
|
||||
soa_struct->Struct.fields[field_count+2] = allocator_field;
|
||||
add_entity(ctx, scope, nullptr, allocator_field);
|
||||
add_entity_use(ctx, nullptr, allocator_field);
|
||||
|
||||
@@ -710,7 +710,9 @@ gb_internal void lb_debug_complete_types(lbModule *m) {
|
||||
|
||||
case Type_Map:
|
||||
GB_ASSERT(t_raw_map != nullptr);
|
||||
bt = base_type(t_raw_map);
|
||||
bt = base_type(bt->Map.debug_metadata_type);
|
||||
// bt = base_type(t_raw_map);
|
||||
GB_ASSERT(bt->kind == Type_Struct);
|
||||
/*fallthrough*/
|
||||
case Type_Struct:
|
||||
if (file == nullptr) {
|
||||
|
||||
@@ -107,6 +107,22 @@ gb_internal void thread_set_name (Thread *t, char const *name);
|
||||
gb_internal void yield_thread(void);
|
||||
gb_internal void yield_process(void);
|
||||
|
||||
struct Wait_Signal {
|
||||
Futex futex;
|
||||
};
|
||||
|
||||
gb_internal void wait_signal_until_available(Wait_Signal *ws) {
|
||||
if (ws->futex.load() == 0) {
|
||||
futex_wait(&ws->futex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
gb_internal void wait_signal_set(Wait_Signal *ws) {
|
||||
ws->futex.store(1);
|
||||
futex_broadcast(&ws->futex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct MutexGuard {
|
||||
MutexGuard() = delete;
|
||||
@@ -119,17 +135,25 @@ struct MutexGuard {
|
||||
explicit MutexGuard(RecursiveMutex *rm) noexcept : rm{rm} {
|
||||
mutex_lock(this->rm);
|
||||
}
|
||||
explicit MutexGuard(RwMutex *rwm) noexcept : rwm{rwm} {
|
||||
rw_mutex_lock(this->rwm);
|
||||
}
|
||||
explicit MutexGuard(BlockingMutex &bm) noexcept : bm{&bm} {
|
||||
mutex_lock(this->bm);
|
||||
}
|
||||
explicit MutexGuard(RecursiveMutex &rm) noexcept : rm{&rm} {
|
||||
mutex_lock(this->rm);
|
||||
}
|
||||
explicit MutexGuard(RwMutex &rwm) noexcept : rwm{&rwm} {
|
||||
rw_mutex_lock(this->rwm);
|
||||
}
|
||||
~MutexGuard() noexcept {
|
||||
if (this->bm) {
|
||||
mutex_unlock(this->bm);
|
||||
} else if (this->rm) {
|
||||
mutex_unlock(this->rm);
|
||||
} else if (this->rwm) {
|
||||
rw_mutex_unlock(this->rwm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,10 +161,12 @@ struct MutexGuard {
|
||||
|
||||
BlockingMutex *bm;
|
||||
RecursiveMutex *rm;
|
||||
RwMutex *rwm;
|
||||
};
|
||||
|
||||
#define MUTEX_GUARD_BLOCK(m) if (MutexGuard GB_DEFER_3(_mutex_guard_){m})
|
||||
#define MUTEX_GUARD(m) mutex_lock(m); defer (mutex_unlock(m))
|
||||
#define RW_MUTEX_GUARD(m) rw_mutex_lock(m); defer (rw_mutex_unlock(m))
|
||||
|
||||
|
||||
struct RecursiveMutex {
|
||||
|
||||
+7
-11
@@ -144,7 +144,7 @@ struct TypeStruct {
|
||||
Type * soa_elem;
|
||||
i32 soa_count;
|
||||
StructSoaKind soa_kind;
|
||||
RwMutex fields_mutex;
|
||||
Wait_Signal fields_wait_signal;
|
||||
BlockingMutex offset_mutex; // for settings offsets
|
||||
|
||||
bool is_polymorphic;
|
||||
@@ -231,6 +231,7 @@ struct TypeProc {
|
||||
Type *key; \
|
||||
Type *value; \
|
||||
Type *lookup_result_type; \
|
||||
Type *debug_metadata_type; \
|
||||
}) \
|
||||
TYPE_KIND(Struct, TypeStruct) \
|
||||
TYPE_KIND(Union, TypeUnion) \
|
||||
@@ -2968,9 +2969,8 @@ gb_internal Selection lookup_field_from_index(Type *type, i64 index) {
|
||||
isize max_count = 0;
|
||||
switch (type->kind) {
|
||||
case Type_Struct:
|
||||
rw_mutex_shared_lock(&type->Struct.fields_mutex);
|
||||
wait_signal_until_available(&type->Struct.fields_wait_signal);
|
||||
max_count = type->Struct.fields.count;
|
||||
rw_mutex_shared_unlock(&type->Struct.fields_mutex);
|
||||
break;
|
||||
case Type_Tuple: max_count = type->Tuple.variables.count; break;
|
||||
}
|
||||
@@ -2981,8 +2981,7 @@ gb_internal Selection lookup_field_from_index(Type *type, i64 index) {
|
||||
|
||||
switch (type->kind) {
|
||||
case Type_Struct: {
|
||||
rw_mutex_shared_lock(&type->Struct.fields_mutex);
|
||||
defer (rw_mutex_shared_unlock(&type->Struct.fields_mutex));
|
||||
wait_signal_until_available(&type->Struct.fields_wait_signal);
|
||||
for (isize i = 0; i < max_count; i++) {
|
||||
Entity *f = type->Struct.fields[i];
|
||||
if (f->kind == Entity_Variable) {
|
||||
@@ -3047,9 +3046,8 @@ gb_internal Selection lookup_field_with_selection(Type *type_, String field_name
|
||||
}
|
||||
}
|
||||
if (type->kind == Type_Struct) {
|
||||
rw_mutex_shared_lock(&type->Struct.fields_mutex);
|
||||
wait_signal_until_available(&type->Struct.fields_wait_signal);
|
||||
isize field_count = type->Struct.fields.count;
|
||||
rw_mutex_shared_unlock(&type->Struct.fields_mutex);
|
||||
if (field_count != 0) for_array(i, type->Struct.fields) {
|
||||
Entity *f = type->Struct.fields[i];
|
||||
if (f->flags&EntityFlag_Using) {
|
||||
@@ -3078,9 +3076,8 @@ gb_internal Selection lookup_field_with_selection(Type *type_, String field_name
|
||||
}
|
||||
|
||||
if (type->kind == Type_Struct) {
|
||||
rw_mutex_shared_lock(&type->Struct.fields_mutex);
|
||||
wait_signal_until_available(&type->Struct.fields_wait_signal);
|
||||
Scope *s = type->Struct.scope;
|
||||
rw_mutex_shared_unlock(&type->Struct.fields_mutex);
|
||||
if (s != nullptr) {
|
||||
Entity *found = scope_lookup_current(s, field_name);
|
||||
if (found != nullptr && found->kind != Entity_Variable) {
|
||||
@@ -3128,9 +3125,8 @@ gb_internal Selection lookup_field_with_selection(Type *type_, String field_name
|
||||
}
|
||||
}
|
||||
|
||||
rw_mutex_shared_lock(&type->Struct.fields_mutex);
|
||||
wait_signal_until_available(&type->Struct.fields_wait_signal);
|
||||
isize field_count = type->Struct.fields.count;
|
||||
rw_mutex_shared_unlock(&type->Struct.fields_mutex);
|
||||
if (field_count != 0) for_array(i, type->Struct.fields) {
|
||||
Entity *f = type->Struct.fields[i];
|
||||
if (f->kind != Entity_Variable || (f->flags & EntityFlag_Field) == 0) {
|
||||
|
||||
Vendored
+16
@@ -4,6 +4,7 @@ foreign import "system:d3d11.lib"
|
||||
|
||||
import "../dxgi"
|
||||
import "../d3d_compiler"
|
||||
import "core:sys/windows"
|
||||
|
||||
IUnknown :: dxgi.IUnknown
|
||||
IUnknown_VTable :: dxgi.IUnknown_VTable
|
||||
@@ -16,6 +17,7 @@ IID :: dxgi.IID
|
||||
SIZE_T :: dxgi.SIZE_T
|
||||
BOOL :: dxgi.BOOL
|
||||
UINT :: dxgi.UINT
|
||||
INT :: dxgi.INT
|
||||
|
||||
RECT :: dxgi.RECT
|
||||
SIZE :: dxgi.SIZE
|
||||
@@ -5151,3 +5153,17 @@ MESSAGE_ID :: enum u32 {
|
||||
CalcSubresource :: #force_inline proc "contextless" (MipSlice: UINT, ArraySlice: UINT, MipLevels: UINT) -> UINT {
|
||||
return MipSlice + ArraySlice * MipLevels
|
||||
}
|
||||
|
||||
ID3DUserDefinedAnnotation_UUID_STRING :: "B2DAAD8B-03D4-4DBF-95EB-32AB4B63D0AB"
|
||||
ID3DUserDefinedAnnotation_UUID := &IID{0xB2DAAD8B, 0x03D4, 0x4DBF, {0x95, 0xEB, 0x32, 0xAB, 0x4B, 0x63, 0xD0, 0xAB}}
|
||||
ID3DUserDefinedAnnotation :: struct #raw_union {
|
||||
#subtype iunknown: IUnknown,
|
||||
using vtable: ^ID3DUserDefinedAnnotation_VTable,
|
||||
}
|
||||
ID3DUserDefinedAnnotation_VTable :: struct {
|
||||
using iunknown_vtable: IUnknown_VTable,
|
||||
BeginEvent: proc "system" (this: ^ID3DUserDefinedAnnotation, Name: windows.LPCWSTR) -> INT,
|
||||
EndEvent: proc "system" (this: ^ID3DUserDefinedAnnotation) -> INT,
|
||||
SetMarker: proc "system" (this: ^ID3DUserDefinedAnnotation, Name: windows.LPCWSTR),
|
||||
GetStatus: proc "system" (this: ^ID3DUserDefinedAnnotation) -> BOOL,
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -11,6 +11,7 @@ DEBUG_RLO_FLAGS :: enum u32 { // TODO: convert to bit_set
|
||||
}
|
||||
|
||||
UINT :: win32.UINT
|
||||
INT :: win32.INT
|
||||
UINT64 :: win32.UINT64
|
||||
LPCSTR :: win32.LPCSTR
|
||||
DEBUG_ID :: win32.GUID
|
||||
|
||||
Vendored
+818
@@ -0,0 +1,818 @@
|
||||
package raylib
|
||||
|
||||
import c "core:c/libc"
|
||||
import "core:math"
|
||||
import "core:math/linalg"
|
||||
|
||||
EPSILON :: 0.000001
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Utils math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Clamp float value
|
||||
@(require_results)
|
||||
Clamp :: proc "c" (value: f32, min, max: f32) -> f32 {
|
||||
return clamp(value, min, max)
|
||||
}
|
||||
|
||||
// Calculate linear interpolation between two floats
|
||||
@(require_results)
|
||||
Lerp :: proc "c" (start, end: f32, amount: f32) -> f32 {
|
||||
return start*(1-amount) + end*amount
|
||||
}
|
||||
|
||||
// Normalize input value within input range
|
||||
@(require_results)
|
||||
Normalize :: proc "c" (value: f32, start, end: f32) -> f32 {
|
||||
return (value - start) / (end - start)
|
||||
}
|
||||
|
||||
// Remap input value within input range to output range
|
||||
@(require_results)
|
||||
Remap :: proc "c" (value: f32, inputStart, inputEnd: f32, outputStart, outputEnd: f32) -> f32 {
|
||||
return (value - inputStart)/(inputEnd - inputStart)*(outputEnd - outputStart) + outputStart
|
||||
}
|
||||
|
||||
// Wrap input value from min to max
|
||||
@(require_results)
|
||||
Wrap :: proc "c" (value: f32, min, max: f32) -> f32 {
|
||||
return value - (max - min)*math.floor((value - min)/(max - min))
|
||||
}
|
||||
|
||||
// Check whether two given floats are almost equal
|
||||
@(require_results)
|
||||
FloatEquals :: proc "c" (x, y: f32) -> bool {
|
||||
return abs(x - y) <= EPSILON*c.fmaxf(1.0, c.fmaxf(abs(x), abs(y)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vector2 math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Vector with components value 0.0
|
||||
@(require_results, deprecated="Prefer Vector2(0)")
|
||||
Vector2Zero :: proc "c" () -> Vector2 {
|
||||
return Vector2(0)
|
||||
}
|
||||
// Vector with components value 1.0
|
||||
@(require_results, deprecated="Prefer Vector2(1)")
|
||||
Vector2One :: proc "c" () -> Vector2 {
|
||||
return Vector2(1)
|
||||
}
|
||||
// Add two vectors (v1 + v2)
|
||||
@(require_results, deprecated="Prefer v1 + v2")
|
||||
Vector2Add :: proc "c" (v1, v2: Vector2) -> Vector2 {
|
||||
return v1 + v2
|
||||
}
|
||||
// Add vector and float value
|
||||
@(require_results, deprecated="Prefer v + value")
|
||||
Vector2AddValue :: proc "c" (v: Vector2, value: f32) -> Vector2 {
|
||||
return v + value
|
||||
}
|
||||
// Subtract two vectors (v1 - v2)
|
||||
@(require_results, deprecated="Prefer a - b")
|
||||
Vector2Subtract :: proc "c" (a, b: Vector2) -> Vector2 {
|
||||
return a - b
|
||||
}
|
||||
// Subtract vector by float value
|
||||
@(require_results, deprecated="Prefer v + value")
|
||||
Vector2SubtractValue :: proc "c" (v: Vector2, value: f32) -> Vector2 {
|
||||
return v - value
|
||||
}
|
||||
// Calculate vector length
|
||||
@(require_results, deprecated="Prefer linalg.length(v)")
|
||||
Vector2Length :: proc "c" (v: Vector2) -> f32 {
|
||||
return linalg.length(v)
|
||||
}
|
||||
// Calculate vector square length
|
||||
@(require_results, deprecated="Prefer linalg.length2(v)")
|
||||
Vector2LengthSqr :: proc "c" (v: Vector2) -> f32 {
|
||||
return linalg.length2(v)
|
||||
}
|
||||
// Calculate two vectors dot product
|
||||
@(require_results, deprecated="Prefer linalg.dot(v1, v2)")
|
||||
Vector2DotProduct :: proc "c" (v1, v2: Vector2) -> f32 {
|
||||
return linalg.dot(v1, v2)
|
||||
}
|
||||
// Calculate distance between two vectors
|
||||
@(require_results, deprecated="Prefer linalg.distance(v1, v2)")
|
||||
Vector2Distance :: proc "c" (v1, v2: Vector2) -> f32 {
|
||||
return linalg.distance(v1, v2)
|
||||
}
|
||||
// Calculate square distance between two vectors
|
||||
@(require_results, deprecated="Prefer linalg.length2(v2-v1)")
|
||||
Vector2DistanceSqrt :: proc "c" (v1, v2: Vector2) -> f32 {
|
||||
return linalg.length2(v2-v1)
|
||||
}
|
||||
// Calculate angle between two vectors
|
||||
// NOTE: Angle is calculated from origin point (0, 0)
|
||||
@(require_results, deprecated="Prefer linalg.angle_between(v1, v2)")
|
||||
Vector2Angle :: proc "c" (v1, v2: Vector2) -> f32 {
|
||||
return linalg.angle_between(v1, v2)
|
||||
}
|
||||
|
||||
// Calculate angle defined by a two vectors line
|
||||
// NOTE: Parameters need to be normalized
|
||||
// Current implementation should be aligned with glm::angle
|
||||
@(require_results)
|
||||
Vector2LineAngle :: proc "c" (start, end: Vector2) -> f32 {
|
||||
// TODO(10/9/2023): Currently angles move clockwise, determine if this is wanted behavior
|
||||
return -math.atan2(end.y - start.y, end.x - start.x)
|
||||
}
|
||||
|
||||
// Scale vector (multiply by value)
|
||||
@(require_results, deprecated="Prefer v * scale")
|
||||
Vector2Scale :: proc "c" (v: Vector2, scale: f32) -> Vector2 {
|
||||
return v * scale
|
||||
}
|
||||
// Multiply vector by vector
|
||||
@(require_results, deprecated="Prefer v1 * v2")
|
||||
Vector2Multiply :: proc "c" (v1, v2: Vector2) -> Vector2 {
|
||||
return v1 * v2
|
||||
}
|
||||
// Negate vector
|
||||
@(require_results, deprecated="Prefer -v")
|
||||
Vector2Negate :: proc "c" (v: Vector2) -> Vector2 {
|
||||
return -v
|
||||
}
|
||||
// Divide vector by vector
|
||||
@(require_results, deprecated="Prefer v1 / v2")
|
||||
Vector2Divide :: proc "c" (v1, v2: Vector2) -> Vector2 {
|
||||
return v1 / v2
|
||||
}
|
||||
// Normalize provided vector
|
||||
@(require_results, deprecated="Prefer linalg.normalize0(v)")
|
||||
Vector2Normalize :: proc "c" (v: Vector2) -> Vector2 {
|
||||
return linalg.normalize0(v)
|
||||
}
|
||||
// Transforms a Vector2 by a given Matrix
|
||||
@(require_results)
|
||||
Vector2Transform :: proc "c" (v: Vector2, m: Matrix) -> Vector2 {
|
||||
v4 := Vector4{v.x, v.y, 0, 0}
|
||||
return (m * v4).xy
|
||||
}
|
||||
// Calculate linear interpolation between two vectors
|
||||
@(require_results, deprecated="Prefer = linalg.lerp(v1, v2, amount)")
|
||||
Vector2Lerp :: proc "c" (v1, v2: Vector2, amount: f32) -> Vector2 {
|
||||
return linalg.lerp(v1, v2, amount)
|
||||
}
|
||||
// Calculate reflected vector to normal
|
||||
@(require_results, deprecated="Prefer = linalg.reflect(v, normal)")
|
||||
Vector2Reflect :: proc "c" (v, normal: Vector2) -> Vector2 {
|
||||
return linalg.reflect(v, normal)
|
||||
}
|
||||
// Rotate vector by angle
|
||||
@(require_results)
|
||||
Vector2Rotate :: proc "c" (v: Vector2, angle: f32) -> Vector2 {
|
||||
c, s := math.cos(angle), math.sin(angle)
|
||||
|
||||
return Vector2{
|
||||
v.x*c - v.y*s,
|
||||
v.x*s + v.y*c,
|
||||
}
|
||||
}
|
||||
|
||||
// Move Vector towards target
|
||||
@(require_results)
|
||||
Vector2MoveTowards :: proc "c" (v, target: Vector2, maxDistance: f32) -> Vector2 {
|
||||
dv := target - v
|
||||
value := linalg.dot(dv, dv)
|
||||
|
||||
if value == 0 || (maxDistance >= 0 && value <= maxDistance*maxDistance) {
|
||||
return target
|
||||
}
|
||||
|
||||
dist := math.sqrt(value)
|
||||
return v + dv/dist*maxDistance
|
||||
}
|
||||
|
||||
// Invert the given vector
|
||||
@(require_results, deprecated="Prefer 1.0/v")
|
||||
Vector2Invert :: proc "c" (v: Vector2) -> Vector2 {
|
||||
return 1.0/v
|
||||
}
|
||||
|
||||
// Clamp the components of the vector between
|
||||
// min and max values specified by the given vectors
|
||||
@(require_results)
|
||||
Vector2Clamp :: proc "c" (v: Vector2, min, max: Vector2) -> Vector2 {
|
||||
return Vector2{
|
||||
clamp(v.x, min.x, max.x),
|
||||
clamp(v.y, min.y, max.y),
|
||||
}
|
||||
}
|
||||
|
||||
// Clamp the magnitude of the vector between two min and max values
|
||||
@(require_results)
|
||||
Vector2ClampValue :: proc "c" (v: Vector2, min, max: f32) -> Vector2 {
|
||||
result := v
|
||||
|
||||
length := linalg.dot(v, v)
|
||||
if length > 0 {
|
||||
length = math.sqrt(length)
|
||||
scale := f32(1)
|
||||
if length < min {
|
||||
scale = min/length
|
||||
} else if length > max {
|
||||
scale = max/length
|
||||
}
|
||||
result = v*scale
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
Vector2Equals :: proc "c" (p, q: Vector2) -> bool {
|
||||
return FloatEquals(p.x, q.x) &&
|
||||
FloatEquals(p.y, q.y)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vector3 math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Vector with components value 0.0
|
||||
@(require_results, deprecated="Prefer Vector3(0)")
|
||||
Vector3Zero :: proc "c" () -> Vector3 {
|
||||
return Vector3(0)
|
||||
}
|
||||
// Vector with components value 1.0
|
||||
@(require_results, deprecated="Prefer Vector3(1)")
|
||||
Vector3One :: proc "c" () -> Vector3 {
|
||||
return Vector3(1)
|
||||
}
|
||||
// Add two vectors (v1 + v2)
|
||||
@(require_results, deprecated="Prefer v1 + v2")
|
||||
Vector3Add :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return v1 + v2
|
||||
}
|
||||
// Add vector and float value
|
||||
@(require_results, deprecated="Prefer v + value")
|
||||
Vector3AddValue :: proc "c" (v: Vector3, value: f32) -> Vector3 {
|
||||
return v + value
|
||||
}
|
||||
// Subtract two vectors (v1 - v2)
|
||||
@(require_results, deprecated="Prefer a - b")
|
||||
Vector3Subtract :: proc "c" (a, b: Vector3) -> Vector3 {
|
||||
return a - b
|
||||
}
|
||||
// Subtract vector by float value
|
||||
@(require_results, deprecated="Prefer v + value")
|
||||
Vector3SubtractValue :: proc "c" (v: Vector3, value: f32) -> Vector3 {
|
||||
return v - value
|
||||
}
|
||||
// Calculate vector length
|
||||
@(require_results, deprecated="Prefer linalg.length(v)")
|
||||
Vector3Length :: proc "c" (v: Vector3) -> f32 {
|
||||
return linalg.length(v)
|
||||
}
|
||||
// Calculate vector square length
|
||||
@(require_results, deprecated="Prefer linalg.length2(v)")
|
||||
Vector3LengthSqr :: proc "c" (v: Vector3) -> f32 {
|
||||
return linalg.length2(v)
|
||||
}
|
||||
// Calculate two vectors dot product
|
||||
@(require_results, deprecated="Prefer linalg.dot(v1, v2)")
|
||||
Vector3DotProduct :: proc "c" (v1, v2: Vector3) -> f32 {
|
||||
return linalg.dot(v1, v2)
|
||||
}
|
||||
// Calculate two vectors dot product
|
||||
@(require_results, deprecated="Prefer linalg.cross(v1, v2)")
|
||||
Vector3CrossProduct :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return linalg.cross(v1, v2)
|
||||
}
|
||||
// Calculate distance between two vectors
|
||||
@(require_results, deprecated="Prefer linalg.distance(v1, v2)")
|
||||
Vector3Distance :: proc "c" (v1, v2: Vector3) -> f32 {
|
||||
return linalg.distance(v1, v2)
|
||||
}
|
||||
// Calculate square distance between two vectors
|
||||
@(require_results, deprecated="Prefer linalg.length2(v2-v1)")
|
||||
Vector3DistanceSqrt :: proc "c" (v1, v2: Vector3) -> f32 {
|
||||
return linalg.length2(v2-v1)
|
||||
}
|
||||
// Calculate angle between two vectors
|
||||
// NOTE: Angle is calculated from origin point (0, 0)
|
||||
@(require_results, deprecated="Prefer linalg.angle_between(v1, v2)")
|
||||
Vector3Angle :: proc "c" (v1, v2: Vector3) -> f32 {
|
||||
return linalg.angle_between(v1, v2)
|
||||
}
|
||||
|
||||
// Calculate angle defined by a two vectors line
|
||||
// NOTE: Parameters need to be normalized
|
||||
// Current implementation should be aligned with glm::angle
|
||||
@(require_results)
|
||||
Vector3LineAngle :: proc "c" (start, end: Vector3) -> f32 {
|
||||
// TODO(10/9/2023): Currently angles move clockwise, determine if this is wanted behavior
|
||||
return -math.atan2(end.y - start.y, end.x - start.x)
|
||||
}
|
||||
|
||||
// Scale vector (multiply by value)
|
||||
@(require_results, deprecated="Prefer v * scale")
|
||||
Vector3Scale :: proc "c" (v: Vector3, scale: f32) -> Vector3 {
|
||||
return v * scale
|
||||
}
|
||||
// Multiply vector by vector
|
||||
@(require_results, deprecated="Prefer v1 * v2")
|
||||
Vector3Multiply :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return v1 * v2
|
||||
}
|
||||
// Negate vector
|
||||
@(require_results, deprecated="Prefer -v")
|
||||
Vector3Negate :: proc "c" (v: Vector3) -> Vector3 {
|
||||
return -v
|
||||
}
|
||||
// Divide vector by vector
|
||||
@(require_results, deprecated="Prefer v1 / v2")
|
||||
Vector3Divide :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return v1 / v2
|
||||
}
|
||||
// Normalize provided vector
|
||||
@(require_results, deprecated="Prefer linalg.normalize0(v)")
|
||||
Vector3Normalize :: proc "c" (v: Vector3) -> Vector3 {
|
||||
return linalg.normalize0(v)
|
||||
}
|
||||
|
||||
// Calculate the projection of the vector v1 on to v2
|
||||
@(require_results)
|
||||
Vector3Project :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return linalg.projection(v1, v2)
|
||||
}
|
||||
|
||||
// Calculate the rejection of the vector v1 on to v2
|
||||
@(require_results)
|
||||
Vector3Reject :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
mag := linalg.dot(v1, v2)/linalg.dot(v2, v2)
|
||||
return v1 - v2*mag
|
||||
}
|
||||
|
||||
// Orthonormalize provided vectors
|
||||
// Makes vectors normalized and orthogonal to each other
|
||||
// Gram-Schmidt function implementation
|
||||
Vector3OrthoNormalize :: proc "c" (v1, v2: ^Vector3) {
|
||||
v1^ = linalg.normalize0(v1^)
|
||||
v3 := linalg.normalize0(linalg.cross(v1^, v2^))
|
||||
v2^ = linalg.cross(v3, v1^)
|
||||
}
|
||||
|
||||
// Transform a vector by quaternion rotation
|
||||
@(require_results, deprecated="Prefer linalg.mul(q, v")
|
||||
Vector3RotateByQuaternion :: proc "c" (v: Vector3, q: Quaternion) -> Vector3 {
|
||||
return linalg.mul(q, v)
|
||||
}
|
||||
|
||||
// Rotates a vector around an axis
|
||||
@(require_results)
|
||||
Vector3RotateByAxisAngle :: proc "c" (v: Vector3, axis: Vector3, angle: f32) -> Vector3 {
|
||||
axis, angle := axis, angle
|
||||
|
||||
axis = linalg.normalize0(axis)
|
||||
|
||||
angle *= 0.5
|
||||
a := math.sin(angle)
|
||||
b := axis.x*a
|
||||
c := axis.y*a
|
||||
d := axis.z*a
|
||||
a = math.cos(angle)
|
||||
w := Vector3{b, c, d}
|
||||
|
||||
wv := linalg.cross(w, v)
|
||||
wwv := linalg.cross(w, wv)
|
||||
|
||||
a *= 2
|
||||
wv *= a
|
||||
|
||||
wwv *= 2
|
||||
|
||||
return v + wv + wwv
|
||||
|
||||
}
|
||||
|
||||
// Transforms a Vector3 by a given Matrix
|
||||
@(require_results)
|
||||
Vector3Transform :: proc "c" (v: Vector3, m: Matrix) -> Vector3 {
|
||||
v4 := Vector4{v.x, v.y, v.z, 0}
|
||||
return (m * v4).xyz
|
||||
}
|
||||
// Calculate linear interpolation between two vectors
|
||||
@(require_results, deprecated="Prefer = linalg.lerp(v1, v2, amount)")
|
||||
Vector3Lerp :: proc "c" (v1, v2: Vector3, amount: f32) -> Vector3 {
|
||||
return linalg.lerp(v1, v2, amount)
|
||||
}
|
||||
// Calculate reflected vector to normal
|
||||
@(require_results, deprecated="Prefer = linalg.reflect(v, normal)")
|
||||
Vector3Reflect :: proc "c" (v, normal: Vector3) -> Vector3 {
|
||||
return linalg.reflect(v, normal)
|
||||
}
|
||||
// Compute the direction of a refracted ray
|
||||
// v: normalized direction of the incoming ray
|
||||
// n: normalized normal vector of the interface of two optical media
|
||||
// r: ratio of the refractive index of the medium from where the ray comes
|
||||
// to the refractive index of the medium on the other side of the surface
|
||||
@(require_results, deprecated="Prefer = linalg.refract(v, n, r)")
|
||||
Vector3Refract :: proc "c" (v, n: Vector3, r: f32) -> Vector3 {
|
||||
return linalg.refract(v, n, r)
|
||||
}
|
||||
|
||||
// Move Vector towards target
|
||||
@(require_results)
|
||||
Vector3MoveTowards :: proc "c" (v, target: Vector3, maxDistance: f32) -> Vector3 {
|
||||
dv := target - v
|
||||
value := linalg.dot(dv, dv)
|
||||
|
||||
if value == 0 || (maxDistance >= 0 && value <= maxDistance*maxDistance) {
|
||||
return target
|
||||
}
|
||||
|
||||
dist := math.sqrt(value)
|
||||
return v + dv/dist*maxDistance
|
||||
}
|
||||
|
||||
// Invert the given vector
|
||||
@(require_results, deprecated="Prefer 1.0/v")
|
||||
Vector3Invert :: proc "c" (v: Vector3) -> Vector3 {
|
||||
return 1.0/v
|
||||
}
|
||||
|
||||
// Clamp the components of the vector between
|
||||
// min and max values specified by the given vectors
|
||||
@(require_results)
|
||||
Vector3Clamp :: proc "c" (v: Vector3, min, max: Vector3) -> Vector3 {
|
||||
return Vector3{
|
||||
clamp(v.x, min.x, max.x),
|
||||
clamp(v.y, min.y, max.y),
|
||||
clamp(v.z, min.z, max.z),
|
||||
}
|
||||
}
|
||||
|
||||
// Clamp the magnitude of the vector between two min and max values
|
||||
@(require_results)
|
||||
Vector3ClampValue :: proc "c" (v: Vector3, min, max: f32) -> Vector3 {
|
||||
result := v
|
||||
|
||||
length := linalg.dot(v, v)
|
||||
if length > 0 {
|
||||
length = math.sqrt(length)
|
||||
scale := f32(1)
|
||||
if length < min {
|
||||
scale = min/length
|
||||
} else if length > max {
|
||||
scale = max/length
|
||||
}
|
||||
result = v*scale
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
Vector3Equals :: proc "c" (p, q: Vector3) -> bool {
|
||||
return FloatEquals(p.x, q.x) &&
|
||||
FloatEquals(p.y, q.y) &&
|
||||
FloatEquals(p.z, q.z)
|
||||
}
|
||||
|
||||
|
||||
@(require_results, deprecated="Prefer linalg.min(v1, v2)")
|
||||
Vector3Min :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return linalg.min(v1, v2)
|
||||
}
|
||||
|
||||
@(require_results, deprecated="Prefer linalg.max(v1, v2)")
|
||||
Vector3Max :: proc "c" (v1, v2: Vector3) -> Vector3 {
|
||||
return linalg.max(v1, v2)
|
||||
}
|
||||
|
||||
|
||||
// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
|
||||
// NOTE: Assumes P is on the plane of the triangle
|
||||
@(require_results)
|
||||
Vector3Barycenter :: proc "c" (p: Vector3, a, b, c: Vector3) -> (result: Vector3) {
|
||||
v0 := b - a
|
||||
v1 := c - a
|
||||
v2 := p - a
|
||||
d00 := linalg.dot(v0, v0)
|
||||
d01 := linalg.dot(v0, v1)
|
||||
d11 := linalg.dot(v1, v1)
|
||||
d20 := linalg.dot(v2, v0)
|
||||
d21 := linalg.dot(v2, v1)
|
||||
|
||||
denom := d00*d11 - d01*d01
|
||||
|
||||
result.y = (d11*d20 - d01*d21)/denom
|
||||
result.z = (d00*d21 - d01*d20)/denom
|
||||
result.x = 1 - (result.z + result.y)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
// Projects a Vector3 from screen space into object space
|
||||
@(require_results)
|
||||
Vector3Unproject :: proc "c" (source: Vector3, projection: Matrix, view: Matrix) -> Vector3 {
|
||||
matViewProj := view * projection
|
||||
|
||||
matViewProjInv := linalg.inverse(matViewProj)
|
||||
|
||||
quat: Quaternion
|
||||
quat.x = source.x
|
||||
quat.y = source.z
|
||||
quat.z = source.z
|
||||
quat.w = 1
|
||||
|
||||
qtransformed := QuaternionTransform(quat, matViewProjInv)
|
||||
|
||||
return Vector3{qtransformed.x/qtransformed.w, qtransformed.y/qtransformed.w, qtransformed.z/qtransformed.w}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Matrix math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Compute matrix determinant
|
||||
@(require_results, deprecated="Prefer linalg.determinant(mat)")
|
||||
MatrixDeterminant :: proc "c" (mat: Matrix) -> f32 {
|
||||
return linalg.determinant(mat)
|
||||
}
|
||||
|
||||
// Get the trace of the matrix (sum of the values along the diagonal)
|
||||
@(require_results, deprecated="Prefer linalg.trace(mat)")
|
||||
MatrixTrace :: proc "c" (mat: Matrix) -> f32 {
|
||||
return linalg.trace(mat)
|
||||
}
|
||||
|
||||
// Transposes provided matrix
|
||||
@(require_results, deprecated="Prefer linalg.transpose(mat)")
|
||||
MatrixTranspose :: proc "c" (mat: Matrix) -> Matrix {
|
||||
return linalg.transpose(mat)
|
||||
}
|
||||
|
||||
// Invert provided matrix
|
||||
@(require_results, deprecated="Prefer linalg.inverse(mat)")
|
||||
MatrixInvert :: proc "c" (mat: Matrix) -> Matrix {
|
||||
return linalg.inverse(mat)
|
||||
}
|
||||
|
||||
// Get identity matrix
|
||||
@(require_results, deprecated="Prefer Matrix(1)")
|
||||
MatrixIdentity :: proc "c" () -> Matrix {
|
||||
return Matrix(1)
|
||||
}
|
||||
|
||||
// Add two matrices
|
||||
@(require_results, deprecated="Prefer left + right")
|
||||
MatrixAdd :: proc "c" (left, right: Matrix) -> Matrix {
|
||||
return left + right
|
||||
}
|
||||
|
||||
// Subtract two matrices (left - right)
|
||||
@(require_results, deprecated="Prefer left - right")
|
||||
MatrixSubtract :: proc "c" (left, right: Matrix) -> Matrix {
|
||||
return left - right
|
||||
}
|
||||
|
||||
// Get two matrix multiplication
|
||||
// NOTE: When multiplying matrices... the order matters!
|
||||
@(require_results, deprecated="Prefer left * right")
|
||||
MatrixMultiply :: proc "c" (left, right: Matrix) -> Matrix {
|
||||
return left * right
|
||||
}
|
||||
|
||||
// Get translation matrix
|
||||
@(require_results)
|
||||
MatrixTranslate :: proc "c" (x, y, z: f32) -> Matrix {
|
||||
return linalg.matrix4_translate(Vector3{x, y, z})
|
||||
}
|
||||
|
||||
// Create rotation matrix from axis and angle
|
||||
// NOTE: Angle should be provided in radians
|
||||
@(require_results)
|
||||
MatrixRotate :: proc "c" (axis: Vector3, angle: f32) -> Matrix {
|
||||
return linalg.matrix4_rotate(angle, axis)
|
||||
}
|
||||
|
||||
// Get x-rotation matrix
|
||||
// NOTE: Angle must be provided in radians
|
||||
@(require_results)
|
||||
MatrixRotateX :: proc "c" (angle: f32) -> Matrix {
|
||||
return linalg.matrix4_rotate(angle, Vector3{1, 0, 0})
|
||||
}
|
||||
|
||||
// Get y-rotation matrix
|
||||
// NOTE: Angle must be provided in radians
|
||||
@(require_results)
|
||||
MatrixRotateY :: proc "c" (angle: f32) -> Matrix {
|
||||
return linalg.matrix4_rotate(angle, Vector3{0, 1, 0})
|
||||
}
|
||||
|
||||
// Get z-rotation matrix
|
||||
// NOTE: Angle must be provided in radians
|
||||
@(require_results)
|
||||
MatrixRotateZ :: proc "c" (angle: f32) -> Matrix {
|
||||
return linalg.matrix4_rotate(angle, Vector3{0, 0, 1})
|
||||
}
|
||||
|
||||
// Get xyz-rotation matrix
|
||||
// NOTE: Angle must be provided in radians
|
||||
@(require_results)
|
||||
MatrixRotateXYZ :: proc "c" (angle: Vector3) -> Matrix {
|
||||
return linalg.matrix4_from_euler_angles_xyz(angle.x, angle.y, angle.z)
|
||||
}
|
||||
|
||||
// Get zyx-rotation matrix
|
||||
// NOTE: Angle must be provided in radians
|
||||
@(require_results)
|
||||
MatrixRotateZYX :: proc "c" (angle: Vector3) -> Matrix {
|
||||
return linalg.matrix4_from_euler_angles_zyx(angle.x, angle.y, angle.z)
|
||||
}
|
||||
|
||||
|
||||
// Get scaling matrix
|
||||
@(require_results)
|
||||
MatrixScale :: proc "c" (x, y, z: f32) -> Matrix {
|
||||
return linalg.matrix4_scale(Vector3{x, y, z})
|
||||
}
|
||||
|
||||
// Get orthographic projection matrix
|
||||
@(require_results)
|
||||
MatrixOrtho :: proc "c" (left, right, bottom, top, near, far: f32) -> Matrix {
|
||||
return linalg.matrix_ortho3d(left, right, bottom, top, near, far)
|
||||
}
|
||||
|
||||
// Get perspective projection matrix
|
||||
// NOTE: Fovy angle must be provided in radians
|
||||
@(require_results)
|
||||
MatrixPerspective :: proc "c" (fovY, aspect, nearPlane, farPlane: f32) -> Matrix {
|
||||
return linalg.matrix4_perspective(fovY, aspect, nearPlane, farPlane)
|
||||
}
|
||||
// Get camera look-at matrix (view matrix)
|
||||
@(require_results)
|
||||
MatrixLookAt :: proc "c" (eye, target, up: Vector3) -> Matrix {
|
||||
return linalg.matrix4_look_at(eye, target, up)
|
||||
}
|
||||
|
||||
// Get float array of matrix data
|
||||
@(require_results)
|
||||
MatrixToFloatV :: proc "c" (mat: Matrix) -> [16]f32 {
|
||||
return transmute([16]f32)mat
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Quaternion math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Add two quaternions
|
||||
@(require_results, deprecated="Prefer q1 + q2")
|
||||
QuaternionAdd :: proc "c" (q1, q2: Quaternion) -> Quaternion {
|
||||
return q1 + q2
|
||||
}
|
||||
// Add quaternion and float value
|
||||
@(require_results)
|
||||
QuaternionAddValue :: proc "c" (q: Quaternion, add: f32) -> Quaternion {
|
||||
return q + Quaternion(add)
|
||||
}
|
||||
// Subtract two quaternions
|
||||
@(require_results, deprecated="Prefer q1 - q2")
|
||||
QuaternionSubtract :: proc "c" (q1, q2: Quaternion) -> Quaternion {
|
||||
return q1 - q2
|
||||
}
|
||||
// Subtract quaternion and float value
|
||||
@(require_results)
|
||||
QuaternionSubtractValue :: proc "c" (q: Quaternion, sub: f32) -> Quaternion {
|
||||
return q - Quaternion(sub)
|
||||
}
|
||||
// Get identity quaternion
|
||||
@(require_results, deprecated="Prefer Quaternion(1)")
|
||||
QuaternionIdentity :: proc "c" () -> Quaternion {
|
||||
return 1
|
||||
}
|
||||
// Computes the length of a quaternion
|
||||
@(require_results, deprecated="Prefer abs(q)")
|
||||
QuaternionLength :: proc "c" (q: Quaternion) -> f32 {
|
||||
return abs(q)
|
||||
}
|
||||
// Normalize provided quaternion
|
||||
@(require_results, deprecated="Prefer linalg.normalize0(q)")
|
||||
QuaternionNormalize :: proc "c" (q: Quaternion) -> Quaternion {
|
||||
return linalg.normalize0(q)
|
||||
}
|
||||
// Invert provided quaternion
|
||||
@(require_results, deprecated="Prefer 1/q")
|
||||
QuaternionInvert :: proc "c" (q: Quaternion) -> Quaternion {
|
||||
return 1/q
|
||||
}
|
||||
// Calculate two quaternion multiplication
|
||||
@(require_results, deprecated="Prefer q1 * q2")
|
||||
QuaternionMultiply :: proc "c" (q1, q2: Quaternion) -> Quaternion {
|
||||
return q1 * q2
|
||||
}
|
||||
// Scale quaternion by float value
|
||||
@(require_results)
|
||||
QuaternionScale :: proc "c" (q: Quaternion, mul: f32) -> Quaternion {
|
||||
return q * Quaternion(mul)
|
||||
}
|
||||
// Divide two quaternions
|
||||
@(require_results, deprecated="Prefer q1 / q2")
|
||||
QuaternionDivide :: proc "c" (q1, q2: Quaternion) -> Quaternion {
|
||||
return q1 / q2
|
||||
}
|
||||
// Calculate linear interpolation between two quaternions
|
||||
@(require_results)
|
||||
QuaternionLerp :: proc "c" (q1, q2: Quaternion, amount: f32) -> (q3: Quaternion) {
|
||||
q3.x = q1.x + (q2.x-q1.x)*amount
|
||||
q3.y = q1.y + (q2.y-q1.y)*amount
|
||||
q3.z = q1.z + (q2.z-q1.z)*amount
|
||||
q3.w = q1.w + (q2.w-q1.w)*amount
|
||||
return
|
||||
}
|
||||
// Calculate slerp-optimized interpolation between two quaternions
|
||||
@(require_results)
|
||||
QuaternionNlerp :: proc "c" (q1, q2: Quaternion, amount: f32) -> Quaternion {
|
||||
return linalg.quaternion_nlerp(q1, q2, amount)
|
||||
}
|
||||
// Calculates spherical linear interpolation between two quaternions
|
||||
@(require_results)
|
||||
QuaternionSlerp :: proc "c" (q1, q2: Quaternion, amount: f32) -> Quaternion {
|
||||
return linalg.quaternion_slerp(q1, q2, amount)
|
||||
}
|
||||
// Calculate quaternion based on the rotation from one vector to another
|
||||
@(require_results)
|
||||
QuaternionFromVector3ToVector3 :: proc "c" (from, to: Vector3) -> Quaternion {
|
||||
return linalg.quaternion_between_two_vector3(from, to)
|
||||
}
|
||||
// Get a quaternion for a given rotation matrix
|
||||
@(require_results)
|
||||
QuaternionFromMatrix :: proc "c" (mat: Matrix) -> Quaternion {
|
||||
return linalg.quaternion_from_matrix4(mat)
|
||||
}
|
||||
// Get a matrix for a given quaternion
|
||||
@(require_results)
|
||||
QuaternionToMatrix :: proc "c" (q: Quaternion) -> Matrix {
|
||||
return linalg.matrix4_from_quaternion(q)
|
||||
}
|
||||
// Get rotation quaternion for an angle and axis NOTE: Angle must be provided in radians
|
||||
@(require_results)
|
||||
QuaternionFromAxisAngle :: proc "c" (axis: Vector3, angle: f32) -> Quaternion {
|
||||
return linalg.quaternion_angle_axis(angle, axis)
|
||||
}
|
||||
// Get the rotation angle and axis for a given quaternion
|
||||
@(require_results)
|
||||
QuaternionToAxisAngle :: proc "c" (q: Quaternion) -> (outAxis: Vector3, outAngle: f32) {
|
||||
outAngle, outAxis = linalg.angle_axis_from_quaternion(q)
|
||||
return
|
||||
}
|
||||
// Get the quaternion equivalent to Euler angles NOTE: Rotation order is ZYX
|
||||
@(require_results)
|
||||
QuaternionFromEuler :: proc "c" (pitch, yaw, roll: f32) -> Quaternion {
|
||||
return linalg.quaternion_from_pitch_yaw_roll(pitch, yaw, roll)
|
||||
}
|
||||
// Get the Euler angles equivalent to quaternion (roll, pitch, yaw) NOTE: Angles are returned in a Vector3 struct in radians
|
||||
@(require_results)
|
||||
QuaternionToEuler :: proc "c" (q: Quaternion) -> Vector3 {
|
||||
result: Vector3
|
||||
|
||||
// Roll (x-axis rotation)
|
||||
x0 := 2.0*(q.w*q.x + q.y*q.z)
|
||||
x1 := 1.0 - 2.0*(q.x*q.x + q.y*q.y)
|
||||
result.x = math.atan2(x0, x1)
|
||||
|
||||
// Pitch (y-axis rotation)
|
||||
y0 := 2.0*(q.w*q.y - q.z*q.x)
|
||||
y0 = 1.0 if y0 > 1.0 else y0
|
||||
y0 = -1.0 if y0 < -1.0 else y0
|
||||
result.y = math.asin(y0)
|
||||
|
||||
// Yaw (z-axis rotation)
|
||||
z0 := 2.0*(q.w*q.z + q.x*q.y)
|
||||
z1 := 1.0 - 2.0*(q.y*q.y + q.z*q.z)
|
||||
result.z = math.atan2(z0, z1)
|
||||
|
||||
return result
|
||||
}
|
||||
// Transform a quaternion given a transformation matrix
|
||||
@(require_results)
|
||||
QuaternionTransform :: proc "c" (q: Quaternion, mat: Matrix) -> Quaternion {
|
||||
v := mat * transmute(Vector4)q
|
||||
return transmute(Quaternion)v
|
||||
}
|
||||
// Check whether two given quaternions are almost equal
|
||||
@(require_results)
|
||||
QuaternionEquals :: proc "c" (p, q: Quaternion) -> bool {
|
||||
return FloatEquals(p.x, q.x) &&
|
||||
FloatEquals(p.y, q.y) &&
|
||||
FloatEquals(p.z, q.z) &&
|
||||
FloatEquals(p.w, q.w)
|
||||
}
|
||||
Reference in New Issue
Block a user