Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

nuking content - go to 'pl'

  • Loading branch information...
commit b2e3af5fa7166a901120f9a589f32e613e5215b7 1 parent e0a697d
@kevmoo kevmoo authored
Showing with 2 additions and 10,250 deletions.
  1. +0 −1  .gitignore
  2. +2 −18 README.md
  3. +0 −31 collision/ClipVertex.js
  4. +0 −62 collision/Features.js
  5. +0 −48 collision/b2AABB.js
  6. +0 −54 collision/b2Bound.js
  7. +0 −27 collision/b2BoundValues.js
  8. +0 −812 collision/b2BroadPhase.js
  9. +0 −27 collision/b2BufferedPair.js
  10. +0 −621 collision/b2Collision.js
  11. +0 −49 collision/b2ContactID.js
  12. +0 −36 collision/b2ContactPoint.js
  13. +0 −294 collision/b2Distance.js
  14. +0 −36 collision/b2Manifold.js
  15. +0 −33 collision/b2OBB.js
  16. +0 −86 collision/b2Pair.js
  17. +0 −33 collision/b2PairCallback.js
  18. +0 −364 collision/b2PairManager.js
  19. +0 −40 collision/b2Proxy.js
  20. +0 −53 collision/shapes/b2BoxDef.js
  21. +0 −38 collision/shapes/b2CircleDef.js
  22. +0 −154 collision/shapes/b2CircleShape.js
  23. +0 −28 collision/shapes/b2MassData.js
  24. +0 −63 collision/shapes/b2PolyDef.js
  25. +0 −442 collision/shapes/b2PolyShape.js
  26. +0 −239 collision/shapes/b2Shape.js
  27. +0 −65 collision/shapes/b2ShapeDef.js
  28. +0 −30 collision/shapes/b2ShapeFactory.js
  29. +0 −13 common/Util.js
  30. +0 −68 common/b2Settings.js
  31. +0 −140 common/math/b2Mat22.js
  32. +0 −58 common/math/b2Math.js
  33. +0 −193 common/math/b2Vec2.js
  34. +0 −444 dynamics/b2Body.js
  35. +0 −87 dynamics/b2BodyDef.js
  36. +0 −46 dynamics/b2CollisionFilter.js
  37. +0 −290 dynamics/b2ContactManager.js
  38. +0 −279 dynamics/b2Island.js
  39. +0 −28 dynamics/b2TimeStep.js
  40. +0 −484 dynamics/b2World.js
  41. +0 −44 dynamics/b2WorldListener.js
  42. +0 −96 dynamics/contacts/b2CircleContact.js
  43. +0 −210 dynamics/contacts/b2Conservative.js
  44. +0 −93 dynamics/contacts/b2Contact.js
  45. +0 −41 dynamics/contacts/b2ContactConstraint.js
  46. +0 −36 dynamics/contacts/b2ContactConstraintPoint.js
  47. +0 −79 dynamics/contacts/b2ContactFactory.js
  48. +0 −29 dynamics/contacts/b2ContactNode.js
  49. +0 −28 dynamics/contacts/b2ContactRegister.js
  50. +0 −510 dynamics/contacts/b2ContactSolver.js
  51. +0 −71 dynamics/contacts/b2NullContact.js
  52. +0 −96 dynamics/contacts/b2PolyAndCircleContact.js
  53. +0 −143 dynamics/contacts/b2PolyContact.js
  54. +0 −244 dynamics/joints/b2DistanceJoint.js
  55. +0 −43 dynamics/joints/b2DistanceJointDef.js
  56. +0 −254 dynamics/joints/b2GearJoint.js
  57. +0 −43 dynamics/joints/b2GearJointDef.js
  58. +0 −54 dynamics/joints/b2Jacobian.js
  59. +0 −140 dynamics/joints/b2Joint.js
  60. +0 −37 dynamics/joints/b2JointDef.js
  61. +0 −39 dynamics/joints/b2JointFactory.js
  62. +0 −29 dynamics/joints/b2JointNode.js
  63. +0 −212 dynamics/joints/b2MouseJoint.js
  64. +0 −45 dynamics/joints/b2MouseJointDef.js
  65. +0 −601 dynamics/joints/b2PrismaticJoint.js
  66. +0 −46 dynamics/joints/b2PrismaticJointDef.js
  67. +0 −534 dynamics/joints/b2PulleyJoint.js
  68. +0 −56 dynamics/joints/b2PulleyJointDef.js
  69. +0 −436 dynamics/joints/b2RevoluteJoint.js
  70. +0 −47 dynamics/joints/b2RevoluteJointDef.js
