本文介绍了如何使用平移手势旋转场景中的对象 - SceneKit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
限时送ChatGPT账号..
我想用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End

![[ios.cocos2d+box2d]如何禁用自动旋转? [ios.cocos2d+box2d]如何禁用自动旋转?](/assets/images/default.png)
大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)