package {
import flash.events.MouseEvent;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
[SWF(backgroundColor = "#FFFFFF", width="400", height="300")]
public class Main extends BasicView {
public function Main() {
var materialsList:MaterialsList = new MaterialsList( {
front : new ColorMaterial(Math.random() * 0xffffff),
back : new ColorMaterial(Math.random() * 0xffffff),
left : new ColorMaterial(Math.random() * 0xffffff),
right : new ColorMaterial(Math.random() * 0xffffff),
top : new ColorMaterial(Math.random() * 0xffffff),
bottom : new ColorMaterial(Math.random() * 0xffffff)
});
//キューブ生成
var cube:Cube = new Cube(materialsList);
scene.addChild(cube);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
//レンダリングスタート
startRendering();
}
private function onMouseMove(e:MouseEvent):void {
var pitch:Number = -mouseY * 0.5;
if (pitch >= 0)
pitch = -0.1;
camera.orbit(pitch, mouseX * 0.8);
}
public function onMouseWheel(e:MouseEvent):void {
camera.zoom += e.delta;
}
}
}