I have been playing with WOW physics engine (ver.2 Alpha) recently, below is the basic example showing 2 balls in a box in PV3D:

See example
Basically what you need to do is to create physics primitives and set PV3D primitives the same position as them, to create physics primitives, code like below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Create WOW engine instance wow = new WOWEngine(.4); wow.collisionResponseMode = wow.SELECTIVE; // Add force wow.addMasslessForce(new WVector(1,3,1)); wow.damping=0.98; // Create 2 sphere with radius 10 wSphere1 = new WSphere(0,0,0,10, false, 1.2, 0.4); wSphere2 = new WSphere(0,10,0,10, false, 1, 0.3); // Add spheres to WOW wow.addParticle(wSphere1); wow.addParticle(wSphere2); // Create box bound area bound = new WBoundArea(200,200,200); bound.setPosition(0,0,0); bound.elasticity=0.1; bound.friction=0.01; // Add box to WOW wow.setBoundArea(bound); |
Once you have setup the physics, create PV3D primitives the same position/size as above:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Create box var materials:MaterialsList = new MaterialsList({ all: new WireframeMaterial(0xffffff, 1) } ); box = new Cube(materials, 200, 200, 200, 2, 2, 2, Cube.ALL, Cube.NONE); // Create balls ball1 = new Sphere(new WireframeMaterial(0xff00ff, 1), 10); ball2 = new Sphere(new WireframeMaterial(0xff00ff, 1), 10); // Add to scene scene.addChild(ball1); scene.addChild(ball2); scene.addChild(box); |
Once everything is setup, you need to set position of PV3D primitives the same as physics ones in “onRenderTick” function. Below is the complete code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | package { 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.events.InteractiveScene3DEvent; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.DisplayObject3D; 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); } } } |
Please note that physics primitive position “y” is the opposite direction of PV3D.
No user commented in " PV3D and WOW Physics Engine basics "
Follow-up comment rss or Leave a TrackbackLeave A Reply