Pixas Tutorial Series Part 3: Primitives

This entry is part 3 of 5 in the Pixas tutorial series
part 1: building your first application
part 2: coordinate system
• part 3: primitives
part 4: color
part 5: dimension

Primitives are basic geometric shapes such as cube, pyramid. Due to the pixel arrangement restriction, we only care about isometric primitives in Pixas.

Since now Pixas has a set of 5 primitive 9 primitive shapes, and more isometric primitives will be added into this engine in the future. These primitives are showed as follow:
• Update: 4 directions Slope primitives have been added

For each primitive, we will go through the parameters for the constructor.

Brick
public function Brick(_dms:BrickDms = null, _color:SideColor = null, _border:Boolean = true)

Parameters
_dms:BrickDms - the BrickDms dimension obj for rendering
_color:SideColor - the SideColor color obj for rendering
_border:Boolean - whether show border

SideX
public function SideX(_dms:SideXDms = null, _color:SideColor = null, _border:Boolean = true)

Parameters
_dms:SideXDms - the SideXDms dimension obj for rendering
_color:SideColor - the SideColor color obj for rendering
_border:Boolean - whether show border

SideY
public function SideY(_dms:SideYDms = null, _color:SideColor = null, _border:Boolean = true)

Parameters
_dms:SideYDms - the SideYDms dimension obj for rendering
_color:SideColor - the SideColor color obj for rendering
_border:Boolean - whether show border

Cube
public function Cube(_dms:CubeDms = null, _color:CubeColor = null, _border:Boolean = true)

Parameters
_dms:CubeDms - the CubeDms dimension obj for rendering
_color:CubeColor - the CubeColor color obj for rendering
_border:Boolean - whether show border and highlight

Pyramid
public function Pyramid(_dms:PyramidDms = null, _color:PyramidColor = null, _border:Boolean = true)

Parameters
_dms:PyramidDms - the PyramidDms dimension obj for rendering
_color:PyramidColor - the PyramidColor color obj for rendering
_border:Boolean - whether show border and highlight

For example:
Here’s the code to create a brick primitive, with both 120 pixel dimension on x-axis and y-axis:

var brickDms:BrickDms = new BrickDms(120,120);
var brick:Brick = new Brick(brickDms);

This time let’s add SideX and SideY to the preceding code:

import com.risonhuang.pixas.objects.primitives.*;
import com.risonhuang.pixas.colors.SideColor;
import com.risonhuang.pixas.dimensions.*;
import com.risonhuang.pixas.math.Coord3D;

//color obj
var sideColor:SideColor = new SideColor(0x87A900,0xCCFF00);

//brick
var brickDms:BrickDms = new BrickDms(120,120);
var brick:Brick = new Brick(brickDms, sideColor);
var po_brick:PixelObject = new PixelObject(brick);

//SideX
var sideXDms:SideXDms = new SideXDms(120, 60);
var sideX:SideX = new SideX(sideXDms, sideColor);
var po_x:PixelObject = new PixelObject();
po_x.primitive = sideX;
po_x.position = new Coord3D(4, 0, 8);
			
//SideY
var sideYDms:SideYDms = new SideYDms(120, 60);
var sideY:SideY = new SideY(sideYDms, sideColor);
var po_y:PixelObject = new PixelObject();
po_y.primitive = sideY;
po_y.position = new Coord3D(0, 4, 8);

//out PixelObject container
var po_out:PixelObject = new PixelObject();
po_out.addChild(po_brick);
po_out.addChild(po_x);
po_out.addChild(po_y);
po_out.x = 240;
po_out.y = 160;

You may see that we create a SideColor obj firstly for these three primitives.
And in the SideX and SideY part, we didn’t pass the sideX and sideY instance into the construtor, instead of, we set the primitive property after the instance was created. These two approaches are both OK. Actually, you can retrieve and modify the “primitive” property any time with the PixelObject instance.

Runs the code and you will receive this:

Now we know about the primitives, in the next part, we will learn the color manipulating.

Advertisements

Trackbacks / Pingbacks

  1. Pixas Introduction | pixelDiff - 16/08/2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s