How to rotate object in a scene with pan gesture - SceneKit(如何使用平移手势旋转场景中的对象 - SceneKit)
本文介绍了如何使用平移手势旋转场景中的对象 - SceneKit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 Scene 工具包创建一个应用程序来解决 Rubix Cube.我有自己的多维数据集 dae 文件.这是我在 viewDidLoad 中的设置代码
I'm tying to create an app with Scene kit to solve Rubix Cube. I've my own dae file for the cube. this is my setup code in viewDidLoad
let myscene = SCNScene(named: "Rubik1.scnassets/Rubiks_Cube.dae")
scene.rootNode.addChildNode((myscene?.rootNode)!)
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
geometryNode = (scnView.scene?.rootNode.childNodeWithName("Cube",recursively: true))!
let panRecognizer = UIPanGestureRecognizer(target: self, action: "panGesture:")
scnView.addGestureRecognizer(panRecognizer)
在识别平移手势以旋转立方体时
upon recognising a pan gesture to rotate the cube
func panGesture(gestureRecognize: UIPanGestureRecognizer){
let translation = gestureRecognize.translationInView(gestureRecognize.view!)
let x = Float(translation.x)
let y = Float(-translation.y)
let anglePan = sqrt(pow(x,2)+pow(y,2))*(Float)(M_PI)/180.0
var rotationVector = SCNVector4()
rotationVector.x = -y
rotationVector.y = x
rotationVector.z = 0
rotationVector.w = anglePan
geometryNode.rotation = rotationVector
//geometryNode.transform = SCNMatrix4MakeRotation(anglePan, -y, x, 0)
if(gestureRecognize.state == UIGestureRecognizerState.Ended) {
//
}
}
上面的代码不保留以前的平移手势.如何使用旋转向量"或
above code doesn't preserve the previous pan gestures. how do I use "rotationvector" or
SCNMatrix4MakeRotation(anglePan, -y, x, 0)
旋转立方体
推荐答案
问题解决了
if(gestureRecognize.state == UIGestureRecognizerState.Ended) {
let currentPivot = geometryNode.pivot
let changePivot = SCNMatrix4Invert( geometryNode.transform)
geometryNode.pivot = SCNMatrix4Mult(changePivot, currentPivot)
geometryNode.transform = SCNMatrix4Identity
}
这篇关于如何使用平移手势旋转场景中的对象 - SceneKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:如何使用平移手势旋转场景中的对象 - SceneKit
基础教程推荐
猜你喜欢
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
