2017-07-16 4 views
0

私は2つのSCNNodeをまとめて整列しようとしていますが、どのようにして分かりません。これは今私が持っているものです:2つのSCNNodeを水平に並べるにはどうすればいいですか?

cube.scale = SCNVector3(x: 0.1, y: 0.1, z: 0.1) 
cube.position = SCNVector3(0, 3, -3) 

cubeTwo.scale = SCNVector3(x: 0.15, y: 0.15, z: 0.15) 
cubeTwo.position = SCNVector3(0.5, 3, -3) 

cubeThree.scale = SCNVector3(x: 0.2, y: 0.2, z: 0.2) 
cubeThree.position = SCNVector3(1, 3, -3) 

どうすればいいですか?ありがとうございました!!

答えて

0

水平に揃えるには、positionのY値を同じに設定します。 Xは左右、Yは上下、Zは遠近です(カメラを動かすまで!)。

+0

私がいることを、彼らはまだ:(一緒に水平方向と垂直方向に整列していないでした、私はあなたが持っているもののスクリーンショットを含めるように.position部に –

+0

編集してオリジナルのポストをYとZを変更し、どのようにあなたが望むものと違うのかを説明してください。 –

+0

大丈夫です!もっと助けて欲しいです! –

0
parentNode.addChildNode(cube) 
parentNode.addChildNode(cubeTwo) 
parentNode.addChildNode(cubeThree) 


func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { 

    parentNode.position = self.getPositionRelativeToCameraView(distance: 1.0).position 


} 


func getPositionRelativeToCameraView(distance: Float) -> (position: SCNVector3, rotation: SCNVector4) { 
    var x = Float() 
    var y = Float() 
    var z = Float() 

    let cameraLocation = self.sceneView.pointOfView!.position //else { return (SCNVector3Zero) } 
    let rotation = self.sceneView.pointOfView!.rotation //else { return (SCNVector3Zero) } 
    let direction = calculateCameraDirection(cameraNode: rotation) 

    x = cameraLocation.x + distance * direction.x 
    y = cameraLocation.y + distance * direction.y 
    z = cameraLocation.z + distance * direction.z 

    let position = SCNVector3Make(x, y, z) 
    return (position, rotation) 
} 

func calculateCameraDirection(cameraNode: SCNVector4) -> SCNVector3 { 
    let x = -cameraNode.x 
    let y = -cameraNode.y 
    let z = -cameraNode.z 
    let w = cameraNode.w 
    let cameraRotationMatrix = GLKMatrix3Make(cos(w) + pow(x, 2) * (1 - cos(w)), 
               x * y * (1 - cos(w)) - z * sin(w), 
               x * z * (1 - cos(w)) + y*sin(w), 

               y*x*(1-cos(w)) + z*sin(w), 
               cos(w) + pow(y, 2) * (1 - cos(w)), 
               y*z*(1-cos(w)) - x*sin(w), 

               z*x*(1 - cos(w)) - y*sin(w), 
               z*y*(1 - cos(w)) + x*sin(w), 
               cos(w) + pow(z, 2) * (1 - cos(w))) 

    let cameraDirection = GLKMatrix3MultiplyVector3(cameraRotationMatrix, GLKVector3Make(0.0, 0.0, -1.0)) 
    return SCNVector3FromGLKVector3(cameraDirection) 
} 
+0

これは水平にも整列しません。 –

関連する問題