Adam S
07/04/2023, 8:15 AMtypedef struct Ray {
Vector3 position; // Ray position (origin)
Vector3 direction; // Ray direction
} Ray;
Kotlin/Native generates a class with `val`s for the vector properties
expect class Ray(rawPtr: NativePtr) : CStructVar {
expect companion object : CStructVar.Type {}
expect val direction: Vector3 /* compiled code */
expect val position: Vector3 /* compiled code */
}
I’ve tried to create a new instance using cValue {}
val v = cValue<Ray> {
this.direction.x = 1f
this.direction.y = 2f
this.direction.z = 3f
this.position.x = 7f
this.position.y = 8f
this.position.z = 9f
}
but the direction and position vectors are still zeroAdam S
07/04/2023, 8:20 AMAdam S
07/04/2023, 8:22 AMsealed interface Ray {
/** Ray direction */
val direction: Vector3
/** Ray position (origin) */
val position: Vector3
fun readValue(): CValue<RaylibRay> {
val v = cValue<RaylibRay> {
// this.direction.x = this@Ray.direction.x
// this.direction.y = this@Ray.direction.y
// this.direction.z = this@Ray.direction.z
// this.position.x = this@Ray.position.x
// this.position.y = this@Ray.position.y
// this.position.z = this@Ray.position.z
this.direction.x = 1f
this.direction.y = 2f
this.direction.z = 3f
this.position.x = 7f
this.position.y = 8f
this.position.z = 9f
}
val dirString = v.useContents { direction.run { "[$x,$y,$z]" } }
val posString = v.useContents { position.run { "[$x,$y,$z]" } }
println("Ray(dir=$dirString,pos=$posString")
return v
}
}
and for some reason all of the wrapper class vector values, like this@Ray.position.z
, return zeroAdam S
07/04/2023, 2:57 PM