Menu Home

SpringCamera3D

osbo.com | Flash | Papervision3D | SpringCamera3D

SpringCamera3D is Camera3D with a spring effect.

Example

SpringCamera3D

Instructions

  1. Import
    import org.papervision3d.cameras.SpringCamera3D;
  2. Declare
    private var camera :SpringCamera3D;
  3. Initialize
    camera = new SpringCamera3D(fov, near, far, useCulling, useProjection);
    Parameter Default Description
    fov 60 field of view vertical degree
    near 10 clipping plane near distance
    far 5000 clipping plane far distance
    useCulling false cull objects outside view
    useProjection false projection matrix

Code

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import org.papervision3d.cameras.SpringCamera3D;
    import org.papervision3d.core.math.Number3D;
    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;

    public class Papervision3DSpringCamera3D extends Sprite
    {
        private var scene     :Scene3D;
        private var camera    :SpringCamera3D;
        private var viewport  :Viewport3D;
        private var renderer  :BasicRenderEngine;
        private var material  :ColorMaterial;
        private var material2 :ColorMaterial;
        private var object    :Plane;
        private var object2   :Plane;

        public function Papervision3DSpringCamera3D()
        {
            scene = new Scene3D();

            camera                = new SpringCamera3D();
            camera.target         = DisplayObject3D.ZERO;
            camera.lookOffset     = new Number3D(0, 50, 0);
            camera.positionOffset = new Number3D(0, 0, -500);
            camera.damping        = 4;
            camera.mass           = 40;
            camera.stiffness      = 1;

            viewport                  = new Viewport3D();
            viewport.autoScaleToStage = true;
            viewport.interactive      = true;
            addChild(viewport);

            renderer = new BasicRenderEngine();

            material             = new ColorMaterial(0x000000);
            material.doubleSided = true;
            material.interactive = true;

            material2             = new ColorMaterial(0xff0000);
            material2.doubleSided = true;
            material2.interactive = true;

            object   = new Plane(material);
            object.x = -300;
            scene.addChild(object);

            object.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver);
            object.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut);
            object.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPressObject);

            object2   = new Plane(material2);
            object2.x = 300;
            scene.addChild(object2);

            object2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver);
            object2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut);
            object2.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPressObject2);

            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

        private function handleEnterFrame(e:Event):void
        {
            renderer.renderScene(scene, camera, viewport);
        }

        private function handleObjectOver(e:InteractiveScene3DEvent):void
        {
            viewport.containerSprite.buttonMode = true;
        }

        private function handleObjectOut(e:InteractiveScene3DEvent):void
        {
            viewport.containerSprite.buttonMode = false;
        }

        private function handleObjectPressObject(e:InteractiveScene3DEvent):void
        {
            camera.target = object;
        }

        private function handleObjectPressObject2(e:InteractiveScene3DEvent):void
        {
            camera.target = object2;
        }
    }
}

Download

Papervision3D Official Documentation