2008/06/30 | [papervision3d2] 魔方
类别(做生活) | 评论(2) | 阅读(997) | 发表于 01:14

代码如下:
package ex{ 
	import flash.display.Sprite;	
	import flash.events.Event;
	import com.zutils.ComboBox;
	import com.zutils.CompEvent;		
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.scenes.Scene3D; 
	public class Ex6 extends Sprite {
		private var viewport:Viewport3D; 
		private var scene:Scene3D; 
		private var camera:Camera3D; 
		private var renderer:BasicRenderEngine;
		public function Ex6() {
			viewport = new Viewport3D(500,500);	
			addChild(viewport);					
			scene = new Scene3D(); 
			camera = new Camera3D();
			renderer = new BasicRenderEngine();
			var ms:MaterialsList = new MaterialsList();
			ms.addMaterial(new ColorMaterial(0xff0000),"top");
			ms.addMaterial(new ColorMaterial(0x00ff00),"bottom");
			ms.addMaterial(new ColorMaterial(0x0000ff),"left");
			ms.addMaterial(new ColorMaterial(0xffff00),"right");
			ms.addMaterial(new ColorMaterial(0xff00ff),"front");
			ms.addMaterial(new ColorMaterial(0x00ffff),"back");			
			var rubik:Array=["ufl","uf","ufr","ur","ubr","ub","ubl","ul","u","fl","f","fr","r","br","b","bl","l","dfl","df","dfr","dr","dbr","db","dbl","dl","d"]
			for(var i:uint=0;i<rubik.length;i++){
				var cube:Cube = new Cube(ms,100,100,100,1,1,1)
				if (rubik[i].indexOf("u")>=0) cube.y=105;
				if (rubik[i].indexOf("d")>=0) cube.y=-105;
				if (rubik[i].indexOf("r")>=0) cube.x=105;
				if (rubik[i].indexOf("l")>=0) cube.x=-105;
				if (rubik[i].indexOf("f")>=0) cube.z=105;
				if (rubik[i].indexOf("b")>=0) cube.z=-105;
				scene.addChild(cube, rubik[i]); 
			}
			addEventListener(Event.ENTER_FRAME, enterFrameHandle); 
			var cbxa:Array=[["顶正","y-s-a"],["顶逆","y-s-z"],["低正","y-d-a"],["低逆","y-d-z"],
			["左正","x-s-a"],["左逆","x-s-z"],["右正","x-d-a"],["右逆","x-d-z"],
			["前正","z-s-a"],["前逆","z-s-z"],["后正","z-d-a"],["后逆","z-d-z"]];
			var cbx:ComboBox=new ComboBox(cbxa,true);
			addChild(cbx);
			cbx.addEventListener(CompEvent.ComboBoxImplementation,comboBoxImplementation);			
		} 
		private function comboBoxImplementation(e:CompEvent):void{
			var a:Array=(ComboBox(e.item).select).split("-");
			for (var item:String in scene.children) { 
				var citem:Cube =Cube(scene.getChildByName(item));
				citem["scale"]=1;
				var k:int=105
				if (a[1]=="d") k=-105;
				if (citem[a[0]]==k){
					if (a[2]=="z")	citem["scale"]=0.8;
				} 
			} 
		} 		
		private function enterFrameHandle(e:Event):void{
			Camera3D(camera).hover(0, viewport.containerSprite.mouseX/30, viewport.containerSprite.mouseY/30);	
			renderer.renderScene(scene,camera,viewport);
		} 
	}
}
13

评论Comments

日志分类
首页[67]
说故事[8]
看世界[15]
冶情操[9]
贴图片[15]
做生活[20]