package be.nascom.flash10_tests{ import be.nascom.flash.threeD.MouseRotator; import be.nascom.flash10_tests.controls.CubeShadeMaterialToggle; import be.nascom.flash10_tests.widgets.CubeSimpleShadeBitmapMaterial; import be.nascom.flash10_tests.widgets.CubeSimpleShadeMaterial; import be.nascom.flash10_tests.widgets.SimpleShadeCube; import be.nascom.flex.component.FlexSimpleTraceBox; import flash.display.Bitmap; import flash.events.Event; import flash.events.MouseEvent; import flash.filters.GlowFilter; import flash.geom.Point; public class graphic_player_10_cube_be_nascom_flash10_tests_CubeCheapShading extends AbstractFP10Test{ protected var _cube:SimpleShadeCube; protected var _mouse_rotator:MouseRotator; public function graphic_player_10_cube_be_nascom_flash10_tests_CubeCheapShading(){ super(); FlexSimpleTraceBox.trace("graphic_player_10_cube_be_nascom_flash10_tests_CubeCheapShading()"); } protected var _material_function:Function=getMaterials; protected var _material_selector:CubeShadeMaterialToggle; override protected function createChildren():void{ super.createChildren(); _material_selector=new CubeShadeMaterialToggle(); _material_selector.addEventListener(CubeShadeMaterialToggle.USE_COLOR_MATERIAL,useColorMaterial); _material_selector.addEventListener(CubeShadeMaterialToggle.USE_BITMAP_MATERIAL,useBitmapMaterial); _material_selector.addEventListener(CubeShadeMaterialToggle.GLOW_CHANGE,updateGlow); _material_selector.x=10; _material_selector.y=80; _material_selector.percentWidth=100; addChild(_material_selector); } protected function useColorMaterial(e:Event=null):void{ _material_function=getMaterials; createCube(); } protected function useBitmapMaterial(e:Event=null):void{ _material_function=getBitmapMaterials; createCube(); } protected function updateGlow(e:Event=null):void{ if(_cube==null)return; _cube.filters=_material_selector.glow_cb.selected ? [new GlowFilter(0xFFFFFF,.5,40,40)] : []; } override public function run():void{ FlexSimpleTraceBox.trace("graphic_player_10_cube_be_nascom_flash10_tests_CubeCheapShading.run()"); createCube(); startRotateCube(); root.transform.perspectiveProjection.projectionCenter = test_holder.localToGlobal(new Point(400,400)); } protected function createCube():void{ removeCube(); _cube=new SimpleShadeCube(_material_function()); _cube.x=400; _cube.y=300;//because the holder is at 100 this.test_holder.addChild(_cube); updateGlow(); } protected function getMaterials():Array{ var materials:Array=new Array(6); for(var i:uint=0;i<6;i++){ materials[i]=new CubeSimpleShadeMaterial(200,200,i); } return materials; } protected function getBitmapMaterials():Array{ var materials:Array=new Array(6); var i:uint; var bitmaps:Array=new Array( new TestAssets.Burt200x200(), new TestAssets.OHS200x200(), new TestAssets.Picard200x200(), new TestAssets.HardcoreJorge200x200(), new TestAssets.WhatYouDidThere200x200(), new TestAssets.WillieStroker200x200() ); for(i=0;i<6;i++){ //materials[i]=new CubeSimpleShadeMaterial(200,200,i); materials[i]=new CubeSimpleShadeBitmapMaterial(200,200,Bitmap(bitmaps[i])); } return materials; } protected function rotateCube(e:Event):void{ //trace("CubeTest.rotateCube()"); _cube.rotate(_mouse_rotator.x_rotation_speed,_mouse_rotator.y_rotation_speed,_mouse_rotator.z_rotation_speed); } protected function startRotateCube():void{ trace("CubeTest.startRotateCube()"); _mouse_rotator=new MouseRotator(0,0,800,800,5); stage.addEventListener(MouseEvent.MOUSE_MOVE,_mouse_rotator.update); addEventListener(Event.ENTER_FRAME,rotateCube); } protected function stopRotateCube():void{ stage.removeEventListener(MouseEvent.MOUSE_MOVE,_mouse_rotator.update); removeEventListener(Event.ENTER_FRAME,rotateCube); } protected function removeCube():void{ if(_cube!=null){ _cube.destroy(); if(test_holder.contains(_cube))test_holder.removeChild(this._cube); } } override public function destroy():void{ removeCube(); stopRotateCube(); FlexSimpleTraceBox.trace("CubeTest.destroy()"); } //possibility for developer to document findings, important items to note etc. Use HTML. override public function getNotes():String{ var note:String=""; note+="