Archive

Archive for December, 2008

Dragging objects in Papervision3D

December 26th, 2008

A few months ago, Andy Zupko added some methods to Papervision3D which facilitated the ability to drag objects in 3d space. I collected those methods and placed them in a static class called RayTracer. The class currently has only one method which returns a Number3D object with the coordinates in 3D space based on the position of your mouse on a Plane3D object.

Andy says:

In lay terms – this basically shoots a ray from the camera, through where the mouse is, into 3D space. You can then do whatever you want knowing where that ray is.

This is the code for the test above:

package
{
    import flash.events.Event;
   
    import org.papervision3d.core.math.Number3D;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.objects.primitives.Sphere;
    import org.papervision3d.view.BasicView;

    public class Dragging3D extends BasicView
    {
       
        private var sphere:Sphere;
       
        public function Dragging3D()
        {
            initialize();
            createObjects();
            startRendering();
        }
       
        private function initialize():void
        {
            camera.zoom = 11;
            camera.focus = 100;
            camera.z = -2000;
            camera.y = 200;
        }
       
        private function createObjects():void
        {
            var plane:Plane = new Plane(new ColorMaterial(0x0FFFF00), 1000, 1000, 10, 10);
            plane.rotationX = 90;
            scene.addChild(plane);
           
            var wireMaterial:WireframeMaterial = new WireframeMaterial();
            sphere = new Sphere(wireMaterial, 50, 10, 10);
            sphere.useOwnContainer = true;
            sphere.y = 25;
            scene.addChild(sphere);
        }
       
        override protected function onRenderTick(event:Event = null):void
        {
            super.onRenderTick(event);
           
            var intersect:Number3D = RayTracer.getIntersection(viewport, camera, [0, 1, 0]);

            sphere.x = intersect.x;
            sphere.z = intersect.z;
        }
    }
}

The magic happens in the onRenderTick method. This is where we added the RayTracer static method. The first two arguments are self explanatory. The final argument is an array representing the “normal” on an imaginary plane:

[0, 1, 0] = XY plane = objects dragged on the x and z axises
[1, 0, 0] = YZ plane = objects dragged on the y and z axises
[0, 0, 1] = XZ plane = objects dragged on the x and y axises

This is the RayTracer class:

package
{
    import org.papervision3d.core.math.Number3D;
    import org.papervision3d.core.math.Plane3D;
    import org.papervision3d.core.proto.CameraObject3D;
    import org.papervision3d.view.Viewport3D;

    public class RayTracer
    {
       
        public static function getIntersection(viewport:Viewport3D, camera:CameraObject3D, normal:Array):Number3D
        {
            var plane3D:Plane3D = new Plane3D(new Number3D(normal[0], normal[1], normal[2]), new Number3D(0, 0, 0));
            var cameraPosition:Number3D = new Number3D(camera.x, camera.y, camera.z);
            var ray:Number3D = camera.unproject(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY);
            ray = Number3D.add(ray, cameraPosition);
            var intersect:Number3D = plane3D.getIntersectionLineNumbers(cameraPosition, ray);
            return intersect;
        }
       
    }
}

Should be pretty simple to implement. Hit me back if you have any questions!

Experiment, Lab , ,

Exploring a Papervision3D class – Text3D

December 13th, 2008

Hi:

As some of you may know VectorVision (vector fonts in flash) was added into Papervision3D last week so I decided to check out the new typography package. To my surprise, it was fairly simple to set up. This is a small example.

package
{
    import flash.events.Event;
   
    import org.papervision3d.materials.special.Letter3DMaterial;
    import org.papervision3d.typography.Font3D;
    import org.papervision3d.typography.Text3D;
    import org.papervision3d.typography.fonts.HelveticaRoman;
    import org.papervision3d.view.BasicView;

    public class SampleText3D extends BasicView
    {
       
        private var text3D:Text3D;
        private var textMaterial:Letter3DMaterial;
        private var font3D:Font3D;
               
        public function SampleText3D()
        {
            initialize();
            startRendering();
        }
       
        private function initialize():void
        {
            textMaterial = new Letter3DMaterial(0x00FFFF);
            font3D = new HelveticaRoman();
            text3D = new Text3D("Hello there.", font3D, textMaterial);
            text3D.scale = 2;
            scene.addChild(text3D);
        }
       
        override protected function onRenderTick(event:Event = null):void
        {
            super.onRenderTick(event);
            text3D.yaw(0.5);
            text3D.roll(0.5);
        }
    }
}

