2017-10-08 92 views
0

我把SCNNode放到了一個場景中。我想提供適當的空間旋轉,因爲這個節點是一個金字塔。我想Z axis指向V2點,X axis指向V1點(這些V2和V1點是動態計算的,當然在這種情況下,軸之間的角度將是90度,因爲我正確計算它們)。SCNNode方向問題

問題:我不能點X軸,因爲SCNLookAtConstraint(target: nodeWithV2)點只有Z軸,以及我看到的是,Z軸是確定的,但X軸始終是隨機的,這就是爲什麼我的金字塔方向永遠是錯的。我怎樣才能指向X軸?

這裏是我的代碼:

let pyramidGeometry = SCNPyramid(width: 0.1, height: 0.2, length: 0.001) 
pyramidGeometry.firstMaterial?.diffuse.contents = UIColor.white 
pyramidGeometry.firstMaterial?.lightingModel = .constant 
pyramidGeometry.firstMaterial?.isDoubleSided = true 
let nodePyramid = SCNNode(geometry: pyramidGeometry) 
nodePyramid.position = SCNVector3(2, 1, 2) 
parent.addChildNode(nodePyramid) 
let nodeZToLookAt = SCNNode() 
nodeZToLookAt.position = v2 
parent.addChildNode(nodeZToLookAt) 
let constraint = SCNLookAtConstraint(target: nodeZToLookAt) 
nodePyramid.constraints = [constraint] 

但是,這隻會爲Z軸方向,這就是爲什麼X軸始終是隨機的,所以旋轉始終是隨機的。如何將X軸方向設置爲我的點V1?

回答

2

起始iOS 11 SCNLookAtConstraint有一個localFront屬性,允許您更改哪個軸用於定位受約束節點。

+0

非常感謝你 –