Skip to content

Commit 9ad0e1d

Browse files
committed
invoke operator
put now returns Unit/void
1 parent 7dcdec5 commit 9ad0e1d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/main/kotlin/glm_/gtx/gtxRotateVector.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ interface gtxRotateVector {
174174
fun orientation(res: Mat4, normal: Vec3, up: Vec3, tmp: Vec3 = Vec3()): Mat4 {
175175

176176
if (normal.x == up.x && normal.y == up.y && normal.z == up.z)
177-
return res put 1f
177+
return res(1f)
178178

179179
val rotationAxis = cross(tmp, up, normal)
180180
val angle = acos(dot(normal, up))

src/main/kotlin/glm_/mat4x4/Mat4.kt

+23-3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ data class Mat4(override var value: MutableList<Vec4>) : Mat4x4t<Vec4>(value) {
186186
Vec4(mat4[2]), Vec4(mat4[3]))
187187
}
188188

189+
infix operator fun invoke(s: Float) = invoke(s, s, s, s)
190+
infix operator fun invoke(v: Vec3) = invoke(v.x, v.y, v.z, 1f)
191+
infix operator fun invoke(v: Vec4) = invoke(v.x, v.y, v.z, v.w)
192+
193+
infix operator fun invoke(floats: FloatArray) = invoke(floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6],
194+
floats[7], floats[8], floats[9], floats[10], floats[11], floats[12], floats[13], floats[14], floats[15])
195+
196+
operator fun invoke(x: Float, y: Float, z: Float, w: Float) = invoke(
197+
x, 0f, 0f, 0f,
198+
0f, y, 0f, 0f,
199+
0f, 0f, z, 0f,
200+
0f, 0f, 0f, w)
201+
202+
inline fun invoke(a0: Float, a1: Float, a2: Float, a3: Float,
203+
b0: Float, b1: Float, b2: Float, b3: Float,
204+
c0: Float, c1: Float, c2: Float, c3: Float,
205+
d0: Float, d1: Float, d2: Float, d3: Float): Mat4 {
206+
207+
put(a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3)
208+
return this
209+
}
210+
189211
infix fun put(s: Float) = put(s, s, s, s)
190212
infix fun put(v: Vec3) = put(v.x, v.y, v.z, 1f)
191213
infix fun put(v: Vec4) = put(v.x, v.y, v.z, v.w)
@@ -202,7 +224,7 @@ data class Mat4(override var value: MutableList<Vec4>) : Mat4x4t<Vec4>(value) {
202224
fun put(a0: Float, a1: Float, a2: Float, a3: Float,
203225
b0: Float, b1: Float, b2: Float, b3: Float,
204226
c0: Float, c1: Float, c2: Float, c3: Float,
205-
d0: Float, d1: Float, d2: Float, d3: Float): Mat4 {
227+
d0: Float, d1: Float, d2: Float, d3: Float) {
206228

207229
value[0][0] = a0
208230
value[0][1] = a1
@@ -223,8 +245,6 @@ data class Mat4(override var value: MutableList<Vec4>) : Mat4x4t<Vec4>(value) {
223245
value[3][1] = d1
224246
value[3][2] = d2
225247
value[3][3] = d3
226-
227-
return this
228248
}
229249

230250
// TODO others

0 commit comments

Comments
 (0)