我有一个球体(earthSphere),其特定的绘制点由其他较小的球体(coordinateSpheres)表示,这些球体是earthSphere的子节点。当用户点击任何coordinateSpheres时,我想旋转(earthSphere),使得tapped coordinateSphere面向摄像机。
用户当前可以旋转和缩放earthSphere。我想将摄像机保持静态在SCNVector3(x:0,y:0,z:20)并简单地旋转earthSphere(当用户点击子节点时),将子节点对准面向摄像机,就好像它是显示在前面和中间。
Example image HERE(Y +向上,-Z向外(离开))
@objc func sceneTapped(recognizer: UITapGestureRecognizer) {
let location = recognizer.location(in: self)
let hitResults = self.hitTest(location, options: nil)
if hitResults.count > 0 {
let result = hitResults[0]
let node = result.node
print("The location is:", location)
print(node.name as Any)
print(node.position)
if node.name != "earth" {
print("earth position is", self.node.position)
print("earth euler is", self.node.eulerAngles)
print("earth Presentation is", self.node.presentation.position)
print("earth transform is",self.node.transform)
print("earth scale is",self.node.scale)
print("sim world", self.node.simdWorldOrientation)
print("sim rotation",self.node.simdRotation)
print("sim front", self.node.simdWorldFront)
print("******break********")
print("denver position is", node.position)
print("denver euler is", node.eulerAngles)
print("denver Presentation is",node.presentation.position)
print("denver transform is", node.transform)
print("earth scale is", node.scale)
print("sim world", node.simdWorldOrientation)
print("sim rotation", node.simdRotation)
print("sim front", node.simdWorldFront)
}
}
}
Print data:
earth position is SCNVector3(x: 0.0, y: 0.0, z: 0.0)
earth euler is SCNVector3(x: 0.0, y: 1.57079637, z: 0.0)
earth Presentation is SCNVector3(x: 0.0, y: 0.0, z: 0.0)
earth transform is SCNMatrix4(m11: -4.37113883e-08, m12: 0.0, m13: -1.0, m14: 0.0, m21: 0.0, m22: 1.0, m23: 0.0, m24: 0.0, m31: 1.0, m32: 0.0, m33: -4.37113883e-08, m34: 0.0, m41: 0.0, m42: 0.0, m43: 0.0, m44: 1.0)
earth scale is SCNVector3(x: 1.0, y: 1.0, z: 1.0)
sim world simd_quatf(real: 0.707107, imag: float3(0.0, 0.707107, 0.0))
sim rotation float4(0.0, 1.0, 0.0, 1.5708)
sim front float3(-1.0, 0.0, -5.96046e-08)
******break********
denver position is SCNVector3(x: -3.71508956, y: 3.19556522, z: -0.993212819)
denver euler is SCNVector3(x: 0.0, y: -0.0, z: 0.0)
denver Presentation is SCNVector3(x: -3.71508956, y: 3.19556522, z: -0.993212819)
denver transform is SCNMatrix4(m11: 1.0, m12: 0.0, m13: 0.0, m14: 0.0, m21: 0.0, m22: 1.0, m23: 0.0, m24: 0.0, m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0, m41: -3.71508956, m42: 3.19556522, m43: -0.993212819, m44: 1.0)
earth scale is SCNVector3(x: 1.0, y: 1.0, z: 1.0)
sim world simd_quatf(real: 0.707107, imag: float3(0.0, 0.707107, 0.0))
sim rotation float4(0.0, 0.0, 0.0, 0.0)
sim front float3(-1.0, 0.0, -5.96046e-08)
用户从Google商家信息中选择一个位置,然后我使用Lat和Long绘制地球上的当前位置。根据提供的信息,当用户点击它时,我应该能够正确地将地球旋转到正确的方向。目前我正在使用命中测试来查找被点击的子节点,这很有效。当涉及到旋转earthSphere以便轻敲的子节点面向摄像机(面向用户)时,那就是我不知道的地方。我已经尝试了所有可用的动作,变换,欧拉角等等,我无法使它工作并且整天都在使用它。任何帮助,或正确的方向推动将不胜感激!附:我一直是SO的长期读者,并且学到了很多东西。期待一些反馈!