LoginSignup
1
2

More than 5 years have passed since last update.

Away3D 4.0 beta カメラの注視点を指定

Last updated at Posted at 2012-02-29
CameraLookAt.as
/**
 * copyright (c) 2012 www.romatica.com
 * @auther itoz
 */
package
{
    import flash.geom.Vector3D;

    import away3d.debug.AwayStats;
    import away3d.containers.View3D;
    import away3d.entities.Mesh;
    import away3d.materials.ColorMaterial;
    import away3d.primitives.CubeGeometry;

    import flash.events.Event;
    import flash.utils.getTimer;

    [SWF(backgroundColor="#FFFFFF", frameRate="60", width="800", height="600")]
    /**
     * Camera3Dの注視点を指定
     * 動作サンプル
     * @see http://dl.dropbox.com/u/958512/sample/away3d4/cameralookat/index.html
     */
    public class CameraLookAt extends View3D
    {
        private static var ZERO : Vector3D = new Vector3D(0, 0, 0);
        private var _cubes : Array;

        public function CameraLookAt()
        {
            antiAlias = 4;
            backgroundColor = 0xa1c3c0;

            _cubes = [];

            var material : ColorMaterial = new ColorMaterial(0x56a0b6);
            var max : int = 10;
            for (var i : int = 0; i < max; i++) {
                var cubeGeo : CubeGeometry = new CubeGeometry(256, 256, 256, 4, 4, 4);
                var cube : Mesh = new Mesh(cubeGeo, material);
                var xx : int = Math.cos(360 / max * i * ( Math.PI / 180)) * 1000;
                var yy : int = Math.sin(360 / max * i * (Math.PI / 180)) * 1000;
                cube.position = new Vector3D(xx, yy, 0);
                _cubes.push(cube);
                scene.addChild(cube);
            }
            addEventListener(Event.ENTER_FRAME, update);

            addChild(new AwayStats());
        }

        private function update(event : Event) : void
        {
            // カメラを移動し、注視点を原点に
            var t : Number = getTimer();
            _camera.x = int(Math.cos(t / 1000) * 1000);
            _camera.y = int(Math.sin(t / 1000) * 1000);
            _camera.lookAt(ZERO);

            render();
        }
    }
}
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2