Menu
Samaritan's Purse

CAMERA TARGET MOVE

Camera Target Move

CODE

´╗┐package
{
    import flash.events.KeyboardEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.ui.Keyboard;

    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.BasicView;

    public class Papervision3DCameraTargetMove extends BasicView
    {
        private var field :TextField;

        public function Papervision3DCameraTargetMove()
        {
            camera.z = -1;

            var material :ColorMaterial = new ColorMaterial(0xff0000);
            material.opposite = true;

            var material2 :ColorMaterial = new ColorMaterial(0x00ff00);
            material2.opposite = true;

            var material3 :ColorMaterial = new ColorMaterial(0x0000ff);
            material3.opposite = true;

            var material4 :ColorMaterial = new ColorMaterial(0xffff00);
            material4.opposite = true;

            var material5 :ColorMaterial = new ColorMaterial(0xff00ff);
            material5.opposite = true;

            var material6 :ColorMaterial = new ColorMaterial(0x00ffff);
            material6.opposite = true;

            var object :Cube = new Cube(new MaterialsList({
                front: material,
                back: material2,
                right: material3,
                left: material4,
                top:    material5,
                bottom: material6}), 500, 500, 500, 10, 10, 10);
            scene.addChild(object);

            field                 = new TextField();
            field.autoSize         = TextFieldAutoSize.LEFT;
            field.defaultTextFormat = new TextFormat("verdana");
            field.selectable        = false;
            addChild(field);

            stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

            singleRender();
            instructions();
        }

        private function handleKeyDown(e:KeyboardEvent):void
        {
            switch (e.keyCode) {
                case Keyboard.ENTER:
                    camera.target.x = 0;
                    camera.target.y = 0;
                    camera.target.z = 0;
                    break;
                case "Q".charCodeAt():
                    camera.target.moveRight(10);
                    break;
                case "A".charCodeAt():
                    camera.target.moveLeft(10);
                    break;
                case "W".charCodeAt():
                    camera.target.moveUp(10);
                    break;
                case "S".charCodeAt():
                    camera.target.moveDown(10);
                    break;
                case "E".charCodeAt():
                    camera.target.moveForward(10);
                    break;
                case "D".charCodeAt():
                    camera.target.moveBackward(10);
                    break;
            }

            singleRender();
            instructions();
        }

        private function instructions():void
        {
            field.text = "Click\tStart"
                + "\nEnter\tReset"
                + "\nQ\t\tCamera Target Move Right"
                + "\nA\t\tCamera Target Move Left"
                + "\nW\t\tCamera Target Move Up"
                + "\nS\t\tCamera Target Move Down"
                + "\nE\t\tCamera Target Move Forward"
                + "\nD\t\tCamera Target Move Backward"
                + "\n\nCamera Target:"
                + "\nX:\t" + camera.target.x
                + "\nY:\t" + camera.target.y
                + "\nZ:\t" + camera.target.z;
        }
    }
}

Download