jiglib 3D Physics Engine #2

メモ

ご覧になるには最新のFlashPlayerが必要です。

package classes
{
	import flash.events.Event;

	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cone;
	import org.papervision3d.objects.primitives.Plane;

	import jiglib.plugin.papervision3d.Papervision3DPhysics;
	import jiglib.plugin.papervision3d.Pv3dMesh;
	import jiglib.geometry.JBox;

	[SWF(width="450",height="300",backgroundColor="#ffffff",frameRate="30")]

	public class Main extends BasicView
	{
		private var rootNode : DisplayObject3D;
		private var physics : Papervision3DPhysics;

		public static const FROOR_SIZE : uint=2000;
		public static const CONE_NUM : uint=5;
		public static const CONE_RADIUS : uint=80;
		public static const CONE_HEIGHT : uint=200;

		public function Main():void
		{
			super(450,300,false);
			init();
		}

		private function init():void
		{
			camera.y = 400;
			camera.z = -1500;

			rootNode = new DisplayObject3D  ;
			scene.addChild(rootNode);

			physics = new Papervision3DPhysics(rootNode,9.8);

			var floor:Plane = new Plane(new WireframeMaterial(0),FROOR_SIZE,FROOR_SIZE);
			rootNode.addChild(floor);
			var floorBox : JBox=new JBox(new Pv3dMesh(floor),FROOR_SIZE,1,FROOR_SIZE);
			floorBox.y = -500;
			floorBox.rotationX = 90;
			floorBox.movable = false;
			physics.addBody(floorBox);

			for (var i : uint = 0; i < cone_NUM; i++)
			{
				var cone : Cone = new Cone(new WireframeMaterial(0xFF0000),CONE_RADIUS,CONE_HEIGHT,6,4);
				scene.addChild(cone);
				var coneBox : JBox = new JBox(new Pv3dMesh(cone),CONE_RADIUS*2,CONE_RADIUS*2,CONE_HEIGHT);
				coneBox.y = 1000;
				coneBox.friction = 0.2;
				coneBox.restitution = 1.2;
				physics.addBody(coneBox);
			}

			startRendering();
		}

		protected override function onRenderTick(e:Event=null):void
		{
			physics.step();
			super.onRenderTick(e);
		}
	}
}

Tags: , ,

Similar Posts

Leave a Reply