Experiment, Lab ,

Exploring a Papervision3D class – MovieAssetParticleMaterial

December 12th, 2008
Comments Off

Hi All!

Not to long ago, I decided to go on a reconnaissance mission and plunged into the Papervison3D classes. I decided to read up on a class a week and just devour it ans learn as much about it as I could. I didn’t get the chance to do that until now. Here’s the first class : MovieAssetParticleMaterial and below is an example of what you can do with it.

The MovieAssetParticleMaterial is the material used for the Particle class which in turn is added to an instance of the Particles class using its “addParticle” method. I know that may have sounded a bit confusing, but here’s the break down. In the code for the example, I created 150 particles in a loop and add each particle to an array for later use:

for(var a:Number = 0; a<Particles3D.PARTICLE_COUNT; a++){
    var particleMaterial:MovieAssetParticleMaterial = new MovieAssetParticleMaterial("orb", true);
    particleMaterial.smooth = true;
   
    var particles3D:Particles = new Particles("particles_"+a);
    var particle:Particle = new Particle(particleMaterial, 2.5);
   
    particles3D.addParticle(particle);
    container3D.addChild(particles3D);
   
    arrParticles.push(particles3D);
}

After you have your particles set up, you would need some sort of 3D shape to map them to. Start off with something as simple as a sphere:

sphere = new Sphere(new WireframeMaterial(0x000000), 200, 15, 10);

Notice that all we did was create an instance of it, we really never added it to the scene. That’s because all we need is the vertice coordinates of the sphere in order to map the particles to them. We alreay have all our particles in an array, now we need to get all the vertices for the sphere in an array. Luckily, that is a very simple task:

var vertices:Array = sphere.geometry.vertices;

Now all we need to do is place a particle on each vertice by means of a loop and a little help from Tweener as so:

var vertices:Array = sphere.geometry.vertices;
activeVertices = vertices.length;
selectedShape = sphere;
for(var a:Number = 0; a<activeVertices; a++){
    Tweener.addTween(arrParticles[a], {x:vertices[a].x,
                           y:vertices[a].y,
                           z:vertices[a].z,
                           time:2,
                           transition:"easeInStrong"});
}

Thats pretty much it! I’m sure there’s loads of really cool stuff that can be done with 3D particles. Below is the full code for the example above. Enjoy!

package
{
    import caurina.transitions.Tweener;
   
    import flash.events.Event;
   
    import org.papervision3d.core.geom.Particles;
    import org.papervision3d.core.geom.renderables.Particle;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.special.MovieAssetParticleMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Cylinder;
    import org.papervision3d.objects.primitives.Sphere;
    import org.papervision3d.view.BasicView;

    public class Particles3D extends BasicView
    {
        private static const PARTICLE_COUNT:uint = 150;
        private var sphere:Sphere;
        private var cylinder:Cylinder;
        private var container3D:DisplayObject3D;
        private var selectedShape:DisplayObject3D;
        private var arrParticles:Array;
        private var activeVertices:Number;
       
        public function Particles3D()
        {
            super();
            createParticles();
            createObjects3D();
            mapParticlesToSphere();
            startRendering();
        }
       
        private function createParticles():void
        {
            container3D = new DisplayObject3D();
            arrParticles = [];
           
            for(var a:Number = 0; a<Particles3D.PARTICLE_COUNT; a++){
                var particleMaterial:MovieAssetParticleMaterial = new MovieAssetParticleMaterial("orb", true);
                particleMaterial.smooth = true;
               
                var particles3D:Particles = new Particles("particles_"+a);
                var particle:Particle = new Particle(particleMaterial, 2.5);
               
                particles3D.addParticle(particle);
                container3D.addChild(particles3D);
               
                arrParticles.push(particles3D);
            }
           
            scene.addChild(container3D);
        }
       
        private function createObjects3D():void
        {
            sphere = new Sphere(new WireframeMaterial(0x000000), 200, 15, 10);
            cylinder = new Cylinder(new WireframeMaterial(0x000000), 60, 840, 10, 10);
        }
       
        private function mapParticlesToSphere():void
        {
            var vertices:Array = sphere.geometry.vertices;
            activeVertices = vertices.length;
            selectedShape = sphere;
            for(var a:Number = 0; a<activeVertices; a++){
                Tweener.addTween(arrParticles[a], {x:vertices[a].x,
                                                   y:vertices[a].y,
                                                   z:vertices[a].z,
                                                   time:2,
                                                   transition:"easeInStrong"});
            }
            Tweener.addTween(arrParticles[a], {time:4, onComplete:mapParticlesToCylinder});
        }
       
        private function mapParticlesToCylinder():void
        {
            var vertices:Array = cylinder.geometry.vertices;
            activeVertices = vertices.length;
            selectedShape = cylinder
            for(var a:Number = 0; a<activeVertices; a++){
                Tweener.addTween(arrParticles[a], {x:vertices[a].x,
                                                   y:vertices[a].y,
                                                   z:vertices[a].z,
                                                   time:2,
                                                   transition:"easeInStrong"});
            }
            Tweener.addTween(arrParticles[a], {time:4, onComplete:mapParticlesToSphere});
        }
       
        private function hideUnusedParticles():void
        {
            for (var a:Number = 0; a < Particles3D.PARTICLE_COUNT; a++) {
                if (a < selectedShape.geometry.vertices.length) {
                    arrParticles[a].visible = true;
                } else {
                    arrParticles[a].visible = false;
                }
            }
        }
       
        override protected function onRenderTick(event:Event=null):void
        {
            super.onRenderTick(event);
            container3D.yaw(.5);
            container3D.roll(.5);
            hideUnusedParticles();
        }      
       
    }
}
;

