pv3d 的 Camera3D练习

 http://www.sandy1219.com/3d/test2/testflabcamera.html

 

 

<textarea cols="79" rows="20" name="code" class="c-sharp">package { import flab3d.FlabCamera3D; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import org.ascollada.utils.FPS; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapFileMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; public class TestFlabCamera extends Sprite { public function TestFlabCamera() { super() init3D(); } private var view:Viewport3D; private var camera:FlabCamera3D; private var renderer:BasicRenderEngine; private var scene:Scene3D; private var light:PointLight3D; private var currentSelectPlane:Plane; private function init3D():void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; var fp:FPS = new FPS(); addChild(fp); view = new Viewport3D(800,800,true,true); addChild(view) renderer = new BasicRenderEngine(); scene = new Scene3D(); camera = new FlabCamera3D(); light = new PointLight3D(true); scene.addChild(light); for(var i:int=0; i&lt;50; i++) { var bitmapMaterial:BitmapFileMaterial = new BitmapFileMaterial("dae/girl.jpg"); bitmapMaterial.interactive = true; bitmapMaterial.doubleSided = true; bitmapMaterial.precise = true; var plane:Plane = new Plane(bitmapMaterial,400,300); plane.x = Math.random() * 5000 - 2500; plane.y = Math.random() * 5000 - 2500; plane.z = Math.random() * 2500; plane.rotationX = Math.random() * 180 -90; plane.rotationY = Math.random() * 180 -90; plane.rotationZ = Math.random() * 180 -90; scene.addChild(plane); plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onPlaneClick); } stage.addEventListener(MouseEvent.MOUSE_WHEEL ,onMouseWheelHandler); addEventListener(Event.ENTER_FRAME,process); } private function onMouseWheelHandler(evt:MouseEvent):void { //camera.focus += e.delta ; var d : Number = evt.delta ; d = camera.distanceTo( currentSelectPlane ) + d &lt;= 0 ? 0.0001 : d; camera.moveBackward(d); } private function onPlaneClick(e:InteractiveScene3DEvent):void { currentSelectPlane = Plane(e.currentTarget); camera.tweenTo( currentSelectPlane ); } private function process(e:Event):void { renderer.renderScene(scene,camera,view); } } }</textarea>

你可能感兴趣的:(function,Class,import,FP)