topical media & game development
#graphic-player-10-cube-be-nascom-flash10-tests-widgets-SimpleCube.ax
#graphic-player-10-cube-be-nascom-flash10-tests-widgets-SimpleCube.ax
[swf]
[flash]
flex
package be.nascom.flash10_tests.widgets{
import flash.display.Sprite;
An extremely simple implementation of a rotating 3d cube menu
uses only rudimentary 3d features (rotateX, rotateY)
public class @ax-graphic-player-10-cube-be-nascom-flash10-tests-widgets-SimpleCube extends Sprite{
//public static const rotation_targets:Array=new Array();
protected static var _rotation_offsets:Array;
protected var _sides:Array;
protected var _sort_pairs:Array;
public function @ax-graphic-player-10-cube-be-nascom-flash10-tests-widgets-SimpleCube(materials:Array){
super();
init(materials);
}
public function validateMaterials(materials:Array):void{
//throw error
}
protected function getRotationOffsets(size:uint):Array{
var h:int=size/2;
//ORDER front, back, left, right, top, bottom
//values x,y,z,rotationX,rotationY,rotationZ
return new Array(
new Offset3d( 0, 0, h, 0, 0, 0),
new Offset3d( 0, 0, -h, 0, 180, 0),
new Offset3d( -h, 0, 0, 0, 90, 0),
new Offset3d( h, 0, 0, 0, 270, 0),
new Offset3d( 0, -h, 0, 270, 0, 0),
new Offset3d( 0, h, 0, 90, 0, 0)
);
}
public function init(materials:Array):void{
validateMaterials(materials);
var size:uint=materials[0].width;//height should be the same
_rotation_offsets=getRotationOffsets(size);
//trace("size:"+size);
_sides=new Array(6);
_sort_pairs=new Array(6);
var side:@fileSide;
for(var i:uint=0;i<6;i++){
side=new @fileSide(size,materials[i],_rotation_offsets[i]);
addChild(side);
_sides[i]=side;
_sort_pairs[i]=new @fileSortPair(side,0);
}
}
public function rotate( x_rotation:Number,
y_rotation:Number,
z_rotation:Number):void{
this.rotationX+=x_rotation;
this.rotationY+=y_rotation;
this.rotationZ+=z_rotation;
zSort();
}
protected function zSort():void{
var pair:@fileSortPair;
for each(pair in _sort_pairs){
//if(pair.side==null)return;
pair.z=pair.side.material.transform.getRelativeMatrix3D(parent).position.z;
removeChild(pair.side);
}
_sort_pairs.sortOn("z", Array.NUMERIC | Array.DESCENDING);
var i:uint=0;
for(i=0;i<6;i++){
addChild(@fileSortPair(_sort_pairs[i]).side);
}
}
public function destroy():void{
//remove all sides
for(var i:uint=0;i<6;i++){
removeChild(_sides[i]);
_sides[i]=null;
}
_sort_pairs=null;
_sides=null;
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.