Skip to content

Commit b38fab5

Browse files
committed
mat4 operators interdependence
1 parent fc15e53 commit b38fab5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/main/kotlin/glm/mat4x4/operators/mat4_operators.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,26 @@ interface mat4x4_operators {
7272
}
7373

7474
fun times(res: Vec4, a: Mat4, b: Vec4): Vec4 {
75-
res[0] = a[0][0] * b.x + a[1][0] * b.y + a[2][0] * b.z + a[3][0] * b.w
76-
res[1] = a[0][1] * b.x + a[1][1] * b.y + a[2][1] * b.z + a[3][1] * b.w
77-
res[2] = a[0][2] * b.x + a[1][2] * b.y + a[2][2] * b.z + a[3][2] * b.w
78-
res[3] = a[0][3] * b.x + a[1][3] * b.y + a[2][3] * b.z + a[3][3] * b.w
75+
val x = a[0][0] * b.x + a[1][0] * b.y + a[2][0] * b.z + a[3][0] * b.w
76+
val y = a[0][1] * b.x + a[1][1] * b.y + a[2][1] * b.z + a[3][1] * b.w
77+
val z = a[0][2] * b.x + a[1][2] * b.y + a[2][2] * b.z + a[3][2] * b.w
78+
val w = a[0][3] * b.x + a[1][3] * b.y + a[2][3] * b.z + a[3][3] * b.w
79+
res.x = x
80+
res.y = y
81+
res.z = z
82+
res.w = w
7983
return res
8084
}
8185

8286
fun times(res: Vec4, a: Vec4, b: Mat4): Vec4 {
83-
res[0] = a.x * b[0][0] + a.y * b[0][1] + a.z * b[0][2] + a.w * b[0][3]
84-
res[1] = a.x * b[1][0] + a.y * b[1][1] + a.z * b[1][2] + a.w * b[1][3]
85-
res[2] = a.x * b[2][0] + a.y * b[2][1] + a.z * b[2][2] + a.w * b[2][3]
86-
res[3] = a.x * b[3][0] + a.y * b[3][1] + a.z * b[3][2] + a.w * b[3][3]
87+
val x = a.x * b[0][0] + a.y * b[0][1] + a.z * b[0][2] + a.w * b[0][3]
88+
val y = a.x * b[1][0] + a.y * b[1][1] + a.z * b[1][2] + a.w * b[1][3]
89+
val z = a.x * b[2][0] + a.y * b[2][1] + a.z * b[2][2] + a.w * b[2][3]
90+
val w = a.x * b[3][0] + a.y * b[3][1] + a.z * b[3][2] + a.w * b[3][3]
91+
res.x = x
92+
res.y = y
93+
res.z = z
94+
res.w = w
8795
return res
8896
}
8997

0 commit comments

Comments
 (0)