Drehen Sie mit SceneKit ein SCNode-Objekt im 3D-Raum
Ich versuche, mich in SceneKit zurechtzufinden, und als Beispiel dachte ich, ich würde versuchen, mit dem SDK ein Sonnensystem zu bauen. Ich kann SCNode-Objekte hinzufügen und deren Materialeigenschaften wie Muster und Beleuchtung konfigurieren. Außerdem kann ich die Planeten drehen, aber ich kann anscheinend nicht verstehen, wie ich sie entlang eines bestimmten Pfades "drehe".
Mein Code sieht bisher so aus:
// create a new scene
SCNScene *scene = [SCNScene scene];
// create and add a camera to the scene
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
[scene.rootNode addChildNode:cameraNode];
// place the camera
cameraNode.position = SCNVector3Make(0, 0, 2);
// create and add a 3d sphere - sun to the scene
SCNNode *sphereNode = [SCNNode node];
sphereNode.geometry = [SCNSphere sphereWithRadius:0.3];
[scene.rootNode addChildNode:sphereNode];
// create and configure a material
SCNMaterial *material = [SCNMaterial material];
material.diffuse.contents = [NSImage imageNamed:@"SunTexture"];
material.specular.contents = [NSColor whiteColor];
material.specular.intensity = 0.2;
material.locksAmbientWithDiffuse = YES;
// set the material to the 3d object geometry
sphereNode.geometry.firstMaterial = material;
// create and add a 3d sph,ere - earth to the scene
SCNNode *earthNode = [SCNNode node];
earthNode.geometry = [SCNSphere sphereWithRadius:0.15];
NSLog(@"Sun position = %f, %f, %f", sphereNode.position.x, sphereNode.position.y, sphereNode.position.z);
earthNode.position = SCNVector3Make(0.7, 0.7, 0.7);
NSLog(@"Earth position = %f, %f, %f", earthNode.position.x, earthNode.position.y, earthNode.position.z);
//earthNode.physicsBody = [SCNPhysicsBody dynamicBody];
[scene.rootNode addChildNode:earthNode];
SCNMaterial *earthMaterial = [SCNMaterial material];
earthMaterial.diffuse.contents = [NSImage imageNamed:@"EarthTexture"];
earthNode.geometry.firstMaterial = earthMaterial;
Ich habe irgendwo in AppleDocs gelesen, dass Sie Planeten im Koordinatensystem von Sun und nicht im Stammknoten hinzufügen müssen, aber ich bin mir nicht sicher, ob ich das überhaupt richtig verstanden habe.
Lassen Sie mich wissen, wie Sie dazu kommen.