import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.core.*; import sandy.skin.*; import sandy.util.Ease; import sandy.core.transform.*; import sandy.events.InterpolationEvent; import sandy.util.*; import sandy.view.Camera3D; import sandy.events.ObjectEvent; import flash.display.BitmapData; var tg:TransformGroup = new TransformGroup(); var rotation:Transform3D = new Transform3D(); var x:Number = 0; var y:Number = 0; var z:Number = 0; var mouseX; var mouseY; //图片 var img_usb:BitmapData; var img_tv:BitmapData; var img_nav:BitmapData; var img_dvd:BitmapData; var img_sett:BitmapData; var img_bg:BitmapData; //3d引擎world3d var world:World3D = World3D.getInstance(); //摄像头 var cam:Camera3D; var g:Group; var _mc:MovieClip; function setUpControls(){ //fscommand("fullscreen",true); // Mouse controls Mouse.addListener(this); onMouseDown = function() { mousedown = true; mouseX = _xmouse; mouseY = _ymouse; }; onMouseUp = function() { mousedown = false; mouseX = _xmouse; mouseY = _ymouse; }; } //var roll:Number = 0; function camMove():Void { if ( mousedown ) { //x += ( _ymouse - mouseY )/10; y += ( mouseX -_xmouse )/10; rotation.rot(x, y, z); tg.setTransform(rotation); //roll += 10; //cam.roll(roll%360);//cam.roll(cam.getRoll() + 10); //cam.lookAt(0,0,0); } if(Key.isDown(Key.UP)) cam.moveUpwards(10); if(Key.isDown(Key.DOWN)) cam.moveUpwards(-10); if(Key.isDown(Key.LEFT)) cam.rotateY(3); if(Key.isDown(Key.RIGHT)) cam.rotateY(-3); //if(Key.isDown(Key.LEFT)) cam.moveSideways(10); //if(Key.isDown(Key.RIGHT)) cam.moveSideways(-10); if(Key.isDown(Key.HOME)) cam.moveForward(10); if(Key.isDown(Key.END)) cam.moveForward(-10); if(Key.isDown(Key.ENTER)) { //trace(22); } cam.lookAt(0, 0, 0); } function init():Void { cam = new Camera3D( 800, 480 ); g = new Group(); cam.setPosition( 0,0, -800 ); //_mc = this.createEmptyMovieClip("_mc", this.getNextHighestDepth()); //world.setContainer(_mc); //cam.lookAt(0,0,0); world.setCamera( cam ); //监听 world.addEventListener(World3d.onRenderEvent, this, camMove); setUpControls(); createScene(g); world.setRootGroup( g ); world.render(); } function createCoord(bg:Group):Void { var xAxis:Object3D = new Line3D( new Vector(-150,0,0), new Vector(150,0,0) ); var yAxis:Object3D = new Line3D( new Vector(0,-150,0), new Vector(0,150,0) ); var zAxis:Object3D = new Line3D( new Vector(0,0,-150), new Vector(0,0,150) ); xAxis.setSkin( new SimpleLineSkin( 1, 0xff0000, 100 ) ); // red yAxis.setSkin( new SimpleLineSkin( 1, 0x00ff00, 100 ) ); // green zAxis.setSkin( new SimpleLineSkin( 1, 0x0000ff, 100 ) ); // blue var coords:Group = new Group(); coords.addChild(xAxis); coords.addChild(yAxis); coords.addChild(zAxis); bg.addChild( coords); } function createScene( bg:Group ):Void { //createCoord(bg); // 材质 var ts:MovieSkin; // 平面 var cyl:CylSurface; var plane_usb:Object3D; var plane_tv:Object3D; var plane_dvd:Object3D; var plane_nav:Object3D; var plane_set:Object3D; var tsfor:Transform3D; var angle:Number = 72; var transp:Number = 80; var wh:Number = 400; var ht:Number = 300; ts = new MovieSkin("image_usb", false,true); plane_usb = new Plane3D(ht,wh,10,'quad'); plane_usb.setSkin(ts); plane_usb.setTransparency(transp); plane_usb.enableBackFaceCulling(false); plane_usb.setBackSkin(ts); tsfor = new Transform3D(); tsfor.rot(90,180,0); plane_usb.setTransform(tsfor); var tsu = new Transform3D(); var tgu = new TransformGroup(); tsu.translate(0,0,300); tgu.setTransform(tsu); tgu.addChild(plane_usb); var tsual = new Transform3D(); var tgual= new TransformGroup(); tsual.rot(0,angle,0); tgual.setTransform(tsual); tgual.addChild(tgu); ts = new MovieSkin("image_tv", false,true); plane_tv = new Plane3D(ht,wh,8,'quad'); plane_tv.setSkin(ts); plane_tv.setTransparency(transp); plane_tv.enableBackFaceCulling(false); plane_tv.setBackSkin(ts); tsfor = new Transform3D(); tsfor.rot(90,180,0); plane_tv.setTransform(tsfor); var tst = new Transform3D(); var tgt = new TransformGroup(); tst.translate(0,0,300); tgt.setTransform(tst); tgt.addChild(plane_tv); var tstal = new Transform3D(); var tgtal= new TransformGroup(); tstal.rot(0,angle*2,0); tgtal.setTransform(tstal); tgtal.addChild(tgt); ts = new MovieSkin("image_dvd", false,true); plane_dvd = new Plane3D(ht,wh,8,'quad'); plane_dvd.setSkin(ts); plane_dvd.setTransparency(transp); plane_dvd.enableBackFaceCulling(false); plane_dvd.setBackSkin(ts); tsfor = new Transform3D(); tsfor.rot(90,180,0); plane_dvd.setTransform(tsfor); var tsd = new Transform3D(); var tgd = new TransformGroup(); tsd.translate(0,0,300); tgd.setTransform(tsd); tgd.addChild(plane_dvd); var tsdal = new Transform3D(); var tgdal= new TransformGroup(); tsdal.rot(0,angle*3,0); tgdal.setTransform(tsdal); tgdal.addChild(tgd); ts = new MovieSkin("image_nav", false,true); plane_nav = new Plane3D(ht,wh,8,'quad'); plane_nav.setSkin(ts); plane_nav.setTransparency(transp); plane_nav.enableBackFaceCulling(false); plane_nav.setBackSkin(ts); tsfor = new Transform3D(); tsfor.rot(90,180,0); plane_nav.setTransform(tsfor); var tsn = new Transform3D(); var tgn = new TransformGroup(); tsn.translate(0,0,300); tgn.setTransform(tsn); tgn.addChild(plane_nav); var tsnal = new Transform3D(); var tgnal= new TransformGroup(); tsnal.rot(0,angle*4,0); tgnal.setTransform(tsnal); tgnal.addChild(tgn); ts = new MovieSkin("image_set", false,true); plane_set = new Plane3D(ht,wh,8,'quad'); plane_set.setSkin(ts); plane_set.setTransparency(transp); plane_set.enableBackFaceCulling(false); plane_set.setBackSkin(ts); tsfor = new Transform3D(); tsfor.rot(90,180,0); plane_set.setTransform(tsfor); var tss = new Transform3D(); var tgs = new TransformGroup(); tss.translate(0,0,300); tgs.setTransform(tss); tgs.addChild(plane_set); var tssal = new Transform3D(); var tgsal= new TransformGroup(); tssal.rot(0,angle*5,0); tgsal.setTransform(tssal); tgsal.addChild(tgs); plane_usb.enableEvents(true); plane_usb.addEventListener(ObjectEvent.onPressEVENT, this, onPressEventUsb); plane_usb.addEventListener(ObjectEvent.onReleaseEVENT, this, ReleaseEventUsb); plane_dvd.enableEvents(true); plane_dvd.addEventListener(ObjectEvent.onPressEVENT, this, onPressEventDvd); plane_dvd.addEventListener(ObjectEvent.onReleaseEVENT, this, ReleaseEventDvd); plane_tv.enableEvents(true); plane_tv.addEventListener(ObjectEvent.onPressEVENT, this, onPressEventTv); plane_tv.addEventListener(ObjectEvent.onReleaseEVENT, this, ReleaseEventTv); plane_nav.enableEvents(true); plane_nav.addEventListener(ObjectEvent.onPressEVENT, this, onPressEventNav); plane_nav.addEventListener(ObjectEvent.onReleaseEVENT, this, ReleaseEventNav); plane_set.enableEvents(true); plane_set.addEventListener(ObjectEvent.onPressEVENT, this, onPressEventSet); plane_set.addEventListener(ObjectEvent.onReleaseEVENT, this, ReleaseEventSet); tg.addChild(tgual); tg.addChild(tgdal); tg.addChild(tgtal); tg.addChild(tgnal); tg.addChild(tgsal); //tg.addChild(cyl); bg.addChild(tg); } var DownTimer:Number = 0; var UpTimer:Number = 0; var offsetTime:Number = 200; function onPressEventUsb(o:ObjectEvent):Void { DownTimer = getTimer(); } function ReleaseEventUsb(o:ObjectEvent):Void { UpTimer = getTimer(); if(UpTimer - DownTimer < offsetTime) fscommand("exec","t.exe"); } function onPressEventDvd(o:ObjectEvent):Void { DownTimer = getTimer(); } function ReleaseEventDvd(o:ObjectEvent):Void { UpTimer = getTimer(); if(UpTimer - DownTimer < offsetTime) fscommand("exec","t.exe"); } function onPressEventTv(o:ObjectEvent):Void { DownTimer = getTimer(); } function ReleaseEventTv(o:ObjectEvent):Void { UpTimer = getTimer(); if(UpTimer - DownTimer < offsetTime) fscommand("exec","t.exe"); } function onPressEventNav(o:ObjectEvent):Void { DownTimer = getTimer(); } function ReleaseEventNav(o:ObjectEvent):Void { UpTimer = getTimer(); if(UpTimer - DownTimer < offsetTime) fscommand("exec","t.exe"); } function onPressEventSet(o:ObjectEvent):Void { DownTimer = getTimer(); } function ReleaseEventSet(o:ObjectEvent):Void { UpTimer = getTimer(); if(UpTimer - DownTimer < offsetTime) fscommand("exec","t.exe"); } init();