topical media & game development
#graphic-player-10-cube-be-nascom-flash10-tests-CubeCheapShading.ax
#graphic-player-10-cube-be-nascom-flash10-tests-CubeCheapShading.ax
[swf]
[flash]
flex
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 @ax-graphic-player-10-cube-be-nascom-flash10-tests-CubeCheapShading extends AbstractFP10Test{
protected var _cube:SimpleShadeCube;
protected var _mouse_rotator:MouseRotator;
public function @ax-graphic-player-10-cube-be-nascom-flash10-tests-CubeCheapShading(){
super();
FlexSimpleTraceBox.trace("@ax-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("@ax-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+="<ul>";
note+="<li>Still using sprites, adjusting x,y,z and the rotations. </li>";
note+="<li>The 'shading' is achieved by using the same property as the sorting : </li>";
note+="<li>[Sprite].transform.getRelativeMatrix3D(parent).position.z</li>";
note+="<li>Each 'side clip' has a black shape over them, the 'z' position is then 'normalized' to a number between 0 and 1, which inturn is used for the alpha of this black layer.</li>";
note+="<li>The effect is less pronounced in the bitmap version</li>";
note+="<li>The Glow is teh SEX!!!11 ;)</li>";
note+="</ul>";
return note;
}
}
}
(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.