summaryrefslogtreecommitdiffstats
path: root/o3d/samples/box2d-3d/demos/top.js
diff options
context:
space:
mode:
authorgspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 23:15:42 +0000
committergspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-27 23:15:42 +0000
commit05b47f7a8c5451f858dc220df0e3a97542edace6 (patch)
treea2273d619f0625c9d44d40842845ccce2eac1045 /o3d/samples/box2d-3d/demos/top.js
parent5cdc8bdb4c847cefe7f4542bd10c9880c2c557a0 (diff)
downloadchromium_src-05b47f7a8c5451f858dc220df0e3a97542edace6.zip
chromium_src-05b47f7a8c5451f858dc220df0e3a97542edace6.tar.gz
chromium_src-05b47f7a8c5451f858dc220df0e3a97542edace6.tar.bz2
This is the O3D source tree's initial commit to the Chromium tree. It
is not built or referenced at all by the chrome build yet, and doesn't yet build in it's new home. We'll change that shortly. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/box2d-3d/demos/top.js')
-rw-r--r--o3d/samples/box2d-3d/demos/top.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/o3d/samples/box2d-3d/demos/top.js b/o3d/samples/box2d-3d/demos/top.js
new file mode 100644
index 0000000..e569e7e
--- /dev/null
+++ b/o3d/samples/box2d-3d/demos/top.js
@@ -0,0 +1,53 @@
+// 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.top = {};
+demos.top.createBall = function(world, x, y, rad, fixed) {
+ var ballSd = new b2CircleDef();
+ if (!fixed) ballSd.density = 1.0;
+ ballSd.radius = rad || 10;
+ ballSd.restitution = 0.2;
+ var ballBd = new b2BodyDef();
+ ballBd.AddShape(ballSd);
+ ballBd.position.Set(x,y);
+ // NOTE: Added the following line to create a 3d object to display.
+ ballBd.userData = g.mgr.createCylinder(ballSd.radius);
+ return world.CreateBody(ballBd);
+};
+demos.top.createPoly = function(world, x, y, points, fixed) {
+ var polySd = new b2PolyDef();
+ if (!fixed) polySd.density = 1.0;
+ polySd.vertexCount = points.length;
+ for (var i = 0; i < points.length; i++) {
+ polySd.vertices[i].Set(points[i][0], points[i][1]);
+ }
+ var polyBd = new b2BodyDef();
+ if (points.length == 3) {
+ // NOTE: Added the following line to create a 3d object to display.
+ polyBd.userData = g.mgr.createWedge(points);
+ }
+ polyBd.AddShape(polySd);
+ polyBd.position.Set(x,y);
+ return world.CreateBody(polyBd)
+};
+demos.top.initWorld = function(world) {
+ demos.top.createBall(world, 350, 100, 50, true);
+ demos.top.createPoly(world, 100, 100, [[0, 0], [10, 30], [-10, 30]], true);
+ demos.top.createPoly(world, 150, 150, [[0, 0], [10, 30], [-10, 30]], true);
+ var pendulum = createBox(world, 150, 100, 20, 20, false);
+ var jointDef = new b2RevoluteJointDef();
+ jointDef.body1 = pendulum;
+ jointDef.body2 = world.GetGroundBody();
+ jointDef.anchorPoint = pendulum.GetCenterPosition();
+ world.CreateJoint(jointDef);
+
+ var seesaw = demos.top.createPoly(world, 300, 200, [[0, 0], [100, 30], [-100, 30]]);
+ jointDef.body1 = seesaw;
+ jointDef.anchorPoint = seesaw.GetCenterPosition();
+ world.CreateJoint(jointDef);
+};
+demos.InitWorlds.push(demos.top.initWorld);
+
+