I am trying to attach a button to user's left hand. the position is tracked. the button stays above the user's left hand. but it doesn't face the user. or it doesn't even face where the wrist is pointing. this is the main code snippet:
if (model.editWindowAdded) {
let originalMatrix = model.originFromWristLeft
let theattachment = attachments.entity(for: "sample")!
entityDummy.addChild(theattachment)
let testrotvalue = simd_quatf(real: 0.9906431, imag: SIMD3<Float>(-0.028681312, entityDummy.orientation.imag.y, 0.025926698))
entityDummy.orientation = testrotvalue
theattachment.position = [0, 0.1, 0]
var timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) {_ in
let originalMatrix = model.originFromWristLeft
print(originalMatrix.columns.0.y)
let testrotvalue = simd_quatf(real: 0.9906431, imag: SIMD3<Float>(-0.028681312,0.1, 0.025926698))
entityDummy.orientation = testrotvalue
}
}
Thank you. This is what I implemented as per my requirements. If anybody has any suggestions. feel free to add.
if (model.editWindowAdded) {
guard worldTracking.state == .running else { return }
let deviceAnchor = worldTracking.queryDeviceAnchor(atTimestamp: CACurrentMediaTime())
guard let deviceAnchor, deviceAnchor.isTracked else { return }
let theattachment = attachments.entity(for: "sample")!
entityDummy.addChild(theattachment)
entityDummy.setTransformMatrix(model.handAnchorLeft.originFromAnchorTransform, relativeTo: nil)
theattachment.position = [0, 0.1, 0]
entityDummy.look(at: SIMD3<Float>(deviceAnchor.originFromAnchorTransform.columns.3.x,deviceAnchor.originFromAnchorTransform.columns.3.y,deviceAnchor.originFromAnchorTransform.columns.3.z), from: entityDummy.position, relativeTo: nil)
let theyasix = entityDummy.transformMatrix(relativeTo: nil).gravityAligned.rotation
entityDummy.setOrientation(theyasix, relativeTo: nil)
let newOrientation1: Rotation3D
let orientation2 = Rotation3D(entityDummy.orientation(relativeTo: nil))
newOrientation1 = orientation2.rotated(by: .init(angle: .degrees(180), axis: .y))
entityDummy.setOrientation(.init(newOrientation1), relativeTo: nil)
}