Reputation: 1863
Let's say I have 2 SCNNodes
node1 and node2.
I want node1 to have a position of node1.position = SCNVector3(0, 0, 0)
I want node2 to have a position of node2.position = SCNVector3(0, 0, 1)
Now, I want node2 to have rotate around node1. Therefore, I attempt to do, node2.pivot = self.phone.pivot = SCNMatrix4MakeTranslation(0, 0, -1)
.
This provides the it where it rotates around node1 such that if I rotate node2 by Pi/2, then it is on top of the node, i.e., if I rotate node1.rotate(Double.pi/2, 0, 0)
it actually is on top of node1.
How can I get it where ndoe2 pivots around node1?
Edit1:
self.container = SCNNode()
self.container.position = SCNVector3(0, 0, 0)
self.node2 = SCNNode(geometry: geom2)
self.node2.position = SCNVector3(0, 0, 1)
self.container.addChildNode(self.node2)
let constraint = SCNLookAtConstraint(target: self.node2)
constraint.isGimbalLockEnabled = false
self.node1 = SCNNode(geometry: geom)
self.node1.position = SCNVector(0, 0, 0)
self.node1.constraints = [constraint]
Node1 never moves, as node2 never moves. I.e., node2 will ALWAYS be at position (0, 0, 1)
since the container is the only thing rotating.
Upvotes: 1
Views: 237
Reputation: 3554
If you don't want to deal with pivot
elements at all make use of the node hierachy.
Something like this should work
- node1
|
| - rotation center
| - node 2
Then rotate the rotation center, not node 2 directly. Since a node always rotates around it's coordinate center and a node's coordinate space is always relative to it's parent this works just fine.
Upvotes: 1