Game Development Reference
In-Depth Information
unresolved error at this time; now you will create the missing setupCameras() meth-
od, as shown in Listing 12-6 .
Listing 12-6 . setupCameras( ) Method
func setupCameras(scene:SCNScene) {
cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.camera!.zFar = 500
cameraNode.position = SCNVector3(x: 0.0, y: 30.0, z:
200.0)
cameraNode.rotation = SCNVector4(x: 1.0, y: 0.0, z:
0.0, w: Float(-M_PI_4*0.75))
scene.rootNode.addChildNode(cameraNode)
}
Let's go over this bit of code.
You first initialize the cameraNode as a scene node ( SCNNode() ).
After you have the node initialized, you initialize the camera parameter for
the node.
For this camera, you will need to set the zFar parameter. The zFar para-
meter is the maximum distance between the camera and the visible surface.
The camera also needs a position; you will set this position to be slightly be-
hind and above the spaceman to start with. Later in the game development
you will adjust this position to follow the spaceman around the scene.
You now need to set the rotation of the camera. Currently the camera is
pointing straight ahead; however, since you put the camera slightly above
your spaceman, you need to rotate it slight down. This is exactly what setting
the w: parameter in the SCNVector4 is doing.
Now that you have completed this method, your error should be gone. If you run your
game now, you will now see the camera set to be above and behind the spaceman.
Summary
Search WWH ::




Custom Search