dwursteisen
02/05/2020, 12:04 PMModel
which has a field val transform: Matrix
I want to update this transform matrix but I havenāt found a way to do it.
val model = cValue<Model> { }
// ...
model.useContents {
// create a copy so update are lost
transform.useContents {
m1 = ...
}
}
generated code by cinterop:
public final class Model {
// ...
val transform: Matrix
}
header definition:
⢠Model: https://github.com/raysan5/raylib/blob/master/src/raylib.h#L365
⢠Matrix: https://github.com/raysan5/raylib/blob/master/src/raylib.h#L195Artyom Degtyarev [JB]
02/05/2020, 1:37 PMdwursteisen
02/05/2020, 2:05 PMraylib
(a little game engine in C) using Kotlin/Native.
You can rotate models (ie: a 3D object) using transformation.
ie: by assigning a matrix which contains all my rotations.
You can see an example (in C) here:
⢠https://github.com/raysan5/raylib/blob/master/examples/models/models_yaw_pitch_roll.c#L105
⢠https://www.raylib.com/examples/web/models/loader.html?name=models_yaw_pitch_roll
So Iām trying to do the same things but using Kotlin/Native:
val model : CValue<Model> = LoadModel("ā¦")
// ...
DrawModel(model, cubePosition, 1f, Colors.WHITE)
Where I got some issues, is how to update my transform matrix from my model.
cinterop produce this Kotlin model:
class Model(val transform: Matrix, ā¦)
I canāt reasign the transform matrix. So Iām trying now to update the matrix (each fiels of the matrix are var
).
But Iām little confuse about how to do it
-----
Waitā¦While typing this text, I may get my mistake: I didnāt correctly use copy
(I was still using the old reference of model, and not the ācopiedā model):
val model = LoadModel(ā¦).copy {
val matrix = rotatedMatrix(x, y, z)
matrix.useContents {
transform.m0 = matrix.m0
// ...
transform.m15 = matrix.m15
}
}
It seems to work.
But Iām bit surprised that I need to ācopyā an object while I just want to mutate one of its fields š¤ .
Anyway, thanks you š You help me to search deeper!