PV3D and WOW Physics Engine basics(papervision3d与WOWengine动力学的结合研究之一)

http://www.newflash3d.com---flash3D先锋队:北京贝武易科技公司】
有疑问请联系我QQ:363596350
这是我第一个对WOWengine动力学的学习,在这里总结一下,先看看结果。


papervision3d与WOWengine很好结合到一起了。
看看代码:
package {
 
	import flash.events.Event;
	
	import fr.seraf.wow.core.WOWEngine;
	import fr.seraf.wow.core.data.WVector;
	import fr.seraf.wow.primitive.WBoundArea;
	import fr.seraf.wow.primitive.WSphere;
	
	import org.papervision3d.cameras.*;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
 
	[SWF(width="640", height="480", frameRate="30", backgroundColor="#333333")]
	public class Wow extends BasicView {
 
		private var wow:WOWEngine;
		private var wSphere1:WSphere;
		private var wSphere2:WSphere;
		private var bound:WBoundArea;
		private var ball1:Sphere;
		private var ball2:Sphere;
		private var box:Cube;
 
		public function Wow()	{
			super(0, 0, true, true, CameraType.TARGET);
			init();
		}
 
		private function init():void {
			camera.x = 0;
			camera.y = 0;
			camera.z = -400;
			camera.focus = 400;
			camera.zoom = 1;
 
			createBox();
			createBall();
			initWow();
			startRendering();
		}
 
		private function initWow():void {
			wow = new WOWEngine(.4);
			wow.collisionResponseMode = wow.SELECTIVE;  
			wow.addMasslessForce(new WVector(1,3,1));  
			wow.damping=0.98;
 
			wSphere1 = new WSphere(0,0,0,10, false, 1.2, 0.4);
			wSphere2 = new WSphere(0,10,0,10, false, 1, 0.3);
			wow.addParticle(wSphere1);
			wow.addParticle(wSphere2);
 
			bound = new WBoundArea(200,200,200);
			bound.setPosition(0,0,0);
			bound.elasticity=0.1;  
			bound.friction=0.01;  
			wow.setBoundArea(bound);  
		}
 
		private function createBox():void {
			var materials:MaterialsList = new MaterialsList({
				all: new WireframeMaterial(0xffffff, 1)
			} );
			box = new Cube(materials, 200, 200, 200, 2, 2, 2, Cube.ALL, Cube.NONE);
			scene.addChild(box);
		}
 
		private function createBall():void {
			ball1 = new Sphere(new WireframeMaterial(0xff00ff, 1), 10);
			ball2 = new Sphere(new WireframeMaterial(0xff00ff, 1), 10);
			scene.addChild(ball1);
			scene.addChild(ball2);
		}
 
		override protected function onRenderTick(event:Event=null):void {
			var wVec:WVector = bound.getRotation();
			var rx:Number = wVec.x + 1;
			var ry:Number = wVec.y + 1;
			bound.setRotation(rx,ry,0);
			wow.step();
 
			// Set pos ref to wow
			box.rotationX = wVec.x;
			box.rotationY = wVec.y;
			box.rotationZ = 0;
			ball1.x = wSphere1.px;
			ball1.y = -wSphere1.py;
			ball1.z = wSphere1.pz;
			ball2.x = wSphere2.px;
			ball2.y = -wSphere2.py;
			ball2.z = wSphere2.pz;
 
			super.onRenderTick(event);
 
		}
 
	}
}

代码分析:
从根本意义上来说,WOWengine只是以嵌入的方式加入到Papervision3d中的,它的还是自己的运算规律,自己的东西,而把Papervision3d的物体捆绑到它上面去。

你可能感兴趣的:(qq,Flash)