Datasheet

Chapter 1: Understanding Flash3D
13
The stage class is very useful in positioning your Flash objects and will be addressed in more detail in
the next chapter.
Adding a Camera
Along with 3D comes the concept of a camera. Theoretically a camera is just a point in 3D space that acts
as a point of view of that space. Changing the position of your camera lets you change your view in your
3D world. But in reality your camera isn t moving, it s just offsetting everything else in relation to itself.
So for example, if you want your camera to move through a maze, you have to move the maze around
your camera not the camera around the maze.
Programmatically you accomplish this by creating a camera object and giving it x, y, and z values. You
use these values to adjust the position of your objects in your scene (represented by the
statement below).
//create your camera object
camera = new Object();
camera.x = 10;
camera.y = 10;
camera.z = 100;
//loop through for all elements in your scene
scale = focalLength/(focalLength + this.z - camera.z);
this.x = (this.x - camera.x) * scale;
this.y = (this.y - camera.y) * scale;
this.xscale = this.yscale = 100 * scale;
It s important to understand that by putting the camera.z in the numerator of your scale equation
you ve actually changed the position of your singularity. This can produce some weird effects since at
the singularity your object will blow up in size and then flip.
You could continue to extend this train of thought adding many other features such as rotation and
scaling, as was done with Papervision3D. But there is a better way!
Adjusted Vanishing Point
(stageWidth/2, stageHeight/2)
Vanishing at the origin (0, 0)
Figure 1-6
c01.indd 13c01.indd 13 12/14/09 3:03:27 PM12/14/09 3:03:27 PM