RealityKit, unable to rotate Entity/ AnchorEntity object!

Hey

I'm out of ideas... here is my code:

let radians = val * Float.pi / 180

/// object.mEntity = usd Entity.loadModel()
object.mEntity.orientation += simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0)

object.mEntity.transform.rotation += simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0)

object.anchorParent.transform.rotation+= simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0)

the object is a struct that holds my Entity + anchor it was attached to. I have few anchors in general, like the "initial click" position anchor, then shadow anchor on top of it, and then model entity after that. So that I can move the model with shadow/etc.

In any case, I cant rotate it, I always get "weird" rotation as output. Have a look at video > https://www.youtube.com/watch?v=9_WOfLivKvI&ab_channel=DariuszM%C4%85kowski

Accepted Reply

Hey Thank toy for the ping! I ended up getting some help from Andy Fedoroff on StackOverflow where he suggested using *= instead of +=, seems to work! I've no idea why & diving more into matrix operations now.

Thank you for your post & help

Final solution = object.mEntity.transform.rotation *= simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0)

  • Great! *= is a good solution as well. You can think of simd_quatf as similar to a transformation matrix. In order to concatenate/combine transformation matrices, you need to multiply them together, not add them. It's a similar concept with quaternions.

Add a Comment

Replies

Hi! you shouldn't need to update the anchor's parent. Can you try adding something like:

object.mEntity.orientation = simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0)

You will need to update radians every frame, which you can by updating val. simd_quatf works a bit differently from something like simd_float3, you shouldn't be adding multiple simd_quatf values together.

Hey Thank toy for the ping! I ended up getting some help from Andy Fedoroff on StackOverflow where he suggested using *= instead of +=, seems to work! I've no idea why & diving more into matrix operations now.

Thank you for your post & help

Final solution = object.mEntity.transform.rotation *= simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0)

  • Great! *= is a good solution as well. You can think of simd_quatf as similar to a transformation matrix. In order to concatenate/combine transformation matrices, you need to multiply them together, not add them. It's a similar concept with quaternions.

Add a Comment