View
1  .gitignore
@@ -1 +0,0 @@
-.DS_Store
View
20 README.md
@@ -1,19 +1,3 @@
-# Box2d-JS
+This code has been migrated into the [pl](https://github.com/thinkpixellab/pl/tree/master/src/box2d) along with a bunch of other Javascript goodies.
-## Inspiration
-* [Box2D](http://www.box2d.org/) is an actively maintained, open-source C++ library.
-* [Box2D-JS](http://sourceforge.net/projects/box2d-js/) Is a javascript port of the C++ library. It was last updated 15 May, 2008.
- * See the original demo [here](http://box2d-js.sourceforge.net/).
-
-## Pixel Lab Box2d-JS
-The folks at [Pixel Lab](http://thinkpixellab.com) modified the library to use [Google's Closure Javascript Compiler](http://code.google.com/closure/compiler/) for great compression--with the added benefit of compile-time checking. (We found a lot of bugs in the original javascript).
-
-It's being used for [Agent 008 Ball](http://www.agent8ball.com/) - an HTML5 billiards game.
-
-The demo site is [here](http://box2d.thinkpixellab.com/).
-
-The demo site source, including demo code, can be found in [this Github repository](http://github.com/thinkpixellab/box2dWeb).
-
-Please open issues or fork, fix, and send a pull request.
-
-Happy to work with you.
+Please move your pointers there.
View
31 collision/ClipVertex.js
@@ -1,31 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.ClipVertex');
-
-goog.require('box2d.ContactID');
-goog.require('box2d.Vec2');
-
-/**
- @constructor
- */
-box2d.ClipVertex = function() {
- // initialize instance variables for references
- this.v = new box2d.Vec2();
- this.id = new box2d.ContactID();
-};
View
62 collision/Features.js
@@ -1,62 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.Features');
-
-/**
- @constructor
- @param {!box2d.ContactID} contactId
- */
-box2d.Features = function(contactId) {
- /*
- @type {!box2d.ContactID}
- */
- this._m_id = contactId;
- this._incidentEdg = 0;
- this._incidentVertex = 0;
- this._referenceFace = 0;
- this._flip = 0;
-};
-box2d.Features.prototype.set_referenceFace = function(value) {
- this._referenceFace = value;
- this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceFace & 0x000000ff);
-};
-box2d.Features.prototype.get_referenceFace = function() {
- return this._referenceFace;
-};
-box2d.Features.prototype.set_incidentEdge = function(value) {
- this._incidentEdge = value;
- this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00);
-};
-box2d.Features.prototype.get_incidentEdge = function() {
- return this._incidentEdge;
-};
-box2d.Features.prototype.set_incidentVertex = function(value) {
- this._incidentVertex = value;
- this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000);
-};
-box2d.Features.prototype.get_incidentVertex = function() {
- return this._incidentVertex;
-};
-box2d.Features.prototype.set_flip = function(value) {
- this._flip = value;
- this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000);
-};
-box2d.Features.prototype.get_flip = function() {
- return this._flip;
-};
View
48 collision/b2AABB.js
@@ -1,48 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.AABB');
-
-goog.require('box2d.Vec2');
-
-// A manifold for two touching convex shapes.
-/**
- @constructor
- */
-box2d.AABB = function() {
-
- /** @type {box2d.Vec2} */
- this.minVertex = new box2d.Vec2();
-
- /** @type {box2d.Vec2} */
- this.maxVertex = new box2d.Vec2();
-};
-
-/** @return {boolean} */
-box2d.AABB.prototype.IsValid = function() {
- //var d = box2d.Vec2.subtract(this.maxVertex, this.minVertex);
- var dX = this.maxVertex.x;
- var dY = this.maxVertex.y;
- dX = this.maxVertex.x;
- dY = this.maxVertex.y;
- dX -= this.minVertex.x;
- dY -= this.minVertex.y;
- var valid = dX >= 0.0 && dY >= 0.0;
- valid = valid && this.minVertex.IsValid() && this.maxVertex.IsValid();
- return valid;
-};
View
54 collision/b2Bound.js
@@ -1,54 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.Bound');
-
-/**
- @constructor
- */
-box2d.Bound = function() {
- this.value = 0;
- this.proxyId = 0;
- this.stabbingCount = 0;
-};
-
-/**
- @return {boolean}
-*/
-box2d.Bound.prototype.IsLower = function() {
- return (this.value & 1) == 0;
-};
-/**
- @return {boolean}
-*/
-box2d.Bound.prototype.IsUpper = function() {
- return (this.value & 1) == 1;
-};
-box2d.Bound.prototype.Swap = function(b) {
- var tempValue = this.value;
- var tempProxyId = this.proxyId;
- var tempStabbingCount = this.stabbingCount;
-
- this.value = b.value;
- this.proxyId = b.proxyId;
- this.stabbingCount = b.stabbingCount;
-
- b.value = tempValue;
- b.proxyId = tempProxyId;
- b.stabbingCount = tempStabbingCount;
-};
View
27 collision/b2BoundValues.js
@@ -1,27 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.BoundValues');
-
-/**
- @constructor
- */
-box2d.BoundValues = function() {
- this.lowerValues = [0, 0];
- this.upperValues = [0, 0];
-};
View
812 collision/b2BroadPhase.js
@@ -1,812 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.BroadPhase');
-
-goog.require('box2d.Bound');
-goog.require('box2d.BoundValues');
-goog.require('box2d.PairManager');
-goog.require('box2d.Proxy');
-goog.require('box2d.Settings');
-goog.require('box2d.Vec2');
-
-/*
-This broad phase uses the Sweep and Prune algorithm in:
-Collision Detection in Interactive 3D Environments by Gino van den Bergen
-Also, some ideas, such integral values for fast compares comes from
-Bullet (http:/www.bulletphysics.com).
-*/
-
-// Notes:
-// - we use bound arrays instead of linked lists for cache coherence.
-// - we use quantized integral values for fast compares.
-// - we use short indices rather than pointers to save memory.
-// - we use a stabbing count for fast overlap queries (less than order N).
-// - we also use a time stamp on each proxy to speed up the registration of
-// overlap query results.
-// - where possible, we compare bound indices instead of values to reduce
-// cache misses (TODO_ERIN).
-// - no broadphase is perfect and neither is this one: it is not great for huge
-// worlds (use a multi-SAP instead), it is not great for large objects.
-/**
- @constructor
- @param {!box2d.AABB} worldAABB
- @param {!box2d.ContactManager} callback
- */
-box2d.BroadPhase = function(worldAABB, callback) {
- // initialize instance variables for references
- this.m_pairManager = new box2d.PairManager();
-
- /**
- @type {!Array.<box2d.Proxy>}
- */
- this.proxyPool = new Array(box2d.Settings.b2_maxPairs);
- this.m_bounds = new Array(2 * box2d.Settings.b2_maxProxies);
- this.m_queryResults = new Array(box2d.Settings.b2_maxProxies);
- this.m_quantizationFactor = new box2d.Vec2();
- //
- //box2d.Settings.b2Assert(worldAABB.IsValid());
- var i = 0;
-
- this.m_pairManager.Initialize(this, callback);
-
- this.m_worldAABB = worldAABB;
-
- this.m_proxyCount = 0;
-
- // query results
- for (i = 0; i < box2d.Settings.b2_maxProxies; i++) {
- this.m_queryResults[i] = 0;
- }
-
- // bounds array
- this.m_bounds = new Array(2);
- for (i = 0; i < 2; i++) {
- this.m_bounds[i] = new Array(2 * box2d.Settings.b2_maxProxies);
- for (var j = 0; j < 2 * box2d.Settings.b2_maxProxies; j++) {
- this.m_bounds[i][j] = new box2d.Bound();
- }
- }
-
- //var d = box2d.Vec2.subtract(worldAABB.maxVertex, worldAABB.minVertex);
- var dX = worldAABB.maxVertex.x;
- var dY = worldAABB.maxVertex.y;
- dX -= worldAABB.minVertex.x;
- dY -= worldAABB.minVertex.y;
-
- this.m_quantizationFactor.x = box2d.Settings.USHRT_MAX / dX;
- this.m_quantizationFactor.y = box2d.Settings.USHRT_MAX / dY;
-
- var tProxy;
- for (i = 0; i < box2d.Settings.b2_maxProxies - 1; ++i) {
- tProxy = new box2d.Proxy();
- this.proxyPool[i] = tProxy;
- tProxy.SetNext(i + 1);
- tProxy.timeStamp = 0;
- tProxy.overlapCount = box2d.Settings.invalid;
- tProxy.userData = null;
- }
- tProxy = new box2d.Proxy();
- this.proxyPool[box2d.Settings.b2_maxProxies - 1] = tProxy;
- tProxy.SetNext(box2d.Pair.b2_nullProxy);
- tProxy.timeStamp = 0;
- tProxy.overlapCount = box2d.Settings.invalid;
- tProxy.userData = null;
- this.m_freeProxy = 0;
-
- this.m_timeStamp = 1;
- this.m_queryResultCount = 0;
-};
-
-//~b2BroadPhase();
-// Use this to see if your proxy is in range. If it is not in range,
-// it should be destroyed. Otherwise you may get O(m^2) pairs, where m
-// is the number of proxies that are out of range.
-box2d.BroadPhase.prototype.InRange = function(aabb) {
- var dX;
- var dY;
- var d2X;
- var d2Y;
-
- dX = aabb.minVertex.x;
- dY = aabb.minVertex.y;
- dX -= this.m_worldAABB.maxVertex.x;
- dY -= this.m_worldAABB.maxVertex.y;
-
- d2X = this.m_worldAABB.minVertex.x;
- d2Y = this.m_worldAABB.minVertex.y;
- d2X -= aabb.maxVertex.x;
- d2Y -= aabb.maxVertex.y;
-
- dX = Math.max(dX, d2X);
- dY = Math.max(dY, d2Y);
-
- return Math.max(dX, dY) < 0.0;
-};
-
-// Get a single proxy. Returns NULL if the id is invalid.
-box2d.BroadPhase.prototype.GetProxy = function(proxyId) {
- if (proxyId == box2d.Pair.b2_nullProxy || this.proxyPool[proxyId].IsValid() == false) {
- return null;
- }
-
- return this.proxyPool[proxyId];
-};
-
-box2d.BroadPhase.prototype.DestroyProxy = function(proxyId) {
-
- //box2d.Settings.b2Assert(0 < this.m_proxyCount && this.m_proxyCount <= b2_maxProxies);
- var proxy = this.proxyPool[proxyId];
- //box2d.Settings.b2Assert(proxy.IsValid());
- var boundCount = 2 * this.m_proxyCount;
-
- for (var axis = 0; axis < 2; ++axis) {
- var bounds = this.m_bounds[axis];
-
- var lowerIndex = proxy.lowerBounds[axis];
- var upperIndex = proxy.upperBounds[axis];
- var lowerValue = bounds[lowerIndex].value;
- var upperValue = bounds[upperIndex].value;
-
- // replace memmove calls
- //memmove(bounds + lowerIndex, bounds + lowerIndex + 1, (upperIndex - lowerIndex - 1) * sizeof(b2Bound));
- var tArr = new Array();
- var j = 0;
- var tEnd = upperIndex - lowerIndex - 1;
- var tBound1;
- var tBound2;
- // make temp array
- for (j = 0; j < tEnd; j++) {
- tArr[j] = new box2d.Bound();
- tBound1 = tArr[j];
- tBound2 = bounds[lowerIndex + 1 + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
- // move temp array back in to bounds
- tEnd = tArr.length;
- var tIndex = lowerIndex;
- for (j = 0; j < tEnd; j++) {
- //bounds[tIndex+j] = tArr[j];
- tBound2 = tArr[j];
- tBound1 = bounds[tIndex + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
- //memmove(bounds + upperIndex-1, bounds + upperIndex + 1, (edgeCount - upperIndex - 1) * sizeof(b2Bound));
- // make temp array
- tArr = new Array();
- tEnd = boundCount - upperIndex - 1;
- for (j = 0; j < tEnd; j++) {
- tArr[j] = new box2d.Bound();
- tBound1 = tArr[j];
- tBound2 = bounds[upperIndex + 1 + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
- // move temp array back in to bounds
- tEnd = tArr.length;
- tIndex = upperIndex - 1;
- for (j = 0; j < tEnd; j++) {
- //bounds[tIndex+j] = tArr[j];
- tBound2 = tArr[j];
- tBound1 = bounds[tIndex + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
-
- // Fix bound indices.
- tEnd = boundCount - 2;
- for (var index = lowerIndex; index < tEnd; ++index) {
- var proxy2 = this.proxyPool[bounds[index].proxyId];
- if (bounds[index].IsLower()) {
- proxy2.lowerBounds[axis] = index;
- } else {
- proxy2.upperBounds[axis] = index;
- }
- }
-
- // Fix stabbing count.
- tEnd = upperIndex - 1;
- for (var index2 = lowerIndex; index2 < tEnd; ++index2) {
- bounds[index2].stabbingCount--;
- }
-
- // this.Query for pairs to be removed. lowerIndex and upperIndex are not needed.
- // make lowerIndex and upper output using an array and do this for others if compiler doesn't pick them up
- this.Query([0], [0], lowerValue, upperValue, bounds, boundCount - 2, axis);
- }
-
- //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
- for (var i = 0; i < this.m_queryResultCount; ++i) {
- //box2d.Settings.b2Assert(this.proxyPool[this.m_queryResults[i]].IsValid());
- this.m_pairManager.RemoveBufferedPair(proxyId, this.m_queryResults[i]);
- }
-
- this.m_pairManager.Commit();
-
- // Prepare for next query.
- this.m_queryResultCount = 0;
- this.IncrementTimeStamp();
-
- // Return the proxy to the pool.
- proxy.userData = null;
- proxy.overlapCount = box2d.Settings.invalid;
- proxy.lowerBounds[0] = box2d.Settings.invalid;
- proxy.lowerBounds[1] = box2d.Settings.invalid;
- proxy.upperBounds[0] = box2d.Settings.invalid;
- proxy.upperBounds[1] = box2d.Settings.invalid;
-
- proxy.SetNext(this.m_freeProxy);
- this.m_freeProxy = proxyId;
- --this.m_proxyCount;
-};
-
-// this.Query an AABB for overlapping proxies, returns the user data and
-// the count, up to the supplied maximum count.
-box2d.BroadPhase.prototype.QueryAABB = function(aabb, userData, maxCount) {
- var lowerValues = new Array();
- var upperValues = new Array();
- this.ComputeBounds(lowerValues, upperValues, aabb);
-
- var lowerIndex = 0;
- var upperIndex = 0;
- var lowerIndexOut = [lowerIndex];
- var upperIndexOut = [upperIndex];
- this.Query(lowerIndexOut, upperIndexOut, lowerValues[0], upperValues[0], this.m_bounds[0], 2 * this.m_proxyCount, 0);
- this.Query(lowerIndexOut, upperIndexOut, lowerValues[1], upperValues[1], this.m_bounds[1], 2 * this.m_proxyCount, 1);
-
- //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
- var count = 0;
- for (var i = 0; i < this.m_queryResultCount && count < maxCount; ++i, ++count) {
- //box2d.Settings.b2Assert(this.m_queryResults[i] < box2d.Settings.b2_maxProxies);
- var proxy = this.proxyPool[this.m_queryResults[i]];
- //box2d.Settings.b2Assert(proxy.IsValid());
- userData[i] = proxy.userData;
- }
-
- // Prepare for next query.
- this.m_queryResultCount = 0;
- this.IncrementTimeStamp();
-
- return count;
-};
-
-box2d.BroadPhase.prototype.Validate = function() {
- var pair;
- var proxy1;
- var proxy2;
- var overlap;
-
- for (var axis = 0; axis < 2; ++axis) {
- var bounds = this.m_bounds[axis];
-
- var boundCount = 2 * this.m_proxyCount;
- var stabbingCount = 0;
-
- for (var i = 0; i < boundCount; ++i) {
- var bound = bounds[i];
- //box2d.Settings.b2Assert(i == 0 || bounds[i-1].value <= bound->value);
- //box2d.Settings.b2Assert(bound->proxyId != b2_nullProxy);
- //box2d.Settings.b2Assert(this.proxyPool[bound->proxyId].IsValid());
- if (bound.IsLower() == true) {
- //box2d.Settings.b2Assert(this.proxyPool[bound.proxyId].lowerBounds[axis] == i);
- stabbingCount++;
- } else {
- //box2d.Settings.b2Assert(this.proxyPool[bound.proxyId].upperBounds[axis] == i);
- stabbingCount--;
- }
-
- //box2d.Settings.b2Assert(bound.stabbingCount == stabbingCount);
- }
- }
-
-};
-
-//private:
-box2d.BroadPhase.prototype.ComputeBounds = function(lowerValues, upperValues, aabb) {
- //box2d.Settings.b2Assert(aabb.maxVertex.x > aabb.minVertex.x);
- //box2d.Settings.b2Assert(aabb.maxVertex.y > aabb.minVertex.y);
- var minVertexX = aabb.minVertex.x;
- var minVertexY = aabb.minVertex.y;
- minVertexX = Math.min(minVertexX, this.m_worldAABB.maxVertex.x);
- minVertexY = Math.min(minVertexY, this.m_worldAABB.maxVertex.y);
- minVertexX = Math.max(minVertexX, this.m_worldAABB.minVertex.x);
- minVertexY = Math.max(minVertexY, this.m_worldAABB.minVertex.y);
-
- var maxVertexX = aabb.maxVertex.x;
- var maxVertexY = aabb.maxVertex.y;
- maxVertexX = Math.min(maxVertexX, this.m_worldAABB.maxVertex.x);
- maxVertexY = Math.min(maxVertexY, this.m_worldAABB.maxVertex.y);
- maxVertexX = Math.max(maxVertexX, this.m_worldAABB.minVertex.x);
- maxVertexY = Math.max(maxVertexY, this.m_worldAABB.minVertex.y);
-
- // Bump lower bounds downs and upper bounds up. This ensures correct sorting of
- // lower/upper bounds that would have equal values.
- // TODO_ERIN implement fast float to uint16 conversion.
- lowerValues[0] =
- /*uint*/
- (this.m_quantizationFactor.x * (minVertexX - this.m_worldAABB.minVertex.x)) & (box2d.Settings.USHRT_MAX - 1);
- upperValues[0] = (
- /*uint*/
- (this.m_quantizationFactor.x * (maxVertexX - this.m_worldAABB.minVertex.x)) & 0x0000ffff) | 1;
-
- lowerValues[1] =
- /*uint*/
- (this.m_quantizationFactor.y * (minVertexY - this.m_worldAABB.minVertex.y)) & (box2d.Settings.USHRT_MAX - 1);
- upperValues[1] = (
- /*uint*/
- (this.m_quantizationFactor.y * (maxVertexY - this.m_worldAABB.minVertex.y)) & 0x0000ffff) | 1;
-};
-
-// This one is only used for validation.
-box2d.BroadPhase.prototype.TestOverlapValidate = function(p1, p2) {
-
- for (var axis = 0; axis < 2; ++axis) {
- var bounds = this.m_bounds[axis];
-
- //box2d.Settings.b2Assert(p1.lowerBounds[axis] < 2 * this.m_proxyCount);
- //box2d.Settings.b2Assert(p1.upperBounds[axis] < 2 * this.m_proxyCount);
- //box2d.Settings.b2Assert(p2.lowerBounds[axis] < 2 * this.m_proxyCount);
- //box2d.Settings.b2Assert(p2.upperBounds[axis] < 2 * this.m_proxyCount);
- if (bounds[p1.lowerBounds[axis]].value > bounds[p2.upperBounds[axis]].value) return false;
-
- if (bounds[p1.upperBounds[axis]].value < bounds[p2.lowerBounds[axis]].value) return false;
- }
-
- return true;
-};
-
-box2d.BroadPhase.prototype.TestOverlap = function(b, p) {
- for (var axis = 0; axis < 2; ++axis) {
- var bounds = this.m_bounds[axis];
-
- //box2d.Settings.b2Assert(p.lowerBounds[axis] < 2 * this.m_proxyCount);
- //box2d.Settings.b2Assert(p.upperBounds[axis] < 2 * this.m_proxyCount);
- if (b.lowerValues[axis] > bounds[p.upperBounds[axis]].value) return false;
-
- if (b.upperValues[axis] < bounds[p.lowerBounds[axis]].value) return false;
- }
-
- return true;
-};
-
-box2d.BroadPhase.prototype.Query = function(lowerQueryOut, upperQueryOut, lowerValue, upperValue, bounds, boundCount, axis) {
-
- var lowerQuery = box2d.BroadPhase.BinarySearch(bounds, boundCount, lowerValue);
- var upperQuery = box2d.BroadPhase.BinarySearch(bounds, boundCount, upperValue);
-
- // Easy case: lowerQuery <= lowerIndex(i) < upperQuery
- // Solution: search query range for min bounds.
- for (var j = lowerQuery; j < upperQuery; ++j) {
- if (bounds[j].IsLower()) {
- this.IncrementOverlapCount(bounds[j].proxyId);
- }
- }
-
- // Hard case: lowerIndex(i) < lowerQuery < upperIndex(i)
- // Solution: use the stabbing count to search down the bound array.
- if (lowerQuery > 0) {
- var i = lowerQuery - 1;
- var s = bounds[i].stabbingCount;
-
- // Find the s overlaps.
- while (s) {
- //box2d.Settings.b2Assert(i >= 0);
- if (bounds[i].IsLower()) {
- var proxy = this.proxyPool[bounds[i].proxyId];
- if (lowerQuery <= proxy.upperBounds[axis]) {
- this.IncrementOverlapCount(bounds[i].proxyId);
- --s;
- }
- } --i;
- }
- }
-
- lowerQueryOut[0] = lowerQuery;
- upperQueryOut[0] = upperQuery;
-};
-
-box2d.BroadPhase.prototype.IncrementOverlapCount = function(proxyId) {
- var proxy = this.proxyPool[proxyId];
- if (proxy.timeStamp < this.m_timeStamp) {
- proxy.timeStamp = this.m_timeStamp;
- proxy.overlapCount = 1;
- } else {
- proxy.overlapCount = 2;
- //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
- this.m_queryResults[this.m_queryResultCount] = proxyId;
- ++this.m_queryResultCount;
- }
-};
-box2d.BroadPhase.prototype.IncrementTimeStamp = function() {
- if (this.m_timeStamp == box2d.Settings.USHRT_MAX) {
- for (var i = 0; i < box2d.Settings.b2_maxProxies; ++i) {
- this.proxyPool[i].timeStamp = 0;
- }
- this.m_timeStamp = 1;
- } else {
- ++this.m_timeStamp;
- }
-};
-
-// Call this.MoveProxy times like, then when you are done
-// call this.Commit to finalized the proxy pairs (for your time step).
-/**
- @param {number} proxyId
- @param {!box2d.AABB} aabb
- */
-box2d.BroadPhase.prototype.MoveProxy = function(proxyId, aabb) {
- var axis = 0;
- var index = 0;
- var bound;
- var prevBound;
- var nextBound;
- var nextProxyId = 0;
- var nextProxy;
-
- if (proxyId == box2d.Pair.b2_nullProxy || box2d.Settings.b2_maxProxies <= proxyId) {
- //box2d.Settings.b2Assert(false);
- return;
- }
-
- if (aabb.IsValid() == false) {
- //box2d.Settings.b2Assert(false);
- return;
- }
-
- var boundCount = 2 * this.m_proxyCount;
-
- var proxy = this.proxyPool[proxyId];
- // Get new bound values
- var newValues = new box2d.BoundValues();
- this.ComputeBounds(newValues.lowerValues, newValues.upperValues, aabb);
-
- // Get old bound values
- var oldValues = new box2d.BoundValues();
- for (axis = 0; axis < 2; ++axis) {
- oldValues.lowerValues[axis] = this.m_bounds[axis][proxy.lowerBounds[axis]].value;
- oldValues.upperValues[axis] = this.m_bounds[axis][proxy.upperBounds[axis]].value;
- }
-
- for (axis = 0; axis < 2; ++axis) {
- var bounds = this.m_bounds[axis];
-
- var lowerIndex = proxy.lowerBounds[axis];
- var upperIndex = proxy.upperBounds[axis];
-
- var lowerValue = newValues.lowerValues[axis];
- var upperValue = newValues.upperValues[axis];
-
- var deltaLower = lowerValue - bounds[lowerIndex].value;
- var deltaUpper = upperValue - bounds[upperIndex].value;
-
- bounds[lowerIndex].value = lowerValue;
- bounds[upperIndex].value = upperValue;
-
- //
- // Expanding adds overlaps
- //
- // Should we move the lower bound down?
- if (deltaLower < 0) {
- index = lowerIndex;
- while (index > 0 && lowerValue < bounds[index - 1].value) {
- bound = bounds[index];
- prevBound = bounds[index - 1];
-
- var prevProxyId = prevBound.proxyId;
- var prevProxy = this.proxyPool[prevBound.proxyId];
-
- prevBound.stabbingCount++;
-
- if (prevBound.IsUpper() == true) {
- if (this.TestOverlap(newValues, prevProxy)) {
- this.m_pairManager.AddBufferedPair(proxyId, prevProxyId);
- }
-
- prevProxy.upperBounds[axis]++;
- bound.stabbingCount++;
- } else {
- prevProxy.lowerBounds[axis]++;
- bound.stabbingCount--;
- }
-
- proxy.lowerBounds[axis]--;
-
- // swap
- //var temp = bound;
- //bound = prevEdge;
- //prevEdge = temp;
- bound.Swap(prevBound);
- --index;
- }
- }
-
- // Should we move the upper bound up?
- if (deltaUpper > 0) {
- index = upperIndex;
- while (index < boundCount - 1 && bounds[index + 1].value <= upperValue) {
- bound = bounds[index];
- nextBound = bounds[index + 1];
- nextProxyId = nextBound.proxyId;
- nextProxy = this.proxyPool[nextProxyId];
-
- nextBound.stabbingCount++;
-
- if (nextBound.IsLower() == true) {
- if (this.TestOverlap(newValues, nextProxy)) {
- this.m_pairManager.AddBufferedPair(proxyId, nextProxyId);
- }
-
- nextProxy.lowerBounds[axis]--;
- bound.stabbingCount++;
- } else {
- nextProxy.upperBounds[axis]--;
- bound.stabbingCount--;
- }
-
- proxy.upperBounds[axis]++;
- // swap
- //var temp = bound;
- //bound = nextEdge;
- //nextEdge = temp;
- bound.Swap(nextBound);
- index++;
- }
- }
-
- //
- // Shrinking removes overlaps
- //
- // Should we move the lower bound up?
- if (deltaLower > 0) {
- index = lowerIndex;
- while (index < boundCount - 1 && bounds[index + 1].value <= lowerValue) {
- bound = bounds[index];
- nextBound = bounds[index + 1];
-
- nextProxyId = nextBound.proxyId;
- nextProxy = this.proxyPool[nextProxyId];
-
- nextBound.stabbingCount--;
-
- if (nextBound.IsUpper()) {
- if (this.TestOverlap(oldValues, nextProxy)) {
- this.m_pairManager.RemoveBufferedPair(proxyId, nextProxyId);
- }
-
- nextProxy.upperBounds[axis]--;
- bound.stabbingCount--;
- } else {
- nextProxy.lowerBounds[axis]--;
- bound.stabbingCount++;
- }
-
- proxy.lowerBounds[axis]++;
- // swap
- //var temp = bound;
- //bound = nextEdge;
- //nextEdge = temp;
- bound.Swap(nextBound);
- index++;
- }
- }
-
- // Should we move the upper bound down?
- if (deltaUpper < 0) {
- index = upperIndex;
- while (index > 0 && upperValue < bounds[index - 1].value) {
- bound = bounds[index];
- prevBound = bounds[index - 1];
-
- prevProxyId = prevBound.proxyId;
- prevProxy = this.proxyPool[prevProxyId];
-
- prevBound.stabbingCount--;
-
- if (prevBound.IsLower() == true) {
- if (this.TestOverlap(oldValues, prevProxy)) {
- this.m_pairManager.RemoveBufferedPair(proxyId, prevProxyId);
- }
-
- prevProxy.lowerBounds[axis]++;
- bound.stabbingCount--;
- } else {
- prevProxy.upperBounds[axis]++;
- bound.stabbingCount++;
- }
-
- proxy.upperBounds[axis]--;
- // swap
- //var temp = bound;
- //bound = prevEdge;
- //prevEdge = temp;
- bound.Swap(prevBound);
- index--;
- }
- }
- }
-};
-
-/**
- @return {!Array.<box2d.Pair>}
- */
-box2d.BroadPhase.prototype.Commit = function() {
- return this.m_pairManager.Commit();
-};
-
-/**
- // Create and destroy proxies. These call Flush first.
- @param {!box2d.AABB} aabb
- @param {!box2d.Shape} userData
- @return {number}
- */
-box2d.BroadPhase.prototype.CreateProxy = function(aabb, userData) {
- var index = 0;
- var proxy;
-
- //box2d.Settings.b2Assert(this.m_proxyCount < b2_maxProxies);
- //box2d.Settings.b2Assert(this.m_freeProxy != box2d.Pair.b2_nullProxy);
- var proxyId = this.m_freeProxy;
- proxy = this.proxyPool[proxyId];
- this.m_freeProxy = proxy.GetNext();
-
- proxy.overlapCount = 0;
- proxy.userData = userData;
-
- var boundCount = 2 * this.m_proxyCount;
-
- var lowerValues = new Array();
- var upperValues = new Array();
- this.ComputeBounds(lowerValues, upperValues, aabb);
-
- for (var axis = 0; axis < 2; ++axis) {
- var bounds = this.m_bounds[axis];
- var lowerIndex = 0;
- var upperIndex = 0;
- var lowerIndexOut = [lowerIndex];
- var upperIndexOut = [upperIndex];
- this.Query(lowerIndexOut, upperIndexOut, lowerValues[axis], upperValues[axis], bounds, boundCount, axis);
- lowerIndex = lowerIndexOut[0];
- upperIndex = upperIndexOut[0];
-
- // Replace memmove calls
- //memmove(bounds + upperIndex + 2, bounds + upperIndex, (edgeCount - upperIndex) * sizeof(b2Bound));
- var tArr = new Array();
- var j = 0;
- var tEnd = boundCount - upperIndex;
- var tBound1;
- var tBound2;
- // make temp array
- for (j = 0; j < tEnd; j++) {
- tArr[j] = new box2d.Bound();
- tBound1 = tArr[j];
- tBound2 = bounds[upperIndex + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
- // move temp array back in to bounds
- tEnd = tArr.length;
- var tIndex = upperIndex + 2;
- for (j = 0; j < tEnd; j++) {
- //bounds[tIndex+j] = tArr[j];
- tBound2 = tArr[j];
- tBound1 = bounds[tIndex + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
- //memmove(bounds + lowerIndex + 1, bounds + lowerIndex, (upperIndex - lowerIndex) * sizeof(b2Bound));
- // make temp array
- tArr = new Array();
- tEnd = upperIndex - lowerIndex;
- for (j = 0; j < tEnd; j++) {
- tArr[j] = new box2d.Bound();
- tBound1 = tArr[j];
- tBound2 = bounds[lowerIndex + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
- // move temp array back in to bounds
- tEnd = tArr.length;
- tIndex = lowerIndex + 1;
- for (j = 0; j < tEnd; j++) {
- //bounds[tIndex+j] = tArr[j];
- tBound2 = tArr[j];
- tBound1 = bounds[tIndex + j];
- tBound1.value = tBound2.value;
- tBound1.proxyId = tBound2.proxyId;
- tBound1.stabbingCount = tBound2.stabbingCount;
- }
-
- // The upper index has increased because of the lower bound insertion.
- ++upperIndex;
-
- // Copy in the new bounds.
- bounds[lowerIndex].value = lowerValues[axis];
- bounds[lowerIndex].proxyId = proxyId;
- bounds[upperIndex].value = upperValues[axis];
- bounds[upperIndex].proxyId = proxyId;
-
- bounds[lowerIndex].stabbingCount = lowerIndex == 0 ? 0 : bounds[lowerIndex - 1].stabbingCount;
- bounds[upperIndex].stabbingCount = bounds[upperIndex - 1].stabbingCount;
-
- // Adjust the stabbing count between the new bounds.
- for (index = lowerIndex; index < upperIndex; ++index) {
- bounds[index].stabbingCount++;
- }
-
- // Adjust the all the affected bound indices.
- for (index = lowerIndex; index < boundCount + 2; ++index) {
- var proxy2 = this.proxyPool[bounds[index].proxyId];
- if (bounds[index].IsLower()) {
- proxy2.lowerBounds[axis] = index;
- } else {
- proxy2.upperBounds[axis] = index;
- }
- }
- }
-
- ++this.m_proxyCount;
-
- //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
- for (var i = 0; i < this.m_queryResultCount; ++i) {
- //box2d.Settings.b2Assert(this.m_queryResults[i] < b2_maxProxies);
- //box2d.Settings.b2Assert(this.proxyPool[this.m_queryResults[i]].IsValid());
- this.m_pairManager.AddBufferedPair(proxyId, this.m_queryResults[i]);
- }
-
- this.m_pairManager.Commit();
-
- // Prepare for next query.
- this.m_queryResultCount = 0;
- this.IncrementTimeStamp();
-
- return proxyId;
-};
-
-/**
- @private
- @type {number}
- */
-box2d.BroadPhase.m_freeProxy = 0;
-
-box2d.BroadPhase.s_validate = false;
-box2d.BroadPhase.b2_nullEdge = box2d.Settings.USHRT_MAX;
-box2d.BroadPhase.BinarySearch = function(bounds, count, value) {
- var low = 0;
- var high = count - 1;
- while (low <= high) {
- var mid = Math.floor((low + high) / 2);
- if (bounds[mid].value > value) {
- high = mid - 1;
- } else if (bounds[mid].value < value) {
- low = mid + 1;
- } else {
- return (mid);
- }
- }
-
- return (low);
-};
View
27 collision/b2BufferedPair.js
@@ -1,27 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.BufferedPair');
-
-/**
- @constructor
- */
-box2d.BufferedPair = function() {
- this.proxyId1 = 0;
- this.proxyId2 = 0;
-};
View
621 collision/b2Collision.js
@@ -1,621 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.Collision');
-
-goog.require('box2d.ClipVertex');
-
-box2d.Collision.b2_nullFeature = 0x000000ff;
-box2d.Collision.ClipSegmentToLine = function(vOut, vIn, normal, offset) {
- // Start with no output points
- var numOut = 0;
-
- var vIn0 = vIn[0].v;
- var vIn1 = vIn[1].v;
-
- // Calculate the distance of end points to the line
- var distance0 = goog.math.Vec2.dot(normal, vIn[0].v) - offset;
- var distance1 = goog.math.Vec2.dot(normal, vIn[1].v) - offset;
-
- // If the points are behind the plane
- if (distance0 <= 0.0) vOut[numOut++] = vIn[0];
- if (distance1 <= 0.0) vOut[numOut++] = vIn[1];
-
- // If the points are on different sides of the plane
- if (distance0 * distance1 < 0.0) {
- // Find intersection point of edge and plane
- var interp = distance0 / (distance0 - distance1);
- // expanded for performance
- var tVec = vOut[numOut].v;
- tVec.x = vIn0.x + interp * (vIn1.x - vIn0.x);
- tVec.y = vIn0.y + interp * (vIn1.y - vIn0.y);
- if (distance0 > 0.0) {
- vOut[numOut].id = vIn[0].id;
- } else {
- vOut[numOut].id = vIn[1].id;
- } ++numOut;
- }
-
- return numOut;
-};
-box2d.Collision.EdgeSeparation = function(poly1, edge1, poly2) {
- var vert1s = poly1.m_vertices;
- var count2 = poly2.m_vertexCount;
- var vert2s = poly2.m_vertices;
-
- // Convert normal from into poly2's frame.
- //box2d.Settings.b2Assert(edge1 < poly1.m_vertexCount);
- //var normal = box2d.Math.b2MulMV(poly1.m_R, poly1->m_normals[edge1]);
- var normalX = poly1.m_normals[edge1].x;
- var normalY = poly1.m_normals[edge1].y;
- var tX = normalX;
- var tMat = poly1.m_R;
- normalX = tMat.col1.x * tX + tMat.col2.x * normalY;
- normalY = tMat.col1.y * tX + tMat.col2.y * normalY;
- // ^^^^^^^ normal.MulM(poly1.m_R);
- //var normalLocal2 = box2d.Math.b2MulTMV(poly2.m_R, normal);
- var normalLocal2X = normalX;
- var normalLocal2Y = normalY;
- tMat = poly2.m_R;
- tX = normalLocal2X * tMat.col1.x + normalLocal2Y * tMat.col1.y;
- normalLocal2Y = normalLocal2X * tMat.col2.x + normalLocal2Y * tMat.col2.y;
- normalLocal2X = tX;
- // ^^^^^ normalLocal2.MulTM(poly2.m_R);
- // Find support vertex on poly2 for -normal.
- var vertexIndex2 = 0;
- var minDot = Number.MAX_VALUE;
- for (var i = 0; i < count2; ++i) {
- //var dot = goog.math.Vec2.dot(vert2s[i], normalLocal2);
- var tVec = vert2s[i];
- var dot = tVec.x * normalLocal2X + tVec.y * normalLocal2Y;
- if (dot < minDot) {
- minDot = dot;
- vertexIndex2 = i;
- }
- }
-
- //box2d.Vec2 v1 = poly1->m_position + b2Mul(poly1->m_R, vert1s[edge1]);
- tMat = poly1.m_R;
- var v1X = poly1.m_position.x + (tMat.col1.x * vert1s[edge1].x + tMat.col2.x * vert1s[edge1].y);
- var v1Y = poly1.m_position.y + (tMat.col1.y * vert1s[edge1].x + tMat.col2.y * vert1s[edge1].y);
-
- //box2d.Vec2 v2 = poly2->m_position + b2Mul(poly2->m_R, vert2s[vertexIndex2]);
- tMat = poly2.m_R;
- var v2X = poly2.m_position.x + (tMat.col1.x * vert2s[vertexIndex2].x + tMat.col2.x * vert2s[vertexIndex2].y);
- var v2Y = poly2.m_position.y + (tMat.col1.y * vert2s[vertexIndex2].x + tMat.col2.y * vert2s[vertexIndex2].y);
-
- //var separation = goog.math.Vec2.dot( box2d.Vec2.subtract( v2, v1 ) , normal);
- v2X -= v1X;
- v2Y -= v1Y;
- //var separation = goog.math.Vec2.dot( v2 , normal);
- var separation = v2X * normalX + v2Y * normalY;
- return separation;
-};
-box2d.Collision.FindMaxSeparation = function(edgeIndex
-/*int ptr*/
-, poly1, poly2, conservative) {
- var count1 = poly1.m_vertexCount;
-
- // Vector pointing from the origin of poly1 to the origin of poly2.
- //var d = box2d.Vec2.subtract( poly2.m_position, poly1.m_position );
- var dX = poly2.m_position.x - poly1.m_position.x;
- var dY = poly2.m_position.y - poly1.m_position.y;
-
- //var dLocal1 = box2d.Math.b2MulTMV(poly1.m_R, d);
- var dLocal1X = (dX * poly1.m_R.col1.x + dY * poly1.m_R.col1.y);
- var dLocal1Y = (dX * poly1.m_R.col2.x + dY * poly1.m_R.col2.y);
-
- // Get support vertex hint for our search
- var edge = 0;
- var maxDot = -Number.MAX_VALUE;
- for (var i = 0; i < count1; ++i) {
- //var dot = goog.math.Vec2.dot(poly.m_normals[i], dLocal1);
- var dot = (poly1.m_normals[i].x * dLocal1X + poly1.m_normals[i].y * dLocal1Y);
- if (dot > maxDot) {
- maxDot = dot;
- edge = i;
- }
- }
-
- // Get the separation for the edge normal.
- var s = box2d.Collision.EdgeSeparation(poly1, edge, poly2);
- if (s > 0.0 && conservative == false) {
- return s;
- }
-
- // Check the separation for the neighboring edges.
- var prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
- var sPrev = box2d.Collision.EdgeSeparation(poly1, prevEdge, poly2);
- if (sPrev > 0.0 && conservative == false) {
- return sPrev;
- }
-
- var nextEdge = edge + 1 < count1 ? edge + 1 : 0;
- var sNext = box2d.Collision.EdgeSeparation(poly1, nextEdge, poly2);
- if (sNext > 0.0 && conservative == false) {
- return sNext;
- }
-
- // Find the best edge and the search direction.
- var bestEdge = 0;
- var bestSeparation;
- var increment = 0;
- if (sPrev > s && sPrev > sNext) {
- increment = -1;
- bestEdge = prevEdge;
- bestSeparation = sPrev;
- } else if (sNext > s) {
- increment = 1;
- bestEdge = nextEdge;
- bestSeparation = sNext;
- } else {
- // pointer out
- edgeIndex[0] = edge;
- return s;
- }
-
- while (true) {
-
- if (increment == -1) edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
- else edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;
-
- s = box2d.Collision.EdgeSeparation(poly1, edge, poly2);
- if (s > 0.0 && conservative == false) {
- return s;
- }
-
- if (s > bestSeparation) {
- bestEdge = edge;
- bestSeparation = s;
- } else {
- break;
- }
- }
-
- // pointer out
- edgeIndex[0] = bestEdge;
- return bestSeparation;
-};
-box2d.Collision.FindIncidentEdge = function(c, poly1, edge1, poly2) {
- var count1 = poly1.m_vertexCount;
- var vert1s = poly1.m_vertices;
- var count2 = poly2.m_vertexCount;
- var vert2s = poly2.m_vertices;
-
- // Get the vertices associated with edge1.
- var vertex11 = edge1;
- var vertex12 = edge1 + 1 == count1 ? 0 : edge1 + 1;
-
- // Get the normal of edge1.
- var tVec = vert1s[vertex12];
- //var normal1Local1 = box2d.Math.b2CrossVF( box2d.Vec2.subtract( vert1s[vertex12], vert1s[vertex11] ), 1.0);
- var normal1Local1X = tVec.x;
- var normal1Local1Y = tVec.y;
- tVec = vert1s[vertex11];
- normal1Local1X -= tVec.x;
- normal1Local1Y -= tVec.y;
- var tX = normal1Local1X;
- normal1Local1X = normal1Local1Y;
- normal1Local1Y = -tX;
- // ^^^^ normal1Local1.CrossVF(1.0);
- var invLength = 1.0 / Math.sqrt(normal1Local1X * normal1Local1X + normal1Local1Y * normal1Local1Y);
- normal1Local1X *= invLength;
- normal1Local1Y *= invLength;
- // ^^^^normal1Local1.Normalize();
- //var normal1 = box2d.Math.b2MulMV(poly1.m_R, normal1Local1);
- var normal1X = normal1Local1X;
- var normal1Y = normal1Local1Y;
-
- tX = normal1X;
- var tMat = poly1.m_R;
- normal1X = tMat.col1.x * tX + tMat.col2.x * normal1Y;
- normal1Y = tMat.col1.y * tX + tMat.col2.y * normal1Y;
- // ^^^^ normal1.MulM(poly1.m_R);
- //var normal1Local2 = box2d.Math.b2MulTMV(poly2.m_R, normal1);
- var normal1Local2X = normal1X;
- var normal1Local2Y = normal1Y;
- tMat = poly2.m_R;
- tX = normal1Local2X * tMat.col1.x + normal1Local2Y * tMat.col1.y;
- normal1Local2Y = normal1Local2X * tMat.col2.x + normal1Local2Y * tMat.col2.y;
- normal1Local2X = tX;
- // ^^^^ normal1Local2.MulTM(poly2.m_R);
- // Find the incident edge on poly2.
- var vertex21 = 0;
- var vertex22 = 0;
- var minDot = Number.MAX_VALUE;
- for (var i = 0; i < count2; ++i) {
- var i1 = i;
- var i2 = i + 1 < count2 ? i + 1 : 0;
-
- //var normal2Local2 = box2d.Math.b2CrossVF( box2d.Vec2.subtract( vert2s[i2], vert2s[i1] ), 1.0);
- tVec = vert2s[i2];
- var normal2Local2X = tVec.x;
- var normal2Local2Y = tVec.y;
- tVec = vert2s[i1];
- normal2Local2X -= tVec.x;
- normal2Local2Y -= tVec.y;
- tX = normal2Local2X;
- normal2Local2X = normal2Local2Y;
- normal2Local2Y = -tX;
- // ^^^^ normal2Local2.CrossVF(1.0);
- invLength = 1.0 / Math.sqrt(normal2Local2X * normal2Local2X + normal2Local2Y * normal2Local2Y);
- normal2Local2X *= invLength;
- normal2Local2Y *= invLength;
- // ^^^^ normal2Local2.Normalize();
- //var dot = goog.math.Vec2.dot(normal2Local2, normal1Local2);
- var dot = normal2Local2X * normal1Local2X + normal2Local2Y * normal1Local2Y;
- if (dot < minDot) {
- minDot = dot;
- vertex21 = i1;
- vertex22 = i2;
- }
- }
-
- var tClip;
- // Build the clip vertices for the incident edge.
- tClip = c[0];
- //tClip.v = box2d.Vec2.add(poly2.m_position, box2d.Math.b2MulMV(poly2.m_R, vert2s[vertex21]));
- tVec = tClip.v;
- tVec.SetV(vert2s[vertex21]);
- tVec.MulM(poly2.m_R);
- tVec.add(poly2.m_position);
-
- tClip.id.features.referenceFace = edge1;
- tClip.id.features.incidentEdge = vertex21;
- tClip.id.features.incidentVertex = vertex21;
-
- tClip = c[1];
- //tClip.v = box2d.Vec2.add(poly2.m_position, box2d.Math.b2MulMV(poly2.m_R, vert2s[vertex22]));
- tVec = tClip.v;
- tVec.SetV(vert2s[vertex22]);
- tVec.MulM(poly2.m_R);
- tVec.add(poly2.m_position);
- tClip.id.features.referenceFace = edge1;
- tClip.id.features.incidentEdge = vertex21;
- tClip.id.features.incidentVertex = vertex22;
-};
-box2d.Collision.b2CollidePolyTempVec = new box2d.Vec2();
-box2d.Collision.b2CollidePoly = function(manifold, polyA, polyB, conservative) {
- manifold.pointCount = 0;
-
- var edgeA = 0;
- var edgeAOut = [edgeA];
- var separationA = box2d.Collision.FindMaxSeparation(edgeAOut, polyA, polyB, conservative);
- edgeA = edgeAOut[0];
- if (separationA > 0.0 && conservative == false) return;
-
- var edgeB = 0;
- var edgeBOut = [edgeB];
- var separationB = box2d.Collision.FindMaxSeparation(edgeBOut, polyB, polyA, conservative);
- edgeB = edgeBOut[0];
- if (separationB > 0.0 && conservative == false) return;
-
- var poly1;
- var poly2;
- var edge1 = 0;
- var flip = 0;
- var k_relativeTol = 0.98;
- var k_absoluteTol = 0.001;
-
- // TODO_ERIN use "radius" of poly for absolute tolerance.
- if (separationB > k_relativeTol * separationA + k_absoluteTol) {
- poly1 = polyB;
- poly2 = polyA;
- edge1 = edgeB;
- flip = 1;
- } else {
- poly1 = polyA;
- poly2 = polyB;
- edge1 = edgeA;
- flip = 0;
- }
-
- var incidentEdge = [new box2d.ClipVertex(), new box2d.ClipVertex()];
- box2d.Collision.FindIncidentEdge(incidentEdge, poly1, edge1, poly2);
-
- var count1 = poly1.m_vertexCount;
- var vert1s = poly1.m_vertices;
-
- var v11 = vert1s[edge1];
- var v12 = edge1 + 1 < count1 ? vert1s[edge1 + 1] : vert1s[0];
-
- //var dv = box2d.Vec2.subtract(v12, v11);
- var dvX = v12.x - v11.x;
- var dvY = v12.y - v11.y;
-
- //var sideNormal = box2d.Math.b2MulMV(poly1.m_R, box2d.Vec2.subtract(v12, v11));
- var sideNormalX = v12.x - v11.x;
- var sideNormalY = v12.y - v11.y;
-
- var tX = sideNormalX;
- var tMat = poly1.m_R;
- sideNormalX = tMat.col1.x * tX + tMat.col2.x * sideNormalY;
- sideNormalY = tMat.col1.y * tX + tMat.col2.y * sideNormalY;
- // ^^^^ sideNormal.MulM(poly1.m_R);
- var invLength = 1.0 / Math.sqrt(sideNormalX * sideNormalX + sideNormalY * sideNormalY);
- sideNormalX *= invLength;
- sideNormalY *= invLength;
-
- var frontNormalX = sideNormalX;
- var frontNormalY = sideNormalY;
- tX = frontNormalX;
- frontNormalX = frontNormalY;
- frontNormalY = -tX;
-
- // Expanded for performance
- var v11X = v11.x;
- var v11Y = v11.y;
- tX = v11X;
- tMat = poly1.m_R;
- v11X = tMat.col1.x * tX + tMat.col2.x * v11Y;
- v11Y = tMat.col1.y * tX + tMat.col2.y * v11Y;
- // ^^^^ v11.MulM(poly1.m_R);
- v11X += poly1.m_position.x;
- v11Y += poly1.m_position.y;
- //v12 = box2d.Vec2.add(poly1.m_position, box2d.Math.b2MulMV(poly1.m_R, v12));
- var v12X = v12.x;
- var v12Y = v12.y;
- tX = v12X;
- tMat = poly1.m_R;
- v12X = tMat.col1.x * tX + tMat.col2.x * v12Y;
- v12Y = tMat.col1.y * tX + tMat.col2.y * v12Y;
- // ^^^^ v12.MulM(poly1.m_R);
- v12X += poly1.m_position.x;
- v12Y += poly1.m_position.y;
-
- //var frontOffset = goog.math.Vec2.dot(frontNormal, v11);
- var frontOffset = frontNormalX * v11X + frontNormalY * v11Y;
- //var sideOffset1 = -goog.math.Vec2.dot(sideNormal, v11);
- var sideOffset1 = -(sideNormalX * v11X + sideNormalY * v11Y);
- //var sideOffset2 = goog.math.Vec2.dot(sideNormal, v12);
- var sideOffset2 = sideNormalX * v12X + sideNormalY * v12Y;
-
- // Clip incident edge against extruded edge1 side edges.
- var clipPoints1 = [new box2d.ClipVertex(), new box2d.ClipVertex()];
- var clipPoints2 = [new box2d.ClipVertex(), new box2d.ClipVertex()];
-
- var np = 0;
-
- // Clip to box side 1
- box2d.Collision.b2CollidePolyTempVec.Set(-sideNormalX, -sideNormalY);
- np = box2d.Collision.ClipSegmentToLine(clipPoints1, incidentEdge, box2d.Collision.b2CollidePolyTempVec, sideOffset1);
-
- if (np < 2) return;
-
- // Clip to negative box side 1
- box2d.Collision.b2CollidePolyTempVec.Set(sideNormalX, sideNormalY);
- np = box2d.Collision.ClipSegmentToLine(clipPoints2, clipPoints1, box2d.Collision.b2CollidePolyTempVec, sideOffset2);
-
- if (np < 2) return;
-
- // Now clipPoints2 contains the clipped points.
- if (flip) {
- manifold.normal.Set(-frontNormalX, -frontNormalY);
- } else {
- manifold.normal.Set(frontNormalX, frontNormalY);
- }
- // ^^^^ manifold.normal = flip ? frontNormal.Negative() : frontNormal;
- var pointCount = 0;
- for (var i = 0; i < box2d.Settings.b2_maxManifoldPoints; ++i) {
- //var separation = goog.math.Vec2.dot(frontNormal, clipPoints2[i].v) - frontOffset;
- var tVec = clipPoints2[i].v;
- var separation = (frontNormalX * tVec.x + frontNormalY * tVec.y) - frontOffset;
-
- if (separation <= 0.0 || conservative == true) {
- var cp = manifold.points[pointCount];
- cp.separation = separation;
- cp.position.SetV(clipPoints2[i].v);
- cp.id.Set(clipPoints2[i].id);
- cp.id.features.flip = flip;
- ++pointCount;
- }
- }
-
- manifold.pointCount = pointCount;
-};
-box2d.Collision.b2CollideCircle = function(manifold, circle1, circle2, conservative) {
- manifold.pointCount = 0;
-
- //var d = box2d.Vec2.subtract(circle2.m_position, circle1.m_position);
- var dX = circle2.m_position.x - circle1.m_position.x;
- var dY = circle2.m_position.y - circle1.m_position.y;
- //var distSqr = goog.math.Vec2.dot(d, d);
- var distSqr = dX * dX + dY * dY;
- var radiusSum = circle1.m_radius + circle2.m_radius;
- if (distSqr > radiusSum * radiusSum && conservative == false) {
- return;
- }
-
- var separation;
- if (distSqr < Number.MIN_VALUE) {
- separation = -radiusSum;
- manifold.normal.Set(0.0, 1.0);
- } else {
- var dist = Math.sqrt(distSqr);
- separation = dist - radiusSum;
- var a = 1.0 / dist;
- manifold.normal.x = a * dX;
- manifold.normal.y = a * dY;
- }
-
- manifold.pointCount = 1;
- var tPoint = manifold.points[0];
- tPoint.id.set_key(0);
- tPoint.separation = separation;
- //tPoint.position = box2d.Vec2.subtract(circle2.m_position, box2d.Vec2.multiplyScalar(circle2.m_radius, manifold.normal));
- tPoint.position.x = circle2.m_position.x - (circle2.m_radius * manifold.normal.x);
- tPoint.position.y = circle2.m_position.y - (circle2.m_radius * manifold.normal.y);
-};
-box2d.Collision.b2CollidePolyAndCircle = function(manifold, poly, circle, conservative) {
- manifold.pointCount = 0;
- var tPoint;
-
- var dX;
- var dY;
-
- // Compute circle position in the frame of the polygon.
- //var xLocal = box2d.Math.b2MulTMV(poly.m_R, box2d.Vec2.subtract(circle.m_position, poly.m_position));
- var xLocalX = circle.m_position.x - poly.m_position.x;
- var xLocalY = circle.m_position.y - poly.m_position.y;
- var tMat = poly.m_R;
- var tX = xLocalX * tMat.col1.x + xLocalY * tMat.col1.y;
- xLocalY = xLocalX * tMat.col2.x + xLocalY * tMat.col2.y;
- xLocalX = tX;
-
- var dist;
-
- // Find the min separating edge.
- var normalIndex = 0;
- var separation = -Number.MAX_VALUE;
- var radius = circle.m_radius;
- for (var i = 0; i < poly.m_vertexCount; ++i) {
- //var s = goog.math.Vec2.dot(poly.m_normals[i], box2d.Vec2.subtract(xLocal, poly.m_vertices[i]));
- var s = poly.m_normals[i].x * (xLocalX - poly.m_vertices[i].x) + poly.m_normals[i].y * (xLocalY - poly.m_vertices[i].y);
- if (s > radius) {
- // Early out.
- return;
- }
-
- if (s > separation) {
- separation = s;
- normalIndex = i;
- }
- }
-
- // If the center is inside the polygon ...
- if (separation < Number.MIN_VALUE) {
- manifold.pointCount = 1;
- //manifold.normal = box2d.Math.b2MulMV(poly.m_R, poly.m_normals[normalIndex]);
- var tVec = poly.m_normals[normalIndex];
- manifold.normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
- manifold.normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
-
- tPoint = manifold.points[0];
- tPoint.id.features.incidentEdge = normalIndex;
- tPoint.id.features.incidentVertex = box2d.Collision.b2_nullFeature;
- tPoint.id.features.referenceFace = box2d.Collision.b2_nullFeature;
- tPoint.id.features.flip = 0;
- tPoint.position.x = circle.m_position.x - radius * manifold.normal.x;
- tPoint.position.y = circle.m_position.y - radius * manifold.normal.y;
- //tPoint.position = box2d.Vec2.subtract(circle.m_position , box2d.Vec2.multiplyScalar(radius , manifold.normal));
- tPoint.separation = separation - radius;
- return;
- }
-
- // Project the circle center onto the edge segment.
- var vertIndex1 = normalIndex;
- var vertIndex2 = vertIndex1 + 1 < poly.m_vertexCount ? vertIndex1 + 1 : 0;
- //var e = box2d.Vec2.subtract(poly.m_vertices[vertIndex2] , poly.m_vertices[vertIndex1]);
- var eX = poly.m_vertices[vertIndex2].x - poly.m_vertices[vertIndex1].x;
- var eY = poly.m_vertices[vertIndex2].y - poly.m_vertices[vertIndex1].y;
- //var length = e.Normalize();
- var length = Math.sqrt(eX * eX + eY * eY);
- eX /= length;
- eY /= length;
-
- // If the edge length is zero ...
- if (length < Number.MIN_VALUE) {
- //d = box2d.Vec2.subtract(xLocal , poly.m_vertices[vertIndex1]);
- dX = xLocalX - poly.m_vertices[vertIndex1].x;
- dY = xLocalY - poly.m_vertices[vertIndex1].y;
- //dist = d.Normalize();
- dist = Math.sqrt(dX * dX + dY * dY);
- dX /= dist;
- dY /= dist;
- if (dist > radius) {
- return;
- }
-
- manifold.pointCount = 1;
- //manifold.normal = box2d.Math.b2MulMV(poly.m_R, d);
- manifold.normal.Set(tMat.col1.x * dX + tMat.col2.x * dY, tMat.col1.y * dX + tMat.col2.y * dY);
- tPoint = manifold.points[0];
- tPoint.id.features.incidentEdge = box2d.Collision.b2_nullFeature;
- tPoint.id.features.incidentVertex = vertIndex1;
- tPoint.id.features.referenceFace = box2d.Collision.b2_nullFeature;
- tPoint.id.features.flip = 0;
- //tPoint.position = box2d.Vec2.subtract(circle.m_position , box2d.Vec2.multiplyScalar(radius , manifold.normal));
- tPoint.position.x = circle.m_position.x - radius * manifold.normal.x;
- tPoint.position.y = circle.m_position.y - radius * manifold.normal.y;
- tPoint.separation = dist - radius;
- return;
- }
-
- // Project the center onto the edge.
- //var u = goog.math.Vec2.dot(box2d.Vec2.subtract(xLocal , poly.m_vertices[vertIndex1]) , e);
- var u = (xLocalX - poly.m_vertices[vertIndex1].x) * eX + (xLocalY - poly.m_vertices[vertIndex1].y) * eY;
-
- tPoint = manifold.points[0];
- tPoint.id.features.incidentEdge = box2d.Collision.b2_nullFeature;
- tPoint.id.features.incidentVertex = box2d.Collision.b2_nullFeature;
- tPoint.id.features.referenceFace = box2d.Collision.b2_nullFeature;
- tPoint.id.features.flip = 0;
-
- var pX, pY;
- if (u <= 0.0) {
- pX = poly.m_vertices[vertIndex1].x;
- pY = poly.m_vertices[vertIndex1].y;
- tPoint.id.features.incidentVertex = vertIndex1;
- } else if (u >= length) {
- pX = poly.m_vertices[vertIndex2].x;
- pY = poly.m_vertices[vertIndex2].y;
- tPoint.id.features.incidentVertex = vertIndex2;
- } else {
- //p = box2d.Vec2.add(poly.m_vertices[vertIndex1] , box2d.Vec2.multiplyScalar(u, e));
- pX = eX * u + poly.m_vertices[vertIndex1].x;
- pY = eY * u + poly.m_vertices[vertIndex1].y;
- tPoint.id.features.incidentEdge = vertIndex1;
- }
-
- //d = box2d.Vec2.subtract(xLocal , p);
- dX = xLocalX - pX;
- dY = xLocalY - pY;
- //dist = d.Normalize();
- dist = Math.sqrt(dX * dX + dY * dY);
- dX /= dist;
- dY /= dist;
- if (dist > radius) {
- return;
- }
-
- manifold.pointCount = 1;
- //manifold.normal = box2d.Math.b2MulMV(poly.m_R, d);
- manifold.normal.Set(tMat.col1.x * dX + tMat.col2.x * dY, tMat.col1.y * dX + tMat.col2.y * dY);
- //tPoint.position = box2d.Vec2.subtract(circle.m_position , box2d.Vec2.multiplyScalar(radius , manifold.normal));
- tPoint.position.x = circle.m_position.x - radius * manifold.normal.x;
- tPoint.position.y = circle.m_position.y - radius * manifold.normal.y;
- tPoint.separation = dist - radius;
-};
-box2d.Collision.b2TestOverlap = function(a, b) {
- var t1 = b.minVertex;
- var t2 = a.maxVertex;
- //d1 = box2d.Vec2.subtract(b.minVertex, a.maxVertex);
- var d1X = t1.x - t2.x;
- var d1Y = t1.y - t2.y;
- //d2 = box2d.Vec2.subtract(a.minVertex, b.maxVertex);
- t1 = a.minVertex;
- t2 = b.maxVertex;
- var d2X = t1.x - t2.x;
- var d2Y = t1.y - t2.y;
-
- if (d1X > 0.0 || d1Y > 0.0) return false;
-
- if (d2X > 0.0 || d2Y > 0.0) return false;
-
- return true;
-};
View
49 collision/b2ContactID.js
@@ -1,49 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.ContactID');
-
-goog.require('box2d.Features');
-
-// We use contact ids to facilitate warm starting.
-/**
- @constructor
- */
-box2d.ContactID = function() {
- this._key = 0;
- this.features = new box2d.Features(this);
-};
-
-box2d.ContactID.prototype.Set = function(id) {
- this.set_key(id._key);
-};
-box2d.ContactID.prototype.Copy = function() {
- var id = new box2d.ContactID();
- id.set_key(this._key);
- return id;
-};
-box2d.ContactID.prototype.get_key = function() {
- return this._key;
-};
-box2d.ContactID.prototype.set_key = function(value) {
- this._key = value;
- this.features._referenceFace = this._key & 0x000000ff;
- this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
- this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
- this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
-};
View
36 collision/b2ContactPoint.js
@@ -1,36 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.ContactPoint');
-
-goog.require('box2d.ContactID');
-goog.require('box2d.Vec2');
-
-// We use contact ids to facilitate warm starting.
-/**
- @constructor
- */
-box2d.ContactPoint = function() {
- // initialize instance variables for references
- this.position = new box2d.Vec2();
- this.id = new box2d.ContactID();
-
- this.separation = null;
- this.normalImpulse = null;
- this.tangentImpulse = null;
-};
View
294 collision/b2Distance.js
@@ -1,294 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.Distance');
-
-goog.require('box2d.Math');
-
-box2d.Distance.ProcessTwo = function(p1Out, p2Out, p1s, p2s, points) {
- // If in point[1] region
- //box2d.Vec2 r = -points[1];
- var rX = -points[1].x;
- var rY = -points[1].y;
- //box2d.Vec2 d = points[1] - points[0];
- var dX = points[0].x - points[1].x;
- var dY = points[0].y - points[1].y;
- //float32 length = d.Normalize();
- var length = Math.sqrt(dX * dX + dY * dY);
- dX /= length;
- dY /= length;
-
- //float32 lambda = b2Dot(r, d);
- var lambda = rX * dX + rY * dY;
- if (lambda <= 0.0 || length < Number.MIN_VALUE) {
- // The simplex is reduced to a point.
- //*p1Out = p1s[1];
- p1Out.SetV(p1s[1]);
- //*p2Out = p2s[1];
- p2Out.SetV(p2s[1]);
- //p1s[0] = p1s[1];
- p1s[0].SetV(p1s[1]);
- //p2s[0] = p2s[1];
- p2s[0].SetV(p2s[1]);
- points[0].SetV(points[1]);
- return 1;
- }
-
- // Else in edge region
- lambda /= length;
- //*p1Out = p1s[1] + lambda * (p1s[0] - p1s[1]);
- p1Out.x = p1s[1].x + lambda * (p1s[0].x - p1s[1].x);
- p1Out.y = p1s[1].y + lambda * (p1s[0].y - p1s[1].y);
- //*p2Out = p2s[1] + lambda * (p2s[0] - p2s[1]);
- p2Out.x = p2s[1].x + lambda * (p2s[0].x - p2s[1].x);
- p2Out.y = p2s[1].y + lambda * (p2s[0].y - p2s[1].y);
- return 2;
-};
-box2d.Distance.ProcessThree = function(p1Out, p2Out, p1s, p2s, points) {
- //box2d.Vec2 a = points[0];
- var aX = points[0].x;
- var aY = points[0].y;
- //box2d.Vec2 b = points[1];
- var bX = points[1].x;
- var bY = points[1].y;
- //box2d.Vec2 c = points[2];
- var cX = points[2].x;
- var cY = points[2].y;
-
- //box2d.Vec2 ab = b - a;
- var abX = bX - aX;
- var abY = bY - aY;
- //box2d.Vec2 ac = c - a;
- var acX = cX - aX;
- var acY = cY - aY;
- //box2d.Vec2 bc = c - b;
- var bcX = cX - bX;
- var bcY = cY - bY;
-
- //float32 sn = -b2Dot(a, ab), sd = b2Dot(b, ab);
- var sn = -(aX * abX + aY * abY);
- var sd = (bX * abX + bY * abY);
- //float32 tn = -b2Dot(a, ac), td = b2Dot(c, ac);
- var tn = -(aX * acX + aY * acY);
- var td = (cX * acX + cY * acY);
- //float32 un = -b2Dot(b, bc), ud = b2Dot(c, bc);
- var un = -(bX * bcX + bY * bcY);
- var ud = (cX * bcX + cY * bcY);
-
- // In vertex c region?
- if (td <= 0.0 && ud <= 0.0) {
- // Single point
- //*p1Out = p1s[2];
- p1Out.SetV(p1s[2]);
- //*p2Out = p2s[2];
- p2Out.SetV(p2s[2]);
- //p1s[0] = p1s[2];
- p1s[0].SetV(p1s[2]);
- //p2s[0] = p2s[2];
- p2s[0].SetV(p2s[2]);
- points[0].SetV(points[2]);
- return 1;
- }
-
- // Should not be in vertex a or b region.
- //box2d.Settings.b2Assert(sn > 0.0 || tn > 0.0);
- //box2d.Settings.b2Assert(sd > 0.0 || un > 0.0);
- //float32 n = b2Cross(ab, ac);
- var n = abX * acY - abY * acX;
-
- // Should not be in edge ab region.
- //float32 vc = n * b2Cross(a, b);
- var vc = n * (aX * bY - aY * bX);
- //box2d.Settings.b2Assert(vc > 0.0 || sn > 0.0 || sd > 0.0);
- // In edge bc region?
- //float32 va = n * b2Cross(b, c);
- var va = n * (bX * cY - bY * cX);
- var lambda;
- if (va <= 0.0 && un >= 0.0 && ud >= 0.0) {
- //box2d.Settings.b2Assert(un + ud > 0.0);
- //float32 lambda = un / (un + ud);
- lambda = un / (un + ud);
- //*p1Out = p1s[1] + lambda * (p1s[2] - p1s[1]);
- p1Out.x = p1s[1].x + lambda * (p1s[2].x - p1s[1].x);
- p1Out.y = p1s[1].y + lambda * (p1s[2].y - p1s[1].y);
- //*p2Out = p2s[1] + lambda * (p2s[2] - p2s[1]);
- p2Out.x = p2s[1].x + lambda * (p2s[2].x - p2s[1].x);
- p2Out.y = p2s[1].y + lambda * (p2s[2].y - p2s[1].y);
- //p1s[0] = p1s[2];
- p1s[0].SetV(p1s[2]);
- //p2s[0] = p2s[2];
- p2s[0].SetV(p2s[2]);
- //points[0] = points[2];
- points[0].SetV(points[2]);
- return 2;
- }
-
- // In edge ac region?
- //float32 vb = n * b2Cross(c, a);
- var vb = n * (cX * aY - cY * aX);
- if (vb <= 0.0 && tn >= 0.0 && td >= 0.0) {
- //box2d.Settings.b2Assert(tn + td > 0.0);
- //float32 lambda = tn / (tn + td);
- lambda = tn / (tn + td);
- //*p1Out = p1s[0] + lambda * (p1s[2] - p1s[0]);
- p1Out.x = p1s[0].x + lambda * (p1s[2].x - p1s[0].x);
- p1Out.y = p1s[0].y + lambda * (p1s[2].y - p1s[0].y);
- //*p2Out = p2s[0] + lambda * (p2s[2] - p2s[0]);
- p2Out.x = p2s[0].x + lambda * (p2s[2].x - p2s[0].x);
- p2Out.y = p2s[0].y + lambda * (p2s[2].y - p2s[0].y);
- //p1s[1] = p1s[2];
- p1s[1].SetV(p1s[2]);
- //p2s[1] = p2s[2];
- p2s[1].SetV(p2s[2]);
- //points[1] = points[2];
- points[1].SetV(points[2]);
- return 2;
- }
-
- // Inside the triangle, compute barycentric coordinates
- //float32 denom = va + vb + vc;
- var denom = va + vb + vc;
- //box2d.Settings.b2Assert(denom > 0.0);
- denom = 1.0 / denom;
- //float32 u = va * denom;
- var u = va * denom;
- //float32 v = vb * denom;
- var v = vb * denom;
- //float32 w = 1.0f - u - v;
- var w = 1.0 - u - v;
- //*p1Out = u * p1s[0] + v * p1s[1] + w * p1s[2];
- p1Out.x = u * p1s[0].x + v * p1s[1].x + w * p1s[2].x;
- p1Out.y = u * p1s[0].y + v * p1s[1].y + w * p1s[2].y;
- //*p2Out = u * p2s[0] + v * p2s[1] + w * p2s[2];
- p2Out.x = u * p2s[0].x + v * p2s[1].x + w * p2s[2].x;
- p2Out.y = u * p2s[0].y + v * p2s[1].y + w * p2s[2].y;
- return 3;
-};
-box2d.Distance.InPoinsts = function(w, points, pointCount) {
- for (var i = 0; i < pointCount; ++i) {
- if (w.x == points[i].x && w.y == points[i].y) {
- return true;
- }
- }
-
- return false;
-};
-box2d.Distance.Distance = function(p1Out, p2Out, shape1, shape2) {
- //box2d.Vec2 p1s[3], p2s[3];
- var p1s = new Array(3);
- var p2s = new Array(3);
- //box2d.Vec2 points[3];
- var points = new Array(3);
- //int32 pointCount = 0;
- var pointCount = 0;
-
- //*p1Out = shape1->m_position;
- p1Out.SetV(shape1.m_position);
- //*p2Out = shape2->m_position;
- p2Out.SetV(shape2.m_position);
-
- var vSqr = 0.0;
- var maxIterations = 20;
- for (var iter = 0; iter < maxIterations; ++iter) {
- //box2d.Vec2 v = *p2Out - *p1Out;
- var vX = p2Out.x - p1Out.x;
- var vY = p2Out.y - p1Out.y;
- //box2d.Vec2 w1 = shape1->Support(v);
- var w1 = shape1.Support(vX, vY);
- //box2d.Vec2 w2 = shape2->Support(-v);
- var w2 = shape2.Support(-vX, -vY);
- //float32 vSqr = b2Dot(v, v);
- vSqr = (vX * vX + vY * vY);
- //box2d.Vec2 w = w2 - w1;
- var wX = w2.x - w1.x;
- var wY = w2.y - w1.y;
- //float32 vw = b2Dot(v, w);
- var vw = (vX * wX + vY * wY);
- //if (vSqr - b2Dot(v, w) <= 0.01f * vSqr)
- if (vSqr - (vX * wX + vY * wY) <= 0.01 * vSqr) {
- if (pointCount == 0) {
- //*p1Out = w1;
- p1Out.SetV(w1);
- //*p2Out = w2;
- p2Out.SetV(w2);
- }
- box2d.Distance.g_GJK_Iterations = iter;
- return Math.sqrt(vSqr);
- }
-
- switch (pointCount) {
- case 0:
- //p1s[0] = w1;
- p1s[0].SetV(w1);
- //p2s[0] = w2;
- p2s[0].SetV(w2);
- points[0].x = wX;
- points[0].y = wY;
- //*p1Out = p1s[0];
- p1Out.SetV(p1s[0]);
- //*p2Out = p2s[0];
- p2Out.SetV(p2s[0]);
- ++pointCount;
- break;
-
- case 1:
- //p1s[1] = w1;
- p1s[1].SetV(w1);
- //p2s[1] = w2;
- p2s[1].SetV(w2);
- //points[1] = w;
- points[1].x = wX;
- points[1].y = wY;
- pointCount = box2d.Distance.ProcessTwo(p1Out, p2Out, p1s, p2s, points);
- break;
-
- case 2:
- //p1s[2] = w1;
- p1s[2].SetV(w1);
- //p2s[2] = w2;
- p2s[2].SetV(w2);
- //points[2] = w;
- points[2].x = wX;
- points[2].y = wY;
- pointCount = box2d.Distance.ProcessThree(p1Out, p2Out, p1s, p2s, points);
- break;
- }
-
- // If we have three points, then the origin is in the corresponding triangle.
- if (pointCount == 3) {
- box2d.Distance.g_GJK_Iterations = iter;
- return 0.0;
- }
-
- //float32 maxSqr = -FLT_MAX;
- var maxSqr = -Number.MAX_VALUE;
- for (var i = 0; i < pointCount; ++i) {
- //maxSqr = Math.max(maxSqr, b2Dot(points[i], points[i]));
- maxSqr = Math.max(maxSqr, (points[i].x * points[i].x + points[i].y * points[i].y));
- }
-
- if (pointCount == 3 || vSqr <= 100.0 * Number.MIN_VALUE * maxSqr) {
- box2d.Distance.g_GJK_Iterations = iter;
- return Math.sqrt(vSqr);
- }
- }
-
- box2d.Distance.g_GJK_Iterations = maxIterations;
- return Math.sqrt(vSqr);
-};
-box2d.Distance.g_GJK_Iterations = 0;
View
36 collision/b2Manifold.js
@@ -1,36 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.Manifold');
-
-goog.require('box2d.ContactPoint');
-goog.require('box2d.Settings');
-goog.require('box2d.Vec2');
-
-// A manifold for two touching convex shapes.
-/**
- @constructor
- */
-box2d.Manifold = function() {
- this.pointCount = 0;
- this.points = new Array(box2d.Settings.b2_maxManifoldPoints);
- for (var i = 0; i < box2d.Settings.b2_maxManifoldPoints; i++) {
- this.points[i] = new box2d.ContactPoint();
- }
- this.normal = new box2d.Vec2();
-};
View
33 collision/b2OBB.js
@@ -1,33 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.OBB');
-goog.require('box2d.Mat22');
-goog.require('box2d.Vec2');
-
-// A manifold for two touching convex shapes.
-/**
- @constructor
- */
-box2d.OBB = function() {
- // initialize instance variables for references
- this.R = new box2d.Mat22();
- this.center = new box2d.Vec2();
- this.extents = new box2d.Vec2();
- //
-};
View
86 collision/b2Pair.js
@@ -1,86 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.Pair');
-
-goog.require('box2d.Settings');
-
-// The pair manager is used by the broad-phase to quickly add/remove/find pairs
-// of overlapping proxies. It is based closely on code provided by Pierre Terdiman.
-// http:
-/**
- @constructor
- */
-box2d.Pair = function() {};
-box2d.Pair.prototype = {
-
- SetBuffered: function() {
- this.status |= box2d.Pair.Flags.pairBuffered;
- },
- ClearBuffered: function() {
- this.status &= ~box2d.Pair.Flags.pairBuffered;
- },
- IsBuffered: function() {
- return (this.status & box2d.Pair.Flags.pairBuffered) == box2d.Pair.Flags.pairBuffered;
- },
-
- SetRemoved: function() {
- this.status |= box2d.Pair.Flags.pairRemoved;
- },
- ClearRemoved: function() {
- this.status &= ~box2d.Pair.Flags.pairRemoved;
- },
- IsRemoved: function() {
- return (this.status & box2d.Pair.Flags.pairRemoved) == box2d.Pair.Flags.pairRemoved;
- },
-
- SetFinal: function() {
- this.status |= box2d.Pair.Flags.pairFinal;
- },
- IsFinal: function() {
- return (this.status & box2d.Pair.Flags.pairFinal) == box2d.Pair.Flags.pairFinal;
- },
-
- proxyId1: 0,
- proxyId2: 0,
- next: 0,
- status: 0
-};
-
-/**
- @type {box2d.Contact}
-*/
-box2d.Pair.prototype.contactData = null;
-
-/** @const @type {number} */
-box2d.Pair.b2_nullPair = box2d.Settings.USHRT_MAX;
-/** @const @type {number} */
-box2d.Pair.b2_nullProxy = box2d.Settings.USHRT_MAX;
-/** @const @type {number} */
-box2d.Pair.b2_tableCapacity = box2d.Settings.b2_maxPairs;
-/** @const @type {number} */
-box2d.Pair.b2_tableMask = box2d.Pair.b2_tableCapacity - 1;
-
-/**
- @enum {number}
- */
-box2d.Pair.Flags = {
- pairBuffered: 0x0001,
- pairRemoved: 0x0002,
- pairFinal: 0x0004
-};
View
33 collision/b2PairCallback.js
@@ -1,33 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http:
-*
-* This software is provided 'as-is', without any express or implied
-* warranty. In no event will the authors be held liable for any damages
-* arising from the use of this software.
-* Permission is granted to anyone to use this software for any purpose,
-* including commercial applications, and to alter it and redistribute it
-* freely, subject to the following restrictions:
-* 1. The origin of this software must not be misrepresented; you must not
-* claim that you wrote the original software. If you use this software
-* in a product, an acknowledgment in the product documentation would be
-* appreciated but is not required.
-* 2. Altered source versions must be plainly marked, and must not be
-* misrepresented the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-goog.provide('box2d.PairCallback');
-
-/**
- @constructor
- */
-box2d.PairCallback = function() {};
-
-// This returns the new pair user data.
-box2d.PairCallback.prototype.