Make_3d Class Examples

Here is a class I created at extends movie clip. It adds properties that allow you to position movie clips in 3d space. The class is pretty simple with just a few properties and methods. If you’re looking for a featured 3d class that generates solid objects take a look at Sandy or PaperVision.

The Make_3d class might be good for creating simple animated effects for interface elements. The class is really more of a 2.5D. It allows you to create the illustion of depth by scaling and positioning movie clips on the stage.

Make_3d Class

[kml_flashembed movie=”http://webdevils.com/examples/Make3d/3D_04.swf” height=”400″ width=”300″ /]

Make3d provides properties to set the X, Y and Z position of a clip. Make_3d can rotate clips around the origin. Make_3d can also change the brightness of a clip as it moves back in space. This can enhance the illusion of depth. Clips can get brighter or darker and range of the effect can be set. Make_3d also provides a setting to simulate camera angle which can be used to create more less extreme perspective effects.

Using Make_3d

Make_3d Extends the movie clip class. The Make3d Class must be set as the AS 2.0 Class in the Linkage Properties dialog box for any clip will use it. Just right click a symbol in the library and choose Linkage. Then select the Export for Actionscript option and type the name Make_3d into the AS 2.0 Class field.

The Make_3d class adds three new properties, myX, myY, myZ, to movie clips that use this class. The properties set the x y and z positin of an object. To redraw a clip on the stage in 3d space call render point after setting myX, myY or myZ.

Rendering a clip in 3d space sets that clip’s _x, _y, _xscale and _yscale, this makes the clip look like it has been moved in 3d space. Do not set these properties yourself (_x, _y, _xscale and _yscale). Rendering a clip in 3d space also uses swapdepths to set the stacking of clips. Do not use swapDepths() on a 3d clip or it will not stack correctly with other 3d clips.

setOrigin( origin_x:Number, origin_y:Number )

Use setOrigin() to set the location of the vanishing point in your scene. This will usually be in the center of the stage. Setting the X and Y values to half the width and half the height of your Flash project will get the best results. If your 3d elements will be nested within another Movie Clip, you can set the origin to 0, 0 and place the host Movie Clip’s registration point at the origin.

For example if your Movie had a width of 400 and a height of 300 you would want to set the origin to 200, 150:

mc.setOrigin( 200, 150 )

translate_3d( x:Number, y:Number, z:Number )
This method moves an object in 3d. Pass it x, y and z values of the distance you want to the object to move. The values passed to translate_3d are added to the object’s current x, y and z values. For example the following would move an object 100 units in the x, 0 in the y and 400 in the z.
mc.translate_3d( 100, 0, 400 )

position_3d( x:Number, y:Number, z:Number )
This method positions an object at a location in 3d space. Pass position_3d() the x, y and z values and the clip will move to this position. For example to move a clip to the origin you could use the following:
mc.position_3d( 0, 0, 0 )

rotate_3d( x:Number, y:Number, z:Number )
This method rotates an object around the origin. For example to rotate an object 2 degrees around the x axis, 5 degrees around the y axis and 0 degrees around the z axis you could use the following:
mc.rotate_3d( 0, 0, 0 )

renderPoint()
This method renders he clip in 3d by positioning and scaling the object based on it’s x, y and z coordinates. You should call renderPoint() after setting the myX, myY or myZ properties. If you set myX, myY and myZ in the same frame you need call renderPoint() only once to update the position of your clip. If you translate_3d(), position_3d() or rotate_3d() you do not need to call renderPoint(). These methods call renderPoint() themselves.

mc.renderPoint( 0, 0, 0 )

3 thoughts on “Make_3d Class Examples”

  1. this is an awesome set of useful classes! I think that a great addition to this would be the use of a camera value. Like something that would be able to change the position of mulitple objects in a container movieclip relative to a specific set of x, y, z values….
    A tutorial I went through on kirupa has some really good examples:
    http://www.kirupa.com/developer/actionscript/shape_camera.htm

    Also http://www.BBDO has a simple yet very effective image viewing interface that could be a pretty fun way of viewing photos.

  2. This is a really nice class, but is there a way to make it so that you can plot the points in a sphere or even an ellipse instead of a cube? Even if I plot my points so they form a circle, they still rotate as if I were rotating a cube.

Leave a Reply

Your email address will not be published. Required fields are marked *