Hi! I’m doing my first 3D experiments. I’m trying to build a spinning cube without Papervision.
I’ve got 6 mc (200x200), (A,B,C,D,E,F), and a container Sprite, registered in the stage center.
2 problems:
-
Perspective seems not to be centered.
-
When spinning, even if I sort z using the SimpleZSorter class by Ralph Hauwert, the faces not behave properly.
Take a look, just experimenting with only 2 faces for now:
http://reghellin.com/debug/cube/
Any idea? What am I doing wrong?
Here’s the code:
stop();
import com.theflashblog.fp10.SimpleZSorter;
import flash.display.DisplayObject;
import flash.geom.Point;
// B
//CAD
// E
// F
var cube = new Sprite();
cube.x = Math.ceil(stage.stageWidth/2)/*-cube.width/2*/;
cube.y = Math.ceil(stage.stageHeight/2)/*-cube.height/2*/;
addChild(cube);
var A = new sideA();
var B = new sideB();
var C = new sideC();
var D = new sideD();
var E = new sideE();
var F = new sideF();
//the faces are 200x200 in size,
//and I want the cube spin around its center
D.x = 100;
D.y = -100;
D.z = -100;
D.rotationY = -90;
C.x = -100;
C.y = -100;
C.z = 100;
C.rotationY = 90;
cube.addChild(D)
cube.addChild(C)
stage.addEventListener(MouseEvent.CLICK, manageSpin);
var spinning = false;
function manageSpin(e){
if(spinning){
removeEventListener(Event.ENTER_FRAME, spin);
spinning = false;
} else {
addEventListener(Event.ENTER_FRAME, spin);
spinning = true;
}
}
function spin(e){
cube.rotationY++;
SimpleZSorter.sortClips(cube);
}