Stack Overflow Asked by vfxdev on December 12, 2020
I’d like to change the rotation of an entity so it is facing the camera at all times.
When using the convert() function on the entity to convert the camera position to the entity’s local coordinate system, the result is switching back and forth between two consecutive frames (it’s labeled "Cam Local Position" in the output).
Is this a bug or am I missing something?
var c: Cancellable?
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
c = arView.scene.subscribe(to: SceneEvents.Update.self) { (event) in
let camPosition = arView.cameraTransform.translation
print("Cam Translation: (camPosition)")
let camLocalPosition = boxAnchor.steelBox?.convert(position: camPosition, from: nil)
print("Cam Local Position: (camLocalPosition)")
let entityPosition = boxAnchor.steelBox?.position
boxAnchor.steelBox?.look(at: camLocalPosition!, from: entityPosition!, upVector: SIMD3(0.0, 1.0, 0.0), relativeTo: boxAnchor.steelBox?.parent)
}
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
Output:
Cam Translation: SIMD3<Float>(0.36585703, -0.00041653344, 0.07954807)
Cam Local Position: Optional(SIMD3<Float>(0.26085442, 0.22537412, 0.3998856))
Cam Translation: SIMD3<Float>(0.3658554, -0.00040444374, 0.07948807)
Cam Local Position: Optional(SIMD3<Float>(-0.0042985086, 0.048304867, -0.52568823))
Cam Translation: SIMD3<Float>(0.36575097, -0.0006302935, 0.079402976)
Cam Local Position: Optional(SIMD3<Float>(0.26072457, 0.22508359, 0.39980298))
Cam Translation: SIMD3<Float>(0.36571768, -0.00063559867, 0.079362795)
Cam Local Position: Optional(SIMD3<Float>(-0.004287362, 0.048378855, -0.5254265))
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP