Posts

Post not yet marked as solved
0 Replies
394 Views
It’s very easy to get a rotation value: guard let bodyAnchor = anchor as? ARBodyAnchor else { continue } let bodyPosition = simd_make_float3(bodyAnchor.transform.columns.3) let bodyOrientation = Transform(matrix: bodyAnchor.transform).rotation let rotationAngleInDregree = bodyOrientation.angle * 180 / .pi Unfortunately I don’t get a result between 0 an 360°. No matter whether the person turns clockwise or the other way around I get the same values. Somewhere at 200° is a change.  What’s the best way to get a unique value between 0 and 360°?
Posted
by harald_n.
Last updated
.
Post marked as solved
1 Replies
946 Views
I use the code sample from "Capturing Body Motion in 3D"https://developer.apple.com/documentation/arkit/capturing_body_motion_in_3dI use this functionfunc session(_ session: ARSession, didUpdate anchors: [ARAnchor]) { for anchor in anchors { guard let bodyAnchor = anchor as? ARBodyAnchor else { continue } // Update the position of the character anchor's position. let bodyPosition = simd_make_float3(bodyAnchor.transform.columns.3) let bodyOrientation = Transform(matrix: bodyAnchor.transform).rotation characterAnchor.position = bodyPosition + characterOffset /// Also copy over the rotation of the body anchor, because the skeleton's pose /// in the world is relative to the body anchor's rotation. characterAnchor.orientation = bodyOrientation if let character = character, character.parent == nil { // Attach the character to its anchor as soon as // 1. the body anchor was detected and // 2. the character was loaded. characterAnchor.addChild(character) } } }Then I add the code to add or update the body joints: /// add or update joint spheres if let character = character { if jointSpheres.count <= character.jointNames.count, initalSpheresTransforms.count <= character.jointNames.count { let remainingSpheresToAdd = initalSpheresTransforms.count - jointSpheres.count if remainingSpheresToAdd > 0 { if addSphereInterval < 5 { addSphereInterval += 1 } else { addSphereInterval = 0 let sphereToAddIndex = abs(remainingSpheresToAdd - initalSpheresTransforms.count) let newSphere = CustomSphere(color: .blue, radius: 0.02) newSphere.transform = initalSpheresTransforms[sphereToAddIndex] sphereAnchor.addChild(newSphere, preservingWorldTransform: true) jointSpheres.append(newSphere) } } for i in 0.. let jointName = character.jointName(forPath: character.jointNames[i]) if let transform = bodyAnchor.skeleton.modelTransform(for: jointName) { let position = bodyPosition + simd_make_float3(transform.columns.3) jointSpheres[i].position = position jointSpheres[i].orientation = bodyOrientation } } }At first everything is okay. When the person rotate 180° the roboter follows.But the body joints stays in the same direction. How can I set the correct position of the blue body joints after the rotation?
Posted
by harald_n.
Last updated
.
Post not yet marked as solved
1 Replies
489 Views
I want to get the rotation values from ARBodyAnchor. I see the values in the console: bodyAnchor: ARBodyAnchor: 0x2828fc540 identifier="DDD1B2B4-A3BF-4F0E-8B83-2049540C3654" sessionIdentifier="E9E1006B-D4E0-A6A9-161E-FF942B1F5956" tracked=NO transform=translation=(-0.174489 -0.388840 -1.825961) rotation=(6.16° -20.73° 4.05°) How can I get the 3 values 6.16°, -20.73° and 4.05°?
Posted
by harald_n.
Last updated
.
Post marked as solved
2 Replies
4.3k Views
I would like to recognize to a tab gesture in SwiftUI with two fingers.How do I change the codevar body: some View { Image("tap-image") .gesture( TapGesture() .onEnded({ print("Tapped!") }) ) }if I only want to react to the gesture with two fingers?Thanks,Harald
Posted
by harald_n.
Last updated
.