Home Labs Galleries PetitOn
Page 3

Part 3. The Sandy Primitives

The Hedra

You may not know what a hedra is - I know I didn't. The simplest way to describe this creature, is to think of a hedra as two pyramids glued together at their bases. In Sandy the Hedra object is created with its mid point in the zx plane and the horizontal edges parallel to the x and z axes.

Lets see what the Hedra constructor expects! Here is the simple signature.

public function Hedra ( 	p_sName:String, 
		 	p_nHeight : Number = 100, p_nWidth : Number = 100, 
			p_nDepth : Number = 100 )

The width is measured in the x direction, the depth in the z direction and the height in the y direction. The construction is much simpler than for the other primitives. There is no choice between TRI and QUAD mode and no quality setting.

Here is the default hedra.


You can rotate and zoom as before. I have added a preliminary version of a coordinate system to the root group. I'll talk more about that later. For now it is sufficient to say that we should have the CoordinateSystem.as file in the same directory as the fla file.

In the createScene method we instantiate and add the coordinate axes, and potentially the coordinate planes.

	root.addChild( 	new CoordinateSystem( new Vector(-100,-100,-100), 
			new Vector(200,200,200), 
			new Vector(0xff0000, 0x00ff00,0x0000ff) ));

The first argument vector contains the starting points for the three axes, the second the length of the axes and the third the colors of the axes. If we want to create the coordinate planes, these arguments are followed by three Boolean values, one for each coordinate plane. When set to true, the plane is created.

I will use this coordinate axes and planes throughout this tutorial series, as a reference to make translations and rotations understandable.

The Sphere

Like the plane and the cube, the sphere is one of the standard primitives, implemented by many 3D systems. Here is the Sphere constructor.

function Sphere( 	p_sName:String=null , p_nRadius:Number=100, 
		p_nSegmentsW:Number=8, p_nSegmentsH:Number=6 )

The radius is 100 by default.
The quality can be set as number of segments, or polygons, horizontally and vertically.

This is the default Sphere.

I had to retract the camera to z = - 300, to get a good look at the sphere.
It is obvious, that the roundness is rough to put it mild. The doubly curved nature of the sphere surface requires more polygons, which leads to more calculations in the rendering engine.

Let's try to get a better sphere, by setting the horizontal and vertical quality to 20.

shape = new Sphere('Sphere 2', 80, 20, 20);
Sphere 2 Sphere 3

The sphere clearly has has a more rounded appearance, and it gets better yet, when we use the ColorMaterial without the LineAttribute. As we shall see in the upcoming material session, this is improved further, when we dress the sphere in a bitmap material.

The Line3D

There are times when we just want to draw lines in 3D space, as in the case of my coordinate axes. It could be done by giving 3D bodies extreme height  and width values, but that would require a lot of calculations for very small polygons we don't see.

The Line3D lets us draw straight lines in our world. To get a grasp of how this is done, lets se the constructor signature. This is how it looks:

public function Line3D ( p_sName:String, ...rest )

Oh well. Not much to learn from this. The author has used the new possibility to have an anonymous parameter list, the ...rest. The method checks the list to see what arguments are passed and uses them. What's going on inside the metod is mot refelcted in the signature. We'll have to resort to the documentation, which says:

 * @param p_sName	A string identifier for this object
 * @param ...rest 	p_V1 ... p_Vn  A comma delimited list of Vector objects

So this is easy. We decide on how many points we like, create a vector for each and pass them to the Line3D constructor.

Let's say we want a U-shape starting in the zx plane at (-50, 0, -50 ) line to ( 50, 0, 50 ) upwards to ( 50, 50, 50 ) and back to the point above the start point. Here is the createScene method for that case.

// Create the root Group and the object tree 
private function createScene():Group
	var root:Group = new Group();
	shape = new Line3D('Line', 	new Vector(-50,0,-50), 
				new Vector(50,0,50), 
				new Vector(50,50,50), 
				new Vector(-50,50,-50)  );
	var material:Material = new WireFrameMaterial(3, 0xFF6600);
	var app:Appearance = new Appearance( material );
	shape.appearance = app;
	root.addChild( shape );
	root.addChild( new CoordinateSystem( new Vector(-100,-100,-100), 
					new Vector(200,200,200), 
					new Vector(0xff0000, 0x00ff00,0x0000ff), 
					true, true, true ));
	return root;

The line can only be dressed in WireFrameMaterial, and we can set its line thickness and color. To really see where in space the line is drawn, I have included the coordinate planes.

To see a little better how the line is drawn relative to the global system, I moved the camera upwards and to the side, and then turned it to look at the center of the world.
Here are the new camera settings:

	world.camera.z = -300;
	world.camera.x = 30;
	world.camera.y = 40;
	world.camera.lookAt(0,0,0); // Points the camera at the origin

Next The versatile cylinder.