Home Labs Galleries PetitOn

Using Sandy 3D Flash Library

What can happen to an ATransformable

The aim of this paper is to describe how the transformable object is effected by setting its properties and calling its transform methods. You are adviced to regard this as preliminary :)

The TransformGroup, the Shape3D and the Camera3D extend ATransformable with the ability to be transformed, which in this case means scaled, translated and rotated around various axes. They are all part of the node graph tree of the Sandy world.

It is important to note, that any transform performed on a node in the tree, is applied to the sub nodes, or children of that node. Private instance variables keeps information about the transformation state of the object in relation to its parent node. 

Private variables

These can not be changed directly, but are for internal use only.

private var m_oMatrix:Matrix4;	// ???

protected var _vSide:Vector; 	// Side Orientation Vector ( local x ) in the parent frame
protected var _vOut:Vector;  	// view Orientation Vector ( local z ) in the parent frame
protected var _vUp:Vector;   	// up Orientation Vector   ( local y ) in the parent frame

private var _nTilt:Number;	// current tilt value
private var _nYaw:Number;	// current yaw value
private var _nRoll:Number;	// current roll value

private var _vRotation:Vector;	// Rotation angle around the three parent axes
private var _vLookatDown:Vector;// Private absolute down vector
protected var _p:Vector;	// Position within the parent coordinate system
protected var _oScale:Vector;	// Scale factors in the local coordinate directions
protected var m_tmpMt:Matrix4; 	// temporary transform matrix used at updateTransform

Public properties

Properties may be read or changed directly.

The position of the object in the frame of its parent
x : Number		// x position.
y : Number		// y position.
z : Number		// z position.
The object direction vectors in the reference system of its parent
side : Vector		// Side direction ( local x ) in parent coordinates. [read-only]
up   : Vector		// Up direction ( local y ) in parent coordinates. [read-only]
out  : Vector		// Forward direction ( local z ) in parent coordinates.
The rotation values around the local axes of the object
tilt : Number		// The tilt of this object around the local x axis.
pan  : Number		// The pan of this object around the local y axis.
roll : Number		// The roll of this object around the local z axis.
The rotations are not related to the global system but to that of the objects parent node
rotateX : Number	// The rotation of this object around an axis parallel to the parent x axis.
rotateY : Number	// The rotation of this object around an axis parallel to the parent y axis.
rotateZ : Number	// The rotation of this object around an axis parallel to the parent z axis.
The scaling is done in the coordinate system of the object itself
scaleX : Number		// x scale of this object.
scaleY : Number		// y scale of this object.
scaleZ : Number		// z scale of this object.

matrix : Matrix4	// The transform matrix of this object.
target : Vector		// The position for this object to "look at" in the parent frame. [write-only]
visible : Boolean	// Visibility of this node ( associated object ).

Public methods

initFrame():void 					//Initiates the local coordinate system for this object.
setPosition(p_nX:Number, p_nY:Number, p_nZ:Number):void	//Sets the position of this object in the parent system.
getPosition(p_sMode:String = "local"):Vector 		//Returns the position of this group or 
							//object in the global, parent or camera system..

Translations

translate(p_nX:Number, p_nY:Number, p_nZ:Number):void
//Translates this object from it's current position in its parent frame with the specified offset.
moveSideways(p_nD:Number):void		//Translates this object along its side vector ( local x ).
moveUpwards(p_nD:Number):void		//Translates this object along its up vector ( local y ).
moveForward(p_nD:Number):void		//Translates this object along its forward vector ( local z ).

moveHorizontally(p_nD:Number):void	//Translates this object horizontally in its forward direction 
					//( affects x and z in the parent frame ).
moveVertically(p_nD:Number):void	//Translates this object vertically ( affects y in the parent frame ).
moveLateraly(p_nD:Number):void		//Translates this object laterally (  affects x in the parent frame ).

Rotations

rotateAxis(p_nX:Number, p_nY:Number, p_nZ:Number, p_nAngle:Number):void
// Rotate this object around the specified axis in the parent frame by the specified angle.
rotAxisWithReference(p_oAxis:Vector, p_oRef:Vector, p_nAngle:Number):void
//Rotates this object around a specified axis trough a global reference point. Doesn't work!
lookAt(p_nX:Number, p_nY:Number, p_nZ:Number):void
//Make this object "look at" the specified position ( target ) in its parent frame.
update(p_oModelMatrix:Matrix4, p_bChanged:Boolean):void	//Updates this node or object.
updateTransform():void	//Updates the transform matrix of the current object/node before it is rendered

Findings

You can rotate the camera in a circle around an object by adding it to a transform group.
You give the camera an offset, i.e, camera.z = -200.
You then rotate the transform group and you call the camera lookAt method.

private function enterFrameHandler( event : Event ) : void
{
	if(running){
		tg.rotateY += 1; 	// circular rotation around the origin at 
		tg.y -= 0.1;		// Spiraling down.
		camera.lookAt(0,0,0);	// Look at the center of the parent frame.
	}
	world.render();
}

How to make a satellite system.

Add the sun to the root.
Add the earth to tg_earth and offset the tg_earth
Add the moon to tg_moon and offset the tg_moon.
Add tg_moon to tg_earth
Add tg_earth to root.

On frame
    rotate earth about itself
    rotate moon about itself
    rotate tg_moon around y - axis of tg_earth
    rotate tg_earth around y-axis of root.


 

To be continued ...