In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: forked from: forked from: forked from: wonderfl KeyVisual V.4.ja

Get Adobe Flash player
by slave_t4423 04 Feb 2009
    Embed
package {
	import flash.events.Event;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.materials.shadematerials.PhongMaterial;

	import org.papervision3d.cameras.*;
	import org.papervision3d.view.*;
	import org.papervision3d.render.*;
	import org.papervision3d.scenes.*;
	import org.papervision3d.core.proto.*;
	import org.papervision3d.core.view.*;
	import org.papervision3d.lights.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.materials.shadematerials.*;
	import org.papervision3d.materials.shaders.*;
	import org.papervision3d.materials.utils.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.primitives.*;
	
	public class Main extends BasicView {
		private var _light:PointLight3D;
		private var _materialBalls:PhongMaterial;
		private var _materialEyes:PhongMaterial;
		private var _eyesContainer:DisplayObject3D;
		private var _eyeL:Sphere;
		private var _eyeR:Sphere;
		private var _ballL:Sphere;
		private var _ballR:Sphere;
		private var _target:DisplayObject3D;
		private static const EYE_SIZE:Number = 100;
		private static const EYE_POS_X:Number = 100;
		private static const BALL_SIZE:Number = 15;
		private static const BALL_POS_X:Number = 100;
		private static const BALL_MOVE_LEN:Number = 110;
			
		public function Main() {
			super(320, 240);
			camera.z = -300;

			//ライトを作成
			_light = new PointLight3D();
			_light.x = -200;
			_light.y = 300;
			_light.z = -500;

			//白目を作成
			_eyesContainer = new DisplayObject3D();
			scene.addChild( _eyesContainer );
			_materialEyes = new PhongMaterial( _light, 0xFFFFFF, 0x808080, 1 );
			_eyeL = new Sphere(_materialEyes, EYE_SIZE, 20, 20);
			_eyeL.x = -EYE_POS_X
			_eyesContainer.addChild( _eyeL );
			_eyeR = new Sphere( _materialEyes,EYE_SIZE, 20, 20 );
			_eyeR.x = EYE_POS_X;
			_eyesContainer.addChild( _eyeR );

			//黒目を作成
			_materialBalls = new PhongMaterial( _light, 0xFFFFFF, 0x000000, 1 );
			_ballL = new Sphere( _materialBalls, BALL_SIZE, 20, 20 );
			_ballL.x = -BALL_POS_X;
			scene.addChild( _ballL );
			_ballR = new Sphere( _materialBalls, BALL_SIZE, 20, 20 );
			_ballR.x = BALL_POS_X;
			scene.addChild( _ballR );

			//白目が向く方向のターゲットを作成
			_target = new DisplayObject3D();

			//毎フレームの処理用ハンドラを登録
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);

			//レンダリング開始
			startRendering();
		}
		
		private function enterFrameHandler(event:Event):void {
			var ratioX:Number = this.mouseX / stage.stageWidth * 2.0 - 1.0;
			var ratioY:Number = this.mouseY / stage.stageHeight * 2.0 - 1.0;
			var ratioXZ:Number = Math.sin( Math.acos( ratioX ) );
			var ratioYZ:Number = Math.sin( Math.acos( ratioY ) );

			//黒目の位置決め
			var centerX:Number = BALL_POS_X * Math.cos( _eyesContainer.rotationY * Math.PI / 180 );
			var centerY:Number = 0;
			var centerZ:Number = BALL_POS_X * Math.sin( _eyesContainer.rotationY * Math.PI / 180 );
			var offsetX:Number = ratioX * BALL_MOVE_LEN;
			var offsetY:Number = -( ratioY * BALL_MOVE_LEN * ratioXZ );
			var offsetZ:Number = -( ratioXZ * ratioYZ * BALL_MOVE_LEN );
			_ballL.x = -centerX + offsetX;
			_ballL.y = centerY + offsetY;
			_ballL.z = -centerZ + offsetZ;
			_ballR.x = centerX + offsetX;
			_ballR.y = centerY + offsetY;
			_ballR.z = centerZ + offsetZ;

			//マウス位置方向に白目を向ける
			_target.x = ratioX * 320;
			_target.y = 0;
			_target.z = -300;
			_eyesContainer.lookAt( _target );
		}
	}
}