0

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.

impression7vx
  • 1,728
  • 1
  • 20
  • 50
  • I just tested this in a playground and, as expected, node1 __does__ rotate together with node2 – jlsiewert Dec 01 '18 at 14:26
  • Hell, i’ll try it again lol. – impression7vx Dec 01 '18 at 18:54
  • It is impossible that yours works... `node2` never moves as it is always at position. I am in a playground, and as expected, as I rotate `node2` will rotate, however, `node1` does not move. `node2` is stuck at position `(0, 0, 1)` and never actually moves. Therefore, `node1` never rotates. – impression7vx Dec 24 '18 at 02:23

1 Answers1

1

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.

jlsiewert
  • 3,494
  • 18
  • 41
  • While I normally agree, I am trying to have a 3rd node, `look(at:)` the other node. If I just rotate a central node `node1` in your case, `node2` never actually moves, therefore, how do I get it to `look(at:)`? – impression7vx Nov 30 '18 at 14:00
  • `node2` does move and a `SCNLookAtConstraint` should work just fine. – jlsiewert Nov 30 '18 at 14:26
  • I can't use SCNLookAtConstraint as I need to alter the axes as they rotate in a specific manner. I.e., best option right now is to create a pivot – impression7vx Nov 30 '18 at 14:31