:wave: Quick question. I using a C API using Kotli...
# kotlin-native
d
šŸ‘‹ Quick question. I using a C API using Kotlin/Native. Using C interrop, I can use the generated object
Model
which has a field
val transform: Matrix
I want to update this transform matrix but I haven’t found a way to do it.
Copy code
val model = cValue<Model> { }
// ...
model.useContents {
    // create a copy so update are lost 
    transform.useContents {
       m1 = ...
    }  
}
generated code by cinterop:
Copy code
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#L195
a
Hello! Can you tell, what exactly you’re trying to do here?
d
Hello! I’m trying to call
raylib
(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:
Copy code
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):
Copy code
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!
šŸ‘ 1