4

I'm working with SceneKit. The object SCNNode is rotated relative to the center. How to change anchor point of the SCNNode?

SCNScene *scene = [SCNScene new];

SCNBox *boxGeometry = [SCNBox boxWithWidth:384.f height:512.f length:20.f chamferRadius:0];

SCNMaterial *material = [SCNMaterial new];
material.diffuse.contents = [UIImage imageNamed:@"material"];

SCNNode *boxNode = [SCNNode nodeWithGeometry:boxGeometry];
boxNode.geometry.firstMaterial = material;
boxNode.pivot = SCNMatrix4MakeTranslation(0.5f, 0.5f, 0.5f);
[scene.rootNode addChildNode:boxNode];

self.sceneView.scene = scene;
self.sceneView.allowsCameraControl = YES;
Sveta
  • 1,270
  • 3
  • 16
  • 33

2 Answers2

3

Your pivot transform translation is very small compared to the size of your box. It's not normalized.

If you want to translate around one of the corners you should translate half of the side in all directions.

boxNode.pivot = SCNMatrix4MakeTranslation(384.0/2.0, 512.0/2.0, 20.0/2.0);
David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • how do you rotate your object? If you are relying on `allowsCameraControl` it's the wrong approach. You need to manipulate nodes yourself (either a camera or the box). – mnuages Nov 07 '14 at 12:56
0

As a simple example :

yourSceneNode.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5),

where you change the node's position, rotation and scale properties.

SCNNode class reference explains this nicely

humblePilgrim
  • 1,818
  • 4
  • 25
  • 47