Basics of 3D



Introduction to 3D in ActionScript

The main difference between a two-dimensional (2D) object and a three-dimensional (3D) object projected on a two-dimensional screen is the addition of a third dimension to the object. The third dimension allows the object to move toward and away from viewpoint of the user.

When you explicitly set the z property of a display object to a numeric value, the object automatically creates a 3D transformation matrix. You can alter this matrix to modify the 3D transformation settings of that object.

In addition, 3D rotation differs from 2D rotation. In 2D the axis of rotation is always perpendicular to the x/y plane - in other words, on the z-axis. In 3D the axis of rotation can be around any of the x, y, or z axes. Setting the rotation and scaling properties of a display object enable it to move in 3D space.

Common 3D tasks

The following common 3D-related tasks are explored in this chapter:

  • Creating a 3D object

  • Moving an object in 3D space

  • Rotating an object in 3D space

  • Representing depth using perspective projection

  • Reordering the display list to correspond to relative z-axes so objects appear in front of one another correctly to the user

  • Transforming 3D objects using 3D matrixes

  • Using vectors to manipulate objects in 3D space

  • Using the Graphics.drawTriangles() method to create perspective

  • Using UV mapping to add bitmap textures to a 3D object

  • Setting the culling parameter of the Graphics.drawTriangles() method to speed rendering and hide parts of a 3D object that are facing away from the current point of view.

Important terms and concepts

The following reference list contains important terms that you will encounter in this chapter:
  • perspective: in a 2D plane, representation of parallel lines as converging on a vanishing point to give the illusion of depth and distance

  • projection: the production of a 2D image of a higher-dimensional object; 3D projection maps 3D points to a 2D plane

  • rotation: changing the orientation (and often the position) of an object by moving every point included in the object in a circular motion

  • transformation: altering 3D points or sets of points by translation, rotation, scale, skew, or a combination of these actions

  • translation: changing the position of an object by moving every point included in the object by the same amount in the same direction

  • vanishing point: point at which receding parallel lines seem to meet when represented in linear perspective

  • vector: a 3D vector represents a point or a location in the three-dimensional space using the Cartesian coordinates x, y, and z

  • vertex: a corner point

  • textured mesh: any point defining an object in 3D space

  • UV mapping: a way to apply a texture or bitmap to a 3D surface. UV mapping assigns values to coordinates on an image as percentages of the horizontal (U) axis and vertical (V) axis.

  • T value: the scaling factor for determining the size of a 3D object as the object moves toward, or away from, the current point of view

  • culling: rendering, or not, surfaces with specific winding. Using culling you can hide surfaces that are not visible to the current point of view.