4,328
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import .........
public var wDown:Boolean = false;
public var sDown:Boolean = false;
public var aDown:Boolean = false;
public var dDown:Boolean = false;
private var wVel:Number = 0;
private var rVel:Number = 0;
private var limitRotX:Number = 0;
private var container:Sprite;
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:FlabCamera3D;
private var renderer:BasicRenderEngine;
private var rootNode:DisplayObject3D;
private var cube:Cube;
private var mat:MovieMaterial;
private var matback:MovieMaterial;
private var matwallleft:MovieMaterial;
private var matwallright:MovieMaterial;
private var _dae:DAE;
public function init():void
{
container=new Sprite();
rawChildren.addChild(container);
viewport=new Viewport3D(800, 600, true, true);
container.addChild(viewport);
scene=new Scene3D();
camera=new FlabCamera3D();
renderer=new BasicRenderEngine();
camera.zoom=20;
camera.focus = 15;
camera.x = 0;
camera.y =0;
camera.z = 0;
rootNode=scene.addChild(new DisplayObject3D("rootNode"));
mat = new MovieMaterial;
matback= new MovieMaterial(backcavas, true, true, true);
matwallleft = new MovieMaterial(wallleft, true, true, true);
matwallright = new MovieMaterial(wallright, true, true, true);
matback.interactive = true;
matwallleft.interactive = true;
matwallright.interactive =true;
matback.oneSide = false;
matwallleft.oneSide = false;
matwallright.oneSide = false;
var matlist:MaterialsList = new MaterialsList({front:matwallright,back:matwallleft,right:matwallleft,left:matwallleft,top:mat,bottom:matback});
var inside:int = Cube.ALL;
cube=new Cube(matlist, 1000, 900, 600,10,10,10,inside);
cube.x=0;
cube.y=0;
cube.z=0;
rootNode.addChild(cube, "cube");
cube.rotationY=15;
addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
addEventListener(Event.ENTER_FRAME, onFrame);
}
public function onloadCompleteHandler(e:FileLoadEvent):void
{
rootNode.addChild(_dae);
}
public function onFrame(e:Event):void
{
if(wDown)
wVel += 1;
if(sDown)
wVel -= 1;
if(aDown)
rVel -= 1;
if(dDown)
rVel += 1;
wVel *= 0.93;
rVel *= 0.93;
camera.moveForward(wVel);
camera.moveRight(rVel);
/* cube.pitch(1);
cube.yaw(1);
cube.roll(2); */
//0: x:161 y:15 z:155 22.375 -35.25 0
camera.rotationX = viewport.containerSprite.mouseY/8;
camera.rotationY = viewport.containerSprite.mouseX/4;
renderer.renderScene(scene, camera, viewport);
}
public function onscal(e:Event):void
{
camera.focus--;
}
public function onKeyUp(e:KeyboardEvent):void
{
switch(String.fromCharCode(e.keyCode).toUpperCase())
{
case "W": wDown = false; break;
case 'S': sDown = false; break;
case "A": aDown = false; break;
case "D": dDown = false; break;
}
}
public function onKeyDown(e:KeyboardEvent):void
{
trace(e.keyCode);
switch(String.fromCharCode(e.keyCode).toUpperCase())
{
case 'W': wDown = true; break;
case 'S': sDown = true; break;
case 'A': aDown = true; break;
case 'D': dDown = true; break;
}
}
public function onup():void
{
wVel += 1;
}
public function ondown():void
{
wVel -= 1;
}
public function onleft():void
{
rVel -= 1;
}
public function onRound(e:InteractiveScene3DEvent):void
{
}
public function onright():void
{
rVel += 1;
}
public function onreset():void
{
camera.resetToZero();
}
public function sliderchange():void
{
camera.focus = slider.value;
}
public function choice():void
{
matback.texture = backcavas1;
}
]]>
</mx:Script>
<mx:Canvas width="350" height="350" alpha="1" id="backcavas" backgroundColor="#FDFDFD">
<mx:Image source="floor.jpg" width="100%" height="100%">
</mx:Image>
</mx:Canvas>
<mx:Canvas width="350" height="350" alpha="1" id="wallleft" backgroundColor="#FDFDFD">
<mx:Image source="wall1.jpg" width="100%" height="100%">
</mx:Image>
</mx:Canvas>
<mx:Canvas width="350" height="350" alpha="1" id="wallright" backgroundColor="#FDFDFD">
<mx:Image source="wall1.jpg" width="100%" height="100%">
</mx:Image>
</mx:Canvas>
<mx:Canvas width="350" height="350" alpha="1" id="backcavas1" backgroundColor="#FDFDFD">
<mx:Image source="floor1.jpg" width="100%" height="100%">
</mx:Image>
</mx:Canvas>
<mx:Canvas id="keylin" x="0" y="0" width="100%" height="100%" label="" backgroundColor="#FDFDFD" borderStyle="inset">
<mx:Panel x="800" y="33" width="250" height="200" layout="absolute" label="KeyboardEvent">
<mx:Image x="42" y="30" width="23" height="24" source="floor1flag.jpg" click="choice()"/>
</mx:Panel>
<mx:Button id="up" cornerRadius="10" label="向上" x="50" y="15" click="onup()" ></mx:Button>
<mx:Button id="down" cornerRadius="10" label="向下" x="50" y="75" click="ondown()" ></mx:Button>
<mx:Button id="left" cornerRadius="10" label="向左" x="0" y="45" click="onleft()" ></mx:Button>
<mx:Button id="right" cornerRadius="10" label="向右" x="100" y="45" click="onright()" ></mx:Button>
<mx:Button id="reset" cornerRadius="10" label="复位" x="50" y="45" click="onreset()" ></mx:Button>
</mx:Canvas>
<mx:HSlider x="0" y="116" id="slider" allowTrackClick="true" value="30" minimum="10" maximum="50" change="sliderchange()"/>
</mx:Application>