PV3D and WOW Physics Engine basics (papervision3d 와 WOWengine 동력학 의 결합 연구 중 하나)

3664 단어 qqFlash
[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 의 물 체 를 그 위 에 묶 었 다.

좋은 웹페이지 즐겨찾기