タップした座標をとってそれを3次元に直し、オブジェクトをその座標で表示しています。
pointに毎回3次元に直した座標を入れているのですが、ベクトルの向きを変えずにスマホから見て一定の距離になるようにベクトルの長さを同じに調整したいです。
アイデアとしては、正規化して単位ベクトルに直し、同じだけの大きさをかければいけると思っているのですが、SCNVector3にはその機能が用意されていないようです。
他のベクトル系のクラスを使ったりするのでしょうか?
swift
1@IBAction func dragged(_ sender: UIPanGestureRecognizer) { 2 3 let tapPoint = sender.location(in: sceneView) 4 let results = sceneView.hitTest(tapPoint, types: .featurePoint) 5 if let hitPoint = results.first { 6 let point = SCNVector3(hitPoint.worldTransform.columns.3.x, hitPoint.worldTransform.columns.3.y, hitPoint.worldTransform.columns.3.z) 7 let sphereNode = SCNNode(geometry: SCNSphere(radius: 0.02)) 8 sphereNode.position = point 9 self.sceneView.scene.rootNode.addChildNode(sphereNode) 10 sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red 11 } 12 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/02 15:13