Experiment, Lab , ,

Applying modifiers to 3D objects in Papervision3D using AS3Mod

December 9th, 2008

I have been meaning to dig into the as3mod library for a while now but never had the time because I was working on a project. Finally I found some time and dove right into it! At first, I had no idea what I was getting into, but as I read deeper into the classes and devoured the documentation, stuff started to make sense. So much that I decided to build a very simple demonstration of the different modifiers available:

The modifiers are really simple to apply to any 3d object including collada files!! Below is the document class used in the example. If you go through it, I’m sure you’ll pick up pretty fast.

You’re gonna nee d to grab the as3mod library found here and the latest version of papervision3d here.

package
{
    import com.as3dmod.IModifier;
    import com.as3dmod.ModifierStack;
    import com.as3dmod.modifiers.Bend;
    import com.as3dmod.modifiers.Bloat;
    import com.as3dmod.modifiers.Noise;
    import com.as3dmod.modifiers.Perlin;
    import com.as3dmod.modifiers.Skew;
    import com.as3dmod.modifiers.Taper;
    import com.as3dmod.modifiers.Twist;
    import com.as3dmod.plugins.pv3d.LibraryPv3d;
    import com.as3dmod.util.ModConstant;
    import com.as3dmod.util.Phase;
   
    import flash.events.Event;
   
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.special.CompositeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.BasicView;

    public class SimpleMod extends BasicView
    {
        private var cube:Cube;
        private var modStack:ModifierStack;
        private var bend:Bend;
        private var bendPhase:Phase;
        private var perlin:Perlin;
        private var noise:Noise;
        private var skew:Skew;
        private var skewPhase:Phase;
        private var taper:Taper;
        private var taperPhase:Phase;
        private var twist:Twist;
        private var twistPhase:Phase;
        private var bloat:Bloat;
        private var bloatPhase:Phase;
       
        public function SimpleMod()
        {
            camera.z = -1500;
           
            cerateCube();
            addModifiers();
            configureComboBox();
            startRendering();
        }
       
        private function cerateCube():void
        {
            var colorMat:ColorMaterial = new ColorMaterial(0x00FF00);
            var wireMat:WireframeMaterial = new WireframeMaterial(0xFFFFFF);
            var compositeMat:CompositeMaterial = new CompositeMaterial();
            compositeMat.addMaterial(colorMat);
            compositeMat.addMaterial(wireMat);
           
            var materialsList:MaterialsList = new MaterialsList({ all:compositeMat });
           
            cube = new Cube(materialsList, 500, 500, 1000, 10, 10, 10);
           
            scene.addChild(cube);
        }
       
        private function addModifiers():void
        {
            modStack = new ModifierStack(new LibraryPv3d, cube);
           
            bend = new Bend(0.5, 0.5);
            bendPhase = new Phase();
           
            skew = new Skew(0);
            skewPhase = new Phase();
           
            taper = new Taper(3);
            taper.setFalloff(0.2, 0.5);
            taper.power = 6;
            taperPhase = new Phase();
           
            twist = new Twist(Math.PI / 2);
            twistPhase = new Phase();
           
            perlin = new Perlin(3);
            perlin.setFalloff(1, 0);
           
            noise = new Noise(25);
            noise.constraintAxes(ModConstant.X | ModConstant.Y);
           
            bloat = new Bloat();
        }
       
        private function configureComboBox():void
        {
            modifierCB.addItem({label:"Bend", data:bend});
            modifierCB.addItem({label:"Skew", data:skew});
            modifierCB.addItem({label:"Taper", data:taper});
            modifierCB.addItem({label:"Twist", data:twist});
            modifierCB.addItem({label:"Perlin", data:perlin});
            modifierCB.addItem({label:"Noise", data:noise});
            modifierCB.addItem({label:"Bloat", data:bloat});
            modifierCB.addEventListener(Event.CHANGE, changeHandler);
        }
       
        private function changeHandler($event:Event):void
        {
            modStack.clear();
            modStack.addModifier(modifierCB.selectedItem.data as IModifier);
        }
       
        override protected function onRenderTick(event:Event=null):void
        {
            super.onRenderTick(event);
           
            cube.yaw(.5);
             
            bendPhase.value += 0.05;
            bend.force = bendPhase.phasedValue * .5;
           
            skewPhase.value += 0.05;
            skew.force = skewPhase.phasedValue * 100;
           
            taperPhase.value += 0.05;
            taper.force = taperPhase.absPhasedValue * 2;
           
            twistPhase.value += 0.05;
            twist.angle = Math.PI / 8 * twistPhase.phasedValue;
           
            modStack.apply();
        }
    }
}

Enjoy!!

as3mod ,

First Person Camera for Papervision3D

December 6th, 2008

Hi all:


[EDIT : CLICK HERE FIND THE LATEST VERSION]

The current dependencies are Papervision3D and Tweener, but I’m sure with a little tweak here an there, it can be used with any 3D or tween engine out there.

FirstPersonCamera3D extends Papervision’s Camera3D class and adds the mouse and key methods in order to implement the first person functionality, here’s a sample:

Use arrow keys to navigate and mouse to look

I tried to comment the class as much as possible. By default, the motion keys are the arrow keys but you can use the mapKeys method to map any keys you wish. Here’s the FirstPersonCamera3D class and right below that is the document class used for the example above. Please feel free to optimize or edit it as much as possible!

package
{
    import caurina.transitions.Tweener;
   
    import flash.display.Stage;
    import flash.events.KeyboardEvent;
    import flash.utils.*;
   
    import org.papervision3d.cameras.Camera3D;
   
    /**
     * Camera3D object with First Person functionality
     * @author Reynaldo Columna
     *
     */

    public class FirstPersonCamera3D extends Camera3D
    {
        protected static const UP_ARROW:int = 38;
        protected static const LEFT_ARROW:int = 37;
        protected static const RIGHT_ARROW:int = 39;
        protected static const DOWN_ARROW:int = 40;
       
        private static var FORWARD_KEY:int;
        private static var LEFT_KEY:int;
        private static var RIGHT_KEY:int;
        private static var BACK_KEY:int;
       
        protected var _sensitivity:Number;
        protected var _maxRotationX:Number;
        protected var _maxRotationY:Number;
        protected var _stageReference:Stage;
        protected var _moveIncrement:Number;
       
        private var forwardTrigger:uint;
        private var leftTrigger:uint;
        private var rightTrigger:uint;
        private var backTrigger:uint;
        private var intervals:Array;
       
        private var movingForward:Boolean;
        private var movingLeft:Boolean;
        private var movingRight:Boolean;
        private var movingBack:Boolean;
       
        public function FirstPersonCamera3D(fov:Number=60, near:Number=10, far:Number=5000, useCulling:Boolean=false, useProjection:Boolean=false)
        {
            super(fov, near, far, useCulling, useProjection);
            intervals = [forwardTrigger, leftTrigger, rightTrigger, backTrigger];
            movingForward = false;
            movingLeft = false;
            movingRight = false;
            movingBack = false;
        }
       
        /**
         * Initializes the Camera functionality
         * @param $stage A reference to the stage in order to add the key listeners
         * @param $moveIncrement A number which represents the move increment
         *
         */
   
        public function initialize($stage:Stage, $moveIncrement:Number = 250):void
        {
            stageReference = $stage;
            moveIncrement = $moveIncrement;
            addListeners();
        }
       
        /**
         * Maps the keys to be used for movement. If no keys are specified, the arrow keys are used as defauilt.
         * @param $keys An object with the following values: forward, back, left and right. Each should be a key code.
         *
         */
   
        public function mapKeys($keys:Object = null):void
        {
            FirstPersonCamera3D.FORWARD_KEY = (($keys != null) ? $keys.forward : FirstPersonCamera3D.UP_ARROW) || FirstPersonCamera3D.UP_ARROW;
            FirstPersonCamera3D.BACK_KEY = (($keys != null) ? $keys.back : FirstPersonCamera3D.DOWN_ARROW) || FirstPersonCamera3D.DOWN_ARROW;
            FirstPersonCamera3D.LEFT_KEY = (($keys != null) ? $keys.left : FirstPersonCamera3D.LEFT_ARROW) || FirstPersonCamera3D.LEFT_ARROW;
            FirstPersonCamera3D.RIGHT_KEY = (($keys != null) ? $keys.right : FirstPersonCamera3D.RIGHT_ARROW) || FirstPersonCamera3D.RIGHT_ARROW;
        }
       
        /**
         * Makes the camera "look" around based on the mouse position
         * @param $sensitivity Number 0 to 1 representing how sensible the camera is to the mouse movement.
         * @param $maxRotationX Number representing the max horizontal rotation (0 to 360)
         * @param $maxRotationY Number representing the max vertical rotation (0 to 360)
         *
         */
   
        public function look($sensitivity:Number = 0.5, $maxRotationX:Number = 90, $maxRotationY:Number = 90):void
        {
            sensitivity = $sensitivity;
            maxRotationX = $maxRotationX;
            maxRotationY = $maxRotationY;
           
            var horizontalDegrees:Number = map(stageReference.mouseX, 0, stageReference.stageWidth, maxRotationX * -1, maxRotationX);
            var verticalDegrees:Number = map(stageReference.mouseY, 0, stageReference.stageHeight, maxRotationY * -1, maxRotationY);
           
            rotationX += (verticalDegrees - rotationX) * sensitivity;
            rotationY += (horizontalDegrees - rotationY) * sensitivity;
        }
       
        /**
         * Clears the camera
         *
         */
   
        public function clear():void
        {
            removeListeners();
            for(var a:Number = 0; a<intervals.length; a++){
                if(intervals[a] != undefined){
                    clearInterval(intervals[a]);
                    intervals[a] = null;
                }
            }
            intervals = null;
            stageReference = null;
        }
       
        private function addListeners():void
        {
            stageReference.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
            stageReference.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
        }
       
        private function removeListeners():void
        {
            stageReference.removeEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
            stageReference.removeEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
        }
       
        private function move($direction:String, $distance:Number):void
        {
            var distanceZ:Number
            var distanceX:Number
           
            switch ($direction) {          
                case "FORWARD" :
                distanceZ = $distance * Math.cos(this.rotationY*(Math.PI/180));
                distanceX = $distance * Math.sin(this.rotationY*(Math.PI/180));
                Tweener.addTween(this, {z:z+distanceZ, x:x+distanceX, time:0.5, transition:"easeInOutStrong"});
                break;
               
                case "REVERSE" :
                distanceZ = $distance * Math.cos(this.rotationY*(Math.PI/180));
                distanceX = $distance * Math.sin(this.rotationY*(Math.PI/180));
                Tweener.addTween(this, {z:z-distanceZ, x:x-distanceX, time:1, transition:"easeInOutStrong"});
                break;
               
                case "STRAFELEFT" :
                distanceZ = $distance * Math.sin(this.rotationY*(Math.PI/180));
                distanceX = $distance * Math.cos(this.rotationY*(Math.PI/180));
                Tweener.addTween(this, {z:z+distanceZ, x:x-distanceX, time:1, transition:"easeInOutStrong"});
                break;
               
                case "STRAFERIGHT" :
                distanceZ = $distance * Math.sin(this.rotationY*(Math.PI/180));
                distanceX = $distance * Math.cos(this.rotationY*(Math.PI/180));
                Tweener.addTween(this, {z:z-distanceZ, x:x+distanceX, time:1, transition:"easeInOutStrong"});
                break;
            }          
        }
       
        private function map(value:Number, min1:Number, max1:Number, min2:Number, max2:Number):Number
        {
            return min2 + (max2 - min2) * (value - min1) / (max1 - min1);
        }
       
        /*
        Properties
        */

       
        /**
         * Sets or returns the look sensitivity
         * @return Number
         *
         */
   
        public function get sensitivity():Number { return _sensitivity }
        public function set sensitivity(value:Number):void { _sensitivity = value; }

        /**
         * Sets or returns the maximum horizontal rotation
         * @return Number
         *
         */
   
        public function get maxRotationX():Number { return _maxRotationX }
        public function set maxRotationX(value:Number):void { _maxRotationX = value; }
       
        /**
         * Sets or returns the maximum vertical rotation
         * @return Number
         *
         */

        public function get maxRotationY():Number { return _maxRotationY }
        public function set maxRotationY(value:Number):void { _maxRotationY = value; }
       
        /**
         * Sets or returns a reference to the stage
         * @return Number
         *
         */
   
        public function get stageReference():Stage { return _stageReference }
        public function set stageReference(value:Stage):void { _stageReference = value; }
       
        /**
         * Sets or returns the movement increment
         * @return Number
         *
         */
   
        public function get moveIncrement():Number { return _moveIncrement }
        public function set moveIncrement(value:Number):void { _moveIncrement = value; }
       
        /*
        Handlers
        */

       
        private function handleKeyDown(evt:KeyboardEvent):void
        {
            switch(evt.keyCode)
            {
                case FirstPersonCamera3D.FORWARD_KEY:
                if(!movingForward){
                    forwardTrigger = setInterval(move, 100, "FORWARD", moveIncrement);
                    movingForward = true;
                }
               
                break;
               
                case FirstPersonCamera3D.BACK_KEY:
                if(!movingBack){
                    backTrigger = setInterval(move, 100, "REVERSE", moveIncrement);
                    movingBack = true;
                }
               
                break;
               
                case FirstPersonCamera3D.LEFT_KEY:
                if(!movingLeft){
                    leftTrigger = setInterval(move, 100, "STRAFELEFT", moveIncrement);
                    movingLeft = true;
                }
               
                break;
               
                case FirstPersonCamera3D.RIGHT_KEY:
                if(!movingRight){
                    rightTrigger = setInterval(move, 100, "STRAFERIGHT", moveIncrement);
                    movingRight = true;
                }
               
                break;
            }
        }
       
        private function handleKeyUp(evt:KeyboardEvent):void
        {
            switch(evt.keyCode)
            {
                case FirstPersonCamera3D.FORWARD_KEY:
                clearInterval(forwardTrigger);
                movingForward = false;
                break;
               
                case FirstPersonCamera3D.BACK_KEY:
                clearInterval(backTrigger);
                movingBack = false;
                break;
               
                case FirstPersonCamera3D.LEFT_KEY:
                clearInterval(leftTrigger);
                movingLeft = false;
                break;
               
                case FirstPersonCamera3D.RIGHT_KEY:
                clearInterval(rightTrigger);
                movingRight = false;
                break;
            }
        }
       
    }
}

And here is the code used for the example above:

package
{
    import flash.events.Event;
   
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.special.CompositeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.view.BasicView;

    public class CameraTest extends BasicView
    {
       
        private var firstPersonCamera:FirstPersonCamera3D;
       
        public function CameraTest(viewportWidth:Number=640, viewportHeight:Number=480, scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="Target")
        {
            super(640, 480, true, false);
            setupCamera();
            createObjects3D();
            startRendering()
        }
       
        private function setupCamera():void
        {
            firstPersonCamera = new FirstPersonCamera3D();
            firstPersonCamera.initialize(stage);
            firstPersonCamera.y = 750;
            firstPersonCamera.mapKeys();
        }
       
        private function createObjects3D():void
        {
            var cubeMat:WireframeMaterial = new WireframeMaterial(0xFF0000);
            var colorMat:ColorMaterial = new ColorMaterial(0x00FF00);
            var compMat:CompositeMaterial = new CompositeMaterial();
            compMat.addMaterial(cubeMat);
            compMat.addMaterial(colorMat);
           
            var materialsList:MaterialsList = new MaterialsList({ all:compMat });
           
            var alternate:String = "right";
            for(var a:Number = 0; a<20; a++){
                var cube:Cube = new Cube(materialsList);
                cube.z = 1000 * a;
                cube.y = 500;
                if(alternate == "right"){
                    cube.x = 1000;
                    alternate = "left";
                }else{
                    cube.x = -1000;
                    alternate = "right";
                }
                scene.addChild(cube);
            }
           
            var floor:Plane = new Plane(new WireframeMaterial(0xFFFFFF), 10000, 10000, 10, 10);
            floor.rotationX = 90;
            scene.addChild(floor);
        }
       
        override protected function onRenderTick(event:Event=null):void
        {
            firstPersonCamera.look(0.5, 180, 90);
            renderer.renderScene(scene, firstPersonCamera, viewport);
        }
       
    }
}

Experiment, Lab , ,