import flash.display.Sprite; import flash.events.Event; import flash.geom.Matrix3D; import flash.Vector; class DrawCubes extends Draw3D { private var mc:Sprite; private var rx:Float; private var ry:Float; static function main() { //boilerplate var app:DrawCubes = new DrawCubes(); flash.Lib.current.addChild(app); app.init(); } function new() { super(); } override private function init() { super.init(); rx = 0; ry = 0; } override private function update() { ry++; rx++; //reset state vertices = new Vector(); commands = new Vector(); loadIdentityMatrix(); //apply global rotations rotate(0, ry, 0); rotate(rx, 0, 0); //shift over half a square-width modelViewMatrix.prependTranslation(-50,-50,50); //goto origin of modelview matrix move(0,0,0); //middle 3 pushMatrix(); drawCube(); popMatrix(); pushMatrix(); move(150,0,0); drawCube(); popMatrix(); pushMatrix(); move(-150,0,0); drawCube(); popMatrix(); } override private function render(event) { super.render(event); } private function drawCube() { //draw cube //back drawSquare(); //left pushMatrix(); rotate(0,90,0); drawSquare(); popMatrix(); //top pushMatrix(); rotate(-90,0,0); drawSquare(); popMatrix(); //right pushMatrix(); move(100,0,0); rotate(0,90,0); drawSquare(); popMatrix(); //bottom pushMatrix(); move(0,100,0); rotate(-90,0,0); drawSquare(); popMatrix(); //front (not really necessary) pushMatrix(); move(0,0,-100); drawSquare(); popMatrix(); } private function drawSquare() { draw(100,0,0); rotate(0,0,90); draw(100,0,0); rotate(0,0,90); draw(100,0,0); rotate(0,0,90); draw(100,0,0); rotate(0,0,90);//return to starting orientation } }