Dariusz
Dariusz

Reputation: 1046

RealityKit placing object without rotation

I'm trying to place an object/anchor in scene but every time I do it has a rotation. I can not find where the rotation is set as printing our matrices gives me 0,0,0 on rotation so I'm a little lost :

        let point = CGPoint(x: frame.midX, y: frame.midY);
        if let result = raycast(from: point, allowing: .estimatedPlane, alignment: .any).first {
            mLastObject = name
            var transform = simd_float4x4()
            transform.columns.0.x = 1.0
            transform.columns.1.y = 1.0
            transform.columns.2.z = 1.0
            transform.columns.3 = result.worldTransform.columns.3
            let resultAnchor = AnchorEntity(world: transform) // world ping
            let shadow = AnchorEntity(plane: AnchoringComponent.Target.Alignment.horizontal) // shadow ping
            resultAnchor.addChild(shadow)
            scene.anchors.append(resultAnchor)
            print("result : \(resultAnchor.transform)")
            print("result2 : \(resultAnchor.orientation)")
            
            print("shadow : \(shadow.transform)")
            print("shadow2 : \(shadow.orientation)")

Any idea how to access that rotation/remove it so it is aligned to 3d world not ipad rotation? TIA

Upvotes: 1

Views: 200

Answers (1)

maxxfrazer
maxxfrazer

Reputation: 1263

It's not clear which object is rotated wrong, shadow or resultAnchor?

When printing, print out shadow.orientation(relativeTo: nil) if that's the one rotated wrong, and you'll see the real world transform. If you want to set it to be rotated by zero, then once it's anchored in the scene call something like this:

shadow.setOrientation(
  simd_quatf(angle: 0, axis: [0, 1, 0]),
  relativeTo: nil
)

Upvotes: 1

Related Questions