summaryrefslogtreecommitdiffstats
path: root/o3d/samples/box2d-3d/demos/compound.js
diff options
context:
space:
mode:
Diffstat (limited to 'o3d/samples/box2d-3d/demos/compound.js')
-rw-r--r--o3d/samples/box2d-3d/demos/compound.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/o3d/samples/box2d-3d/demos/compound.js b/o3d/samples/box2d-3d/demos/compound.js
new file mode 100644
index 0000000..e63b983
--- /dev/null
+++ b/o3d/samples/box2d-3d/demos/compound.js
@@ -0,0 +1,71 @@
+// This file comes from Box2D-JS, Copyright (c) 2008 ANDO Yasushi.
+// The original version is available at http://box2d-js.sourceforge.net/ under the
+// zlib/libpng license (see License.txt).
+// This version has been modified to make it work with O3D.
+
+demos.compound = {};
+demos.compound.createCompoundBall = function(world, x, y) {
+ var ballSd1 = new b2CircleDef();
+ ballSd1.density = 1.0;
+ ballSd1.radius = 20;
+ ballSd1.restitution = 0.2;
+ ballSd1.localPosition.Set(-20, 0);
+ var ballSd2 = new b2CircleDef();
+ ballSd2.density = 1.0;
+ ballSd2.radius = 20;
+ ballSd2.restitution = 0.2;
+ ballSd2.localPosition.Set(20, 0);
+ var ballBd = new b2BodyDef();
+ ballBd.AddShape(ballSd1);
+ ballBd.AddShape(ballSd2);
+ ballBd.position.Set(x, y);
+ // NOTE: Added the following line to create a 3d object to display.
+ ballBd.userData = g.mgr.createCompoundCylinder(20, -20, 20, 20);
+ return world.CreateBody(ballBd);
+}
+
+demos.compound.createCompoundPoly = function(world, x, y) {
+ var points = [[-30, 0], [30, 0], [0, 15]];
+ var polySd1 = new b2PolyDef();
+ polySd1.vertexCount = points.length;
+ for (var i = 0; i < points.length; i++) {
+ polySd1.vertices[i].Set(points[i][0], points[i][1]);
+ }
+ polySd1.localRotation = 0.3524 * Math.PI;
+ var R1 = new b2Mat22(polySd1.localRotation);
+ polySd1.localPosition = b2Math.b2MulMV(R1, new b2Vec2(30, 0));
+ polySd1.density = 1.0;
+ var polySd2 = new b2PolyDef();
+ polySd2.vertexCount = points.length;
+ for (var i = 0; i < points.length; i++) {
+ polySd2.vertices[i].Set(points[i][0], points[i][1]);
+ }
+ polySd2.localRotation = -0.3524 * Math.PI;
+ var R2 = new b2Mat22(polySd2.localRotation);
+ polySd2.localPosition = b2Math.b2MulMV(R2, new b2Vec2(-30, 0));
+ var polyBd = new b2BodyDef();
+ polyBd.AddShape(polySd1);
+ polyBd.AddShape(polySd2);
+ polyBd.position.Set(x,y);
+ // NOTE: Added the following line to create a 3d object to display.
+ polyBd.userData = g.mgr.createCompoundWedge(points,
+ polySd1.localPosition,
+ polySd1.localRotation,
+ points,
+ polySd2.localPosition,
+ polySd2.localRotation);
+ return world.CreateBody(polyBd)
+}
+
+demos.compound.initWorld = function(world) {
+ var i;
+ for (i = 1; i <= 4; i++) {
+ demos.compound.createCompoundPoly(world, 150 + 3 * Math.random(), 40 * i);
+ }
+ for (i = 1; i <= 4; i++) {
+ demos.compound.createCompoundBall(world, 350 + 3 * Math.random(), 45 * i);
+ }
+}
+demos.InitWorlds.push(demos.compound.initWorld);
+
+