问题描述
在带有RealityKit的ARKit 4中,例如,人们可能会发现相对于骨骼基础(臀部)的左手变换。使用左手变换(相对于臀部)和臀部变换(相对于世界),如何计算相对于世界的左手变换? API在哪里?看来当我弄清楚数学公式时,可以使用SIMD API。但是我想应该有一个简单的API可以进行这种数学运算吗?谢谢。
编辑:添加一些代码以使其清晰..
guard let bodyAnchor = anchor as? ARBodyAnchor else { continue }
let skeleton = bodyArchor.skeleton
let leftHandModelTransform = skeleton.modelTransform(for: .leftHand)
// at this point. I have access to:
// hip transform (bodyArchor.tranform) which is in the world coordinate system;
// lefthand transform which is relative to hip of the skeleton model.
// what to do next? any api? or do I have to figureout math and then use simd apis ?
//
编辑:另外,有人可以推荐一本书/网页来描述如何在不同的3D计算中使用SIMD吗?我发现这篇文章(Augmented Reality 911 — Transform Matrix 4x4)确实有用。但是它没有涉及两个向量空间之间的转换。
解决方法
好的。复习了有关矩阵,3D变换和四元数的所有数学知识之后,我终于找到了解决方案!它实际上埋在RealityKit API中:
func convert(normal: SIMD3<Float>,from referenceEntity: Entity?) -> SIMD3<Float>
我必须创建两个实体才能使用此API。但是至少它能起作用...
,此代码是对Jan的回应。希望对您有所帮助。 bodyAnchor是骨骼跟踪的根锚点。
let skeleton = bodyAnchor.skeleton
let handTransform = skeleton.modelTransform(for: (ARSkeleton.JointName(rawValue: "left_handIndexStart_joint"))
let hipEntity = Entity()
hipEntity.transform = Transform(matrix: bodyAnchor.transform)
let worldEntity = Entity()
let handGlobalTransform = worldEntity.convert(transform: Transform(matrix:handTransform!),from: hipEntity)
我必须承认,这不是理想的解决方案,因为它创建了两个仅用于数学计算的实体。我相信(不会错), Apple创建了两种不同的位置操纵机制-一种是Entity具有位置,另一种是锚点。因此,如果您直接操纵实体位置,则会在此处给出数学运算。但是,我试图操纵锚点位置(并为其分配实体)。这带来了一些麻烦。