Skip to content

Instantly share code, notes, and snippets.

@itoz
Created February 29, 2012 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itoz/1938392 to your computer and use it in GitHub Desktop.
Save itoz/1938392 to your computer and use it in GitHub Desktop.
Away3D 4.0 beta カメラの注視点を指定 ref: http://qiita.com/items/2892
/**
* 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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment