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

[b]【[url]http://www.newflash3d.com[/url]---flash3D先锋队:北京贝武易科技公司】[/b]
有疑问请联系我QQ:363596350
这是我第一个对WOWengine动力学的学习,在这里总结一下,先看看结果。
[flash=400,400]/upload/attachment/129366/701da8a9-32ed-3bc6-a11e-b8e4d04c8d6d.jpg[/flash]

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的物体捆绑到它上面去。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值