施加力后的 ARKit 获取节点的位置
ARKit after apply force get location of node
与此问题相同的问题 how to track the position of a node after applying force in Arkit 1.5 但未得到解答所以我正在添加新问题
我有我施加力的节点 (SCNSphere)。节点有 dynamic
物理学 body。在滑动时,我使用 physicsBody?.applyForce
对 SCNNode
施加力
这一切都很好
问题是施加力后,因为它有 dynamic
body 它不断下降,我想跟踪那个位置
在 renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval)
我打印了 SCNNode
的 position
但它每次都显示相同的位置,为什么 Y 位置在向下时没有减少?
喜欢
<SCNNode: 0x280f29500 'ball' pos(-0.165368 0.3 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>
<SCNNode: 0x280f29500 'ball' pos(-0.165368 0.2 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>
<SCNNode: 0x280f29500 'ball' pos(-0.165368 0.1 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>
等等?
我是如何添加节点的
let ballWithOrientation = getNewBallNode() // return ball node + position
let ballNode = ballWithOrientation.ball // it is the SCNNode
self.sceneView.scene.rootNode.addChildNode(ballNode ?? SCNNode()) // Added to the scene
let cameraPosition = self.sceneView.pointOfView?.worldFront
let target = SCNVector3(Double(cameraPosition?.x ?? 1) * forceVector,Double (cameraPosition?.y ?? 1) * forceVector,Double(cameraPosition?.z ?? 1) * forceVector) // Vector of direction
let throwSpeed = self.calculateBestThrowSpeed(origin: ballNode!.position, target:target , timeToTarget: 0.66) Calculated vector with velocity
ballNode?.physicsBody?.applyForce(throwSpeed, asImpulse: true) // apply force
问题施加力后如何跟踪SCNNode的世界位置?
我找到了非常简单的解决方案
open var presentation: SCNNode { get }
SCNNode
的 属性 将为您提供当前节点的介绍
所以最后 ballNode.presentation.position
将为您提供节点的当前位置以及所有动画(力)
来自 Apple Docs
When you use implicit animation (see SCNTransaction) to change a node’s properties, those node properties are set immediately to their target values, even though the animated node content appears to transition from the old property values to the new. During the animation SceneKit maintains a copy of the node, called the presentation node, whose properties reflect the transitory values determined by any in-flight animations currently affecting the node.
希望对发现类似问题的人有所帮助
与此问题相同的问题 how to track the position of a node after applying force in Arkit 1.5 但未得到解答所以我正在添加新问题
我有我施加力的节点 (SCNSphere)。节点有 dynamic
物理学 body。在滑动时,我使用 physicsBody?.applyForce
对 SCNNode
施加力
这一切都很好
问题是施加力后,因为它有 dynamic
body 它不断下降,我想跟踪那个位置
在 renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval)
我打印了 SCNNode
的 position
但它每次都显示相同的位置,为什么 Y 位置在向下时没有减少?
喜欢
<SCNNode: 0x280f29500 'ball' pos(-0.165368 0.3 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>
<SCNNode: 0x280f29500 'ball' pos(-0.165368 0.2 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>
<SCNNode: 0x280f29500 'ball' pos(-0.165368 0.1 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>
等等?
我是如何添加节点的
let ballWithOrientation = getNewBallNode() // return ball node + position
let ballNode = ballWithOrientation.ball // it is the SCNNode
self.sceneView.scene.rootNode.addChildNode(ballNode ?? SCNNode()) // Added to the scene
let cameraPosition = self.sceneView.pointOfView?.worldFront
let target = SCNVector3(Double(cameraPosition?.x ?? 1) * forceVector,Double (cameraPosition?.y ?? 1) * forceVector,Double(cameraPosition?.z ?? 1) * forceVector) // Vector of direction
let throwSpeed = self.calculateBestThrowSpeed(origin: ballNode!.position, target:target , timeToTarget: 0.66) Calculated vector with velocity
ballNode?.physicsBody?.applyForce(throwSpeed, asImpulse: true) // apply force
问题施加力后如何跟踪SCNNode的世界位置?
我找到了非常简单的解决方案
open var presentation: SCNNode { get }
SCNNode
的 属性 将为您提供当前节点的介绍
所以最后 ballNode.presentation.position
将为您提供节点的当前位置以及所有动画(力)
来自 Apple Docs
When you use implicit animation (see SCNTransaction) to change a node’s properties, those node properties are set immediately to their target values, even though the animated node content appears to transition from the old property values to the new. During the animation SceneKit maintains a copy of the node, called the presentation node, whose properties reflect the transitory values determined by any in-flight animations currently affecting the node.
希望对发现类似问题的人有所帮助