Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change anchor point?

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;
like image 523
Sveta Avatar asked Sep 13 '25 05:09

Sveta


1 Answers

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);
like image 123
David Rönnqvist Avatar answered Sep 15 '25 20:09

David Rönnqvist