如何在 Scenekit 中平滑动画运动
我正在尝试使用 Scenekit 开发自定义 GPS,到目前为止,该应用程序只是根据真实的 GPS 位置用户在 Scenekit 世界上移动蓝色立方体。
现在我只在 z 轴上移动立方体,计算纬度之间的差异。
为了简化项目,我将 CoreLocation 位置发送到 GameScene 中,并在“didRenderScene 渲染器”上使用以下代码移动立方体。
func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
let box = self.rootNode.childNode(withName: "box", recursively: true)
box?.position = SCNVector3(0, 0, zmove)
evaluate(loc: gpsLoc)
}
func evaluate(loc:CLLocation?){
if countFrame < 30 {
// skip first few frame....
} else {
guard let loc = loc else {
return
}
if isFirstStart {
lat1 = loc
print("Start \(loc.coordinate.latitude)")
isFirstStart = false
}
else {
if lat1 != loc {
print("change")
let lat2 = CLLocation(latitude: loc.coordinate.latitude, longitude: 0)
let dist = distance(lat1: lat1, lat2: lat2)
print("dist \(dist)")
zmove = zmove + dist
lat1 = loc
} else {
// no update pos
}
}
}
countFrame = countFrame + 1
}
我的问题是:
立方体看起来像根据纬度的变化正确移动,但是..由于只有当代表更改位置时才会更新 GPS 位置,因此立方体的移动并不平滑“不稳定”。
寻找一些想法如何在位置不可用时平滑动画。
这里是它移动时的样子
I'm try to develope a custom gps use Scenekit, so far the app simply move a blue cube on the Scenekit world based on the real GPS position user.
For now i move the cube only on z axis, calculating the difference between latitude.
For simplify the project i sent the CoreLocation position into the GameScene and on the "didRenderScene renderer" I move the cube with the following code.
func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
let box = self.rootNode.childNode(withName: "box", recursively: true)
box?.position = SCNVector3(0, 0, zmove)
evaluate(loc: gpsLoc)
}
func evaluate(loc:CLLocation?){
if countFrame < 30 {
// skip first few frame....
} else {
guard let loc = loc else {
return
}
if isFirstStart {
lat1 = loc
print("Start \(loc.coordinate.latitude)")
isFirstStart = false
}
else {
if lat1 != loc {
print("change")
let lat2 = CLLocation(latitude: loc.coordinate.latitude, longitude: 0)
let dist = distance(lat1: lat1, lat2: lat2)
print("dist \(dist)")
zmove = zmove + dist
lat1 = loc
} else {
// no update pos
}
}
}
countFrame = countFrame + 1
}
Here my question:
The cube looks like moving correctly base on the change of the latitude, but.. since the gps location is update only when the delegate did change location fire the change the cube movement is not smooth "jerky".
Looking for some idea how I could smooth the animation while the position is not available.
here what it looks like when it move
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论