Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

git-svn-id: http://hotruby.googlecode.com/svn/trunk@26 4fb8041d-b042-…

…0410-9571-f50be27af959
  • Loading branch information...
commit b7b93737c43c9bdef57a4a28719510e566b83bc8 1 parent b9e5afa
yukoba@accelart.jp authored
Showing with 4,920 additions and 13,297 deletions.
  1. +0 −33 test/Box2DFlashAS3/Box2D/Collision/ClipVertex.as
  2. +0 −64 test/Box2DFlashAS3/Box2D/Collision/Features.as
  3. +0 −39 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2BoxDef.as
  4. +0 −39 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2CircleDef.as
  5. +0 −180 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2CircleShape.as
  6. +0 −34 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2MassData.as
  7. +0 −45 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2PolyDef.as
  8. +0 −471 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2PolyShape.as
  9. +0 −340 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2Shape.as
  10. +0 −115 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2ShapeDef.as
  11. +0 −45 test/Box2DFlashAS3/Box2D/Collision/b2AABB.as
  12. +0 −45 test/Box2DFlashAS3/Box2D/Collision/b2Bound.as
  13. +0 −28 test/Box2DFlashAS3/Box2D/Collision/b2BoundValues.as
  14. +0 −901 test/Box2DFlashAS3/Box2D/Collision/b2BroadPhase.as
  15. +0 −28 test/Box2DFlashAS3/Box2D/Collision/b2BufferedPair.as
  16. +0 −743 test/Box2DFlashAS3/Box2D/Collision/b2Collision.as
  17. +0 −53 test/Box2DFlashAS3/Box2D/Collision/b2ContactID.as
  18. +0 −35 test/Box2DFlashAS3/Box2D/Collision/b2ContactPoint.as
  19. +0 −339 test/Box2DFlashAS3/Box2D/Collision/b2Distance.as
  20. +0 −41 test/Box2DFlashAS3/Box2D/Collision/b2Manifold.as
  21. +0 −32 test/Box2DFlashAS3/Box2D/Collision/b2OBB.as
  22. +0 −64 test/Box2DFlashAS3/Box2D/Collision/b2Pair.as
  23. +0 −35 test/Box2DFlashAS3/Box2D/Collision/b2PairCallback.as
  24. +0 −391 test/Box2DFlashAS3/Box2D/Collision/b2PairManager.as
  25. +0 −37 test/Box2DFlashAS3/Box2D/Collision/b2Proxy.as
  26. +0 −128 test/Box2DFlashAS3/Box2D/Common/Math/b2Mat22.as
  27. +0 −220 test/Box2DFlashAS3/Box2D/Common/Math/b2Math.as
  28. +0 −135 test/Box2DFlashAS3/Box2D/Common/Math/b2Vec2.as
  29. +0 −74 test/Box2DFlashAS3/Box2D/Common/b2Settings.as
  30. +0 −69 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2CircleContact.as
  31. +0 −234 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2Conservative.as
  32. +0 −207 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2Contact.as
  33. +0 −49 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2ContactConstraint.as
  34. +0 −39 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2ContactConstraintPoint.as
  35. +0 −36 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2ContactNode.as
  36. +0 −31 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2ContactRegister.as
  37. +0 −541 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2ContactSolver.as
  38. +0 −32 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2NullContact.as
  39. +0 −71 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2PolyAndCircleContact.as
  40. +0 −129 test/Box2DFlashAS3/Box2D/Dynamics/Contacts/b2PolyContact.as
  41. +0 −247 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2DistanceJoint.as
  42. +0 −39 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2DistanceJointDef.as
  43. +0 −289 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2GearJoint.as
  44. +0 −52 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2GearJointDef.as
  45. +0 −48 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2Jacobian.as
  46. +0 −202 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2Joint.as
  47. +0 −46 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2JointDef.as
  48. +0 −36 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2JointNode.as
  49. +0 −212 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2MouseJoint.as
  50. +0 −43 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2MouseJointDef.as
  51. +0 −656 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2PrismaticJoint.as
  52. +0 −50 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2PrismaticJointDef.as
  53. +0 −596 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2PulleyJoint.as
  54. +0 −57 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2PulleyJointDef.as
  55. +0 −469 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2RevoluteJoint.as
  56. +0 −49 test/Box2DFlashAS3/Box2D/Dynamics/Joints/b2RevoluteJointDef.as
  57. +0 −474 test/Box2DFlashAS3/Box2D/Dynamics/b2Body.as
  58. +0 −76 test/Box2DFlashAS3/Box2D/Dynamics/b2BodyDef.as
  59. +0 −46 test/Box2DFlashAS3/Box2D/Dynamics/b2CollisionFilter.as
  60. +0 −338 test/Box2DFlashAS3/Box2D/Dynamics/b2ContactManager.as
  61. +0 −338 test/Box2DFlashAS3/Box2D/Dynamics/b2Island.as
  62. +0 −30 test/Box2DFlashAS3/Box2D/Dynamics/b2TimeStep.as
  63. +0 −530 test/Box2DFlashAS3/Box2D/Dynamics/b2World.as
  64. +0 −55 test/Box2DFlashAS3/Box2D/Dynamics/b2WorldListener.as
  65. +0 −49 test/Box2DFlashAS3/General/FRateLimiter.as
  66. +0 −131 test/Box2DFlashAS3/General/FpsCounter.as
  67. +0 −352 test/Box2DFlashAS3/General/Input.as
  68. +0 −379 test/Box2DFlashAS3/TestBed/Test.as
  69. +0 −156 test/Box2DFlashAS3/TestBed/TestBridge.as
  70. +0 −135 test/Box2DFlashAS3/TestBed/TestCompound.as
  71. +0 −118 test/Box2DFlashAS3/TestBed/TestCrank.as
  72. +0 −268 test/Box2DFlashAS3/TestBed/TestExample.as
  73. +0 −123 test/Box2DFlashAS3/TestBed/TestGears.as
  74. +0 −110 test/Box2DFlashAS3/TestBed/TestPulley.as
  75. +0 −252 test/Box2DFlashAS3/TestBed/TestRagdoll.as
  76. +0 −74 test/Box2DFlashAS3/TestBed/TestStack.as
  77. BIN  test/pinball/Box2DFlashAS3.swc
  78. +13 −0 test/pinball/HotRubyFlash-config.xml
  79. +1 −0  test/pinball/ImportAS.as
  80. +17 −0 test/pinball/LicenseOfBox2DFlashAS3.txt
  81. +9 −0 test/pinball/build.bat
  82. +9 −0 test/pinball/buildDebug.bat
  83. +1 −0  test/pinball/pinball.js
  84. +221 −0 test/pinball/pinball.rb
  85. +4,649 −0 test/pinball/pinball_pretty.json
View
33 test/Box2DFlashAS3/Box2D/Collision/ClipVertex.as
@@ -1,33 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision{
-
-
-import Box2D.Common.Math.*
-import Box2D.Collision.*
-
-
-public class ClipVertex
-{
- public var v:b2Vec2 = new b2Vec2();
- public var id:b2ContactID = new b2ContactID();
-};
-
-
-}
View
64 test/Box2DFlashAS3/Box2D/Collision/Features.as
@@ -1,64 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision{
-
-// We use contact ids to facilitate warm starting.
-public class Features
-{
- //
- public function set referenceFace(value:int) : void{
- _referenceFace = value;
- _m_id._key = (_m_id._key & 0xffffff00) | (_referenceFace & 0x000000ff)
- }
- public function get referenceFace():int{
- return _referenceFace;
- }
- public var _referenceFace:int;
- //
- public function set incidentEdge(value:int) : void{
- _incidentEdge = value;
- _m_id._key = (_m_id._key & 0xffff00ff) | ((_incidentEdge << 8) & 0x0000ff00)
- }
- public function get incidentEdge():int{
- return _incidentEdge;
- }
- public var _incidentEdge:int;
- //
- public function set incidentVertex(value:int) : void{
- _incidentVertex = value;
- _m_id._key = (_m_id._key & 0xff00ffff) | ((_incidentVertex << 16) & 0x00ff0000)
- }
- public function get incidentVertex():int{
- return _incidentVertex;
- }
- public var _incidentVertex:int;
- //
- public function set flip(value:int) : void{
- _flip = value;
- _m_id._key = (_m_id._key & 0x00ffffff) | ((_flip << 24) & 0xff000000)
- }
- public function get flip():int{
- return _flip;
- }
- public var _flip:int;
- public var _m_id:b2ContactID;
-};
-
-
-}
View
39 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2BoxDef.as
@@ -1,39 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Collision.Shapes.*;
-
-
-
-public class b2BoxDef extends b2ShapeDef
-{
- public function b2BoxDef()
- {
- type = b2Shape.e_boxShape;
- extents = new b2Vec2(1.0, 1.0);
- }
-
- public var extents:b2Vec2;
-};
-
-}
View
39 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2CircleDef.as
@@ -1,39 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Collision.Shapes.*;
-
-
-
-public class b2CircleDef extends b2ShapeDef
-{
- public function b2CircleDef()
- {
- type = b2Shape.e_circleShape;
- radius = 1.0;
- }
-
- public var radius:Number;
-};
-
-}
View
180 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2CircleShape.as
@@ -1,180 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Common.*
-import Box2D.Collision.Shapes.*;
-import Box2D.Dynamics.*
-import Box2D.Collision.*
-
-
-
-public class b2CircleShape extends b2Shape
-{
- public override function TestPoint(p:b2Vec2):Boolean{
- //var d:b2Vec2 = b2Math.SubtractVV(p, m_position);
- var d:b2Vec2 = new b2Vec2();
- d.SetV(p);
- d.Subtract(m_position);
- return b2Math.b2Dot(d, d) <= m_radius * m_radius;
- }
-
- //--------------- Internals Below -------------------
-
- public function b2CircleShape(def:b2ShapeDef, body:b2Body, localCenter:b2Vec2){
- super(def, body);
-
- //b2Settings.b2Assert(def.type == b2Shape.e_circleShape);
- var circle:b2CircleDef = def as b2CircleDef;
-
- //m_localPosition = def.localPosition - localCenter;
- m_localPosition.Set(def.localPosition.x - localCenter.x, def.localPosition.y - localCenter.y);
- m_type = b2Shape.e_circleShape;
- m_radius = circle.radius;
-
- m_R.SetM(m_body.m_R);
- //b2Vec2 r = b2Mul(m_body->m_R, m_localPosition);
- var rX:Number = m_R.col1.x * m_localPosition.x + m_R.col2.x * m_localPosition.y;
- var rY:Number = m_R.col1.y * m_localPosition.x + m_R.col2.y * m_localPosition.y;
- //m_position = m_body->m_position + r;
- m_position.x = m_body.m_position.x + rX;
- m_position.y = m_body.m_position.y + rY;
- //m_maxRadius = r.Length() + m_radius;
- m_maxRadius = Math.sqrt(rX*rX+rY*rY) + m_radius;
-
- var aabb:b2AABB = new b2AABB();
- aabb.minVertex.Set(m_position.x - m_radius, m_position.y - m_radius);
- aabb.maxVertex.Set(m_position.x + m_radius, m_position.y + m_radius);
-
- var broadPhase:b2BroadPhase = m_body.m_world.m_broadPhase;
- if (broadPhase.InRange(aabb))
- {
- m_proxyId = broadPhase.CreateProxy(aabb, this);
- }
- else
- {
- m_proxyId = b2Pair.b2_nullProxy;
- }
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- m_body.Freeze();
- }
- }
-
- public override function Synchronize(position1:b2Vec2, R1:b2Mat22,
- position2:b2Vec2, R2:b2Mat22) : void{
- m_R.SetM(R2);
- //m_position = position2 + b2Mul(R2, m_localPosition);
- m_position.x = (R2.col1.x * m_localPosition.x + R2.col2.x * m_localPosition.y) + position2.x;
- m_position.y = (R2.col1.y * m_localPosition.x + R2.col2.y * m_localPosition.y) + position2.y;
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- return;
- }
-
- // Compute an AABB that covers the swept shape (may miss some rotation effect).
- //b2Vec2 p1 = position1 + b2Mul(R1, m_localPosition);
- var p1X:Number = position1.x + (R1.col1.x * m_localPosition.x + R1.col2.x * m_localPosition.y);
- var p1Y:Number = position1.y + (R1.col1.y * m_localPosition.x + R1.col2.y * m_localPosition.y);
- //b2Vec2 lower = b2Min(p1, m_position);
- var lowerX:Number = Math.min(p1X, m_position.x);
- var lowerY:Number = Math.min(p1Y, m_position.y);
- //b2Vec2 upper = b2Max(p1, m_position);
- var upperX:Number = Math.max(p1X, m_position.x);
- var upperY:Number = Math.max(p1Y, m_position.y);
-
- var aabb:b2AABB = new b2AABB();
- aabb.minVertex.Set(lowerX - m_radius, lowerY - m_radius);
- aabb.maxVertex.Set(upperX + m_radius, upperY + m_radius);
-
- var broadPhase:b2BroadPhase = m_body.m_world.m_broadPhase;
- if (broadPhase.InRange(aabb))
- {
- broadPhase.MoveProxy(m_proxyId, aabb);
- }
- else
- {
- m_body.Freeze();
- }
- }
-
- public override function QuickSync(position:b2Vec2, R:b2Mat22) : void{
- m_R.SetM(R);
- //m_position = position + b2Mul(R, m_localPosition);
- m_position.x = (R.col1.x * m_localPosition.x + R.col2.x * m_localPosition.y) + position.x;
- m_position.y = (R.col1.y * m_localPosition.x + R.col2.y * m_localPosition.y) + position.y;
- }
-
-
- public override function ResetProxy(broadPhase:b2BroadPhase) : void
- {
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- return;
- }
-
- var proxy:b2Proxy = broadPhase.GetProxy(m_proxyId);
-
- broadPhase.DestroyProxy(m_proxyId);
- proxy = null;
-
- var aabb:b2AABB = new b2AABB();
- aabb.minVertex.Set(m_position.x - m_radius, m_position.y - m_radius);
- aabb.maxVertex.Set(m_position.x + m_radius, m_position.y + m_radius);
-
- if (broadPhase.InRange(aabb))
- {
- m_proxyId = broadPhase.CreateProxy(aabb, this);
- }
- else
- {
- m_proxyId = b2Pair.b2_nullProxy;
- }
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- m_body.Freeze();
- }
- }
-
-
- public override function Support(dX:Number, dY:Number, out:b2Vec2): void
- {
- //b2Vec2 u = d;
- //u.Normalize();
- var len:Number = Math.sqrt(dX*dX + dY*dY);
- dX /= len;
- dY /= len;
- //return m_position + m_radius * u;
- out.Set( m_position.x + m_radius*dX,
- m_position.y + m_radius*dY);
- }
-
-
- // Local position in parent body
- public var m_localPosition:b2Vec2 = new b2Vec2();
- public var m_radius:Number;
-};
-
-}
View
34 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2MassData.as
@@ -1,34 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-
-
-
-public class b2MassData
-{
- public var mass:Number = 0.0;
- public var center:b2Vec2 = new b2Vec2(0,0);
- public var I:Number = 0.0;
-}
-
-}
View
45 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2PolyDef.as
@@ -1,45 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Common.*;
-import Box2D.Collision.Shapes.*;
-
-
-
-public class b2PolyDef extends b2ShapeDef
-{
- public function b2PolyDef()
- {
- type = b2Shape.e_polyShape;
- vertexCount = 0;
-
- for (var i:int = 0; i < b2Settings.b2_maxPolyVertices; i++){
- vertices[i] = new b2Vec2();
- }
- }
-
- public var vertices:Array = new Array(b2Settings.b2_maxPolyVertices);
- public var vertexCount:int;
-};
-
-}
View
471 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2PolyShape.as
@@ -1,471 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Common.*
-import Box2D.Collision.Shapes.*;
-import Box2D.Dynamics.*
-import Box2D.Collision.*
-
-// A convex polygon. The position of the polygon (m_position) is the
-// position of the centroid. The vertices of the incoming polygon are pre-rotated
-// according to the local rotation. The vertices are also shifted to be centered
-// on the centroid. Since the local rotation is absorbed into the vertex
-// coordinates, the polygon rotation is equal to the body rotation. However,
-// the polygon position is centered on the polygon centroid. This simplifies
-// some collision algorithms.
-
-public class b2PolyShape extends b2Shape
-{
- public override function TestPoint(p:b2Vec2):Boolean{
-
- //var pLocal:b2Vec2 = b2Math.b2MulTMV(m_R, b2Math.SubtractVV(p, m_position));
- var pLocal:b2Vec2 = new b2Vec2();
- pLocal.SetV(p);
- pLocal.Subtract(m_position);
- pLocal.MulTM(m_R);
-
- for (var i:int = 0; i < m_vertexCount; ++i)
- {
- //var dot:Number = b2Math.b2Dot(m_normals[i], b2Math.SubtractVV(pLocal, m_vertices[i]));
- var tVec:b2Vec2 = new b2Vec2();
- tVec.SetV(pLocal);
- tVec.Subtract(m_vertices[i]);
-
- var dot:Number = b2Math.b2Dot(m_normals[i], tVec);
- if (dot > 0.0)
- {
- return false;
- }
- }
-
- return true;
- }
-
- //--------------- Internals Below -------------------
- // Temp vec for PolyCentroid
- static private var tempVec:b2Vec2 = new b2Vec2();
- static private var tAbsR:b2Mat22 = new b2Mat22()
-
- public function b2PolyShape(def:b2ShapeDef, body:b2Body, newOrigin:b2Vec2){
-
- super(def, body);
-
- var i:int;
-
-
- var hX:Number;
- var hY:Number;
-
- var tVec:b2Vec2;
-
- var aabb:b2AABB = new b2AABB();
-
- // Vertices
- m_vertices = new Array(b2Settings.b2_maxPolyVertices);
- m_coreVertices = new Array(b2Settings.b2_maxPolyVertices);
- //for (i = 0; i < b2Settings.b2_maxPolyVertices; i++)
- // m_vertices[i] = new b2Vec2();
-
- // Normals
- m_normals = new Array(b2Settings.b2_maxPolyVertices);
- //for (i = 0; i < b2Settings.b2_maxPolyVertices; i++)
- // m_normals[i] = new b2Vec2();
-
- //b2Settings.b2Assert(def.type == e_boxShape || def.type == e_polyShape);
- m_type = b2Shape.e_polyShape;
-
- var localR:b2Mat22 = new b2Mat22(def.localRotation);
-
- // Get the vertices transformed into the body frame.
- if (def.type == b2Shape.e_boxShape)
- {
- //m_localCentroid = def.localPosition - newOrigin;
- m_localCentroid.x = def.localPosition.x - newOrigin.x;
- m_localCentroid.y = def.localPosition.y - newOrigin.y;
-
- var box:b2BoxDef = def as b2BoxDef;
- m_vertexCount = 4;
- hX = box.extents.x;
- hY = box.extents.y;
-
- //hc.x = b2Max(0.0f, h.x - 2.0f * b2_linearSlop);
- var hcX:Number = Math.max(0.0, hX - 2.0 * b2Settings.b2_linearSlop);
- //hc.y = b2Max(0.0f, h.y - 2.0f * b2_linearSlop);
- var hcY:Number = Math.max(0.0, hY - 2.0 * b2Settings.b2_linearSlop);
-
- //m_vertices[0] = b2Mul(localR, b2Vec2(h.x, h.y));
- tVec = m_vertices[0] = new b2Vec2();
- tVec.x = localR.col1.x * hX + localR.col2.x * hY;
- tVec.y = localR.col1.y * hX + localR.col2.y * hY;
- //m_vertices[1] = b2Mul(localR, b2Vec2(-h.x, h.y));
- tVec = m_vertices[1] = new b2Vec2();
- tVec.x = localR.col1.x * -hX + localR.col2.x * hY;
- tVec.y = localR.col1.y * -hX + localR.col2.y * hY;
- //m_vertices[2] = b2Mul(localR, b2Vec2(-h.x, -h.y));
- tVec = m_vertices[2] = new b2Vec2();
- tVec.x = localR.col1.x * -hX + localR.col2.x * -hY;
- tVec.y = localR.col1.y * -hX + localR.col2.y * -hY;
- //m_vertices[3] = b2Mul(localR, b2Vec2(h.x, -h.y));
- tVec = m_vertices[3] = new b2Vec2();
- tVec.x = localR.col1.x * hX + localR.col2.x * -hY;
- tVec.y = localR.col1.y * hX + localR.col2.y * -hY;
-
- //m_coreVertices[0] = b2Mul(localR, b2Vec2(hc.x, hc.y));
- tVec = m_coreVertices[0] = new b2Vec2();
- tVec.x = localR.col1.x * hcX + localR.col2.x * hcY;
- tVec.y = localR.col1.y * hcX + localR.col2.y * hcY;
- //m_coreVertices[1] = b2Mul(localR, b2Vec2(-hc.x, hc.y));
- tVec = m_coreVertices[1] = new b2Vec2();
- tVec.x = localR.col1.x * -hcX + localR.col2.x * hcY;
- tVec.y = localR.col1.y * -hcX + localR.col2.y * hcY;
- //m_coreVertices[2] = b2Mul(localR, b2Vec2(-hc.x, -hc.y));
- tVec = m_coreVertices[2] = new b2Vec2();
- tVec.x = localR.col1.x * -hcX + localR.col2.x * -hcY;
- tVec.y = localR.col1.y * -hcX + localR.col2.y * -hcY;
- //m_coreVertices[3] = b2Mul(localR, b2Vec2(hc.x, -hc.y));
- tVec = m_coreVertices[3] = new b2Vec2();
- tVec.x = localR.col1.x * hcX + localR.col2.x * -hcY;
- tVec.y = localR.col1.y * hcX + localR.col2.y * -hcY;
- }
- else
- {
- var poly:b2PolyDef = def as b2PolyDef;
-
- m_vertexCount = poly.vertexCount;
- //b2Settings.b2Assert(3 <= m_vertexCount && m_vertexCount <= b2Settings.b2_maxPolyVertices);
- //b2Vec2 centroid = PolyCentroid(poly->vertices, poly->vertexCount);
- PolyCentroid(poly.vertices, poly.vertexCount, tempVec);
- var centroidX:Number = tempVec.x;
- var centroidY:Number = tempVec.y;
- //m_localCentroid = def->localPosition + b2Mul(localR, centroid) - newOrigin;
- m_localCentroid.x = def.localPosition.x + (localR.col1.x * centroidX + localR.col2.x * centroidY) - newOrigin.x;
- m_localCentroid.y = def.localPosition.y + (localR.col1.y * centroidX + localR.col2.y * centroidY) - newOrigin.y;
-
- for (i = 0; i < m_vertexCount; ++i)
- {
- m_vertices[i] = new b2Vec2();
- m_coreVertices[i] = new b2Vec2();
-
- //m_vertices[i] = b2Mul(localR, poly->vertices[i] - centroid);
- hX = poly.vertices[i].x - centroidX;
- hY = poly.vertices[i].y - centroidY;
- m_vertices[i].x = localR.col1.x * hX + localR.col2.x * hY;
- m_vertices[i].y = localR.col1.y * hX + localR.col2.y * hY;
-
- //b2Vec2 u = m_vertices[i];
- var uX:Number = m_vertices[i].x;
- var uY:Number = m_vertices[i].y;
- //float32 length = u.Length();
- var length:Number = Math.sqrt(uX*uX + uY*uY);
- if (length > Number.MIN_VALUE)
- {
- uX *= 1.0 / length;
- uY *= 1.0 / length;
- }
-
- //m_coreVertices[i] = m_vertices[i] - 2.0f * b2_linearSlop * u;
- m_coreVertices[i].x = m_vertices[i].x - 2.0 * b2Settings.b2_linearSlop * uX;
- m_coreVertices[i].y = m_vertices[i].y - 2.0 * b2Settings.b2_linearSlop * uY;
- }
-
- }
-
- // Compute bounding box. TODO_ERIN optimize OBB
- //var minVertex:b2Vec2 = new b2Vec2(Number.MAX_VALUE, Number.MAX_VALUE);
- var minVertexX:Number = Number.MAX_VALUE;
- var minVertexY:Number = Number.MAX_VALUE;
- var maxVertexX:Number = -Number.MAX_VALUE;
- var maxVertexY:Number = -Number.MAX_VALUE;
- m_maxRadius = 0.0;
- for (i = 0; i < m_vertexCount; ++i)
- {
- var v:b2Vec2 = m_vertices[i];
- //minVertex = b2Math.b2MinV(minVertex, m_vertices[i]);
- minVertexX = Math.min(minVertexX, v.x);
- minVertexY = Math.min(minVertexY, v.y);
- //maxVertex = b2Math.b2MaxV(maxVertex, m_vertices[i]);
- maxVertexX = Math.max(maxVertexX, v.x);
- maxVertexY = Math.max(maxVertexY, v.y);
- //m_maxRadius = b2Max(m_maxRadius, v.Length());
- m_maxRadius = Math.max(m_maxRadius, v.Length());
- }
-
- m_localOBB.R.SetIdentity();
- //m_localOBB.center = 0.5 * (minVertex + maxVertex);
- m_localOBB.center.Set((minVertexX + maxVertexX) * 0.5, (minVertexY + maxVertexY) * 0.5);
- //m_localOBB.extents = 0.5 * (maxVertex - minVertex);
- m_localOBB.extents.Set((maxVertexX - minVertexX) * 0.5, (maxVertexY - minVertexY) * 0.5);
-
- // Compute the edge normals and next index map.
- var i1:int;
- var i2:int;
- for (i = 0; i < m_vertexCount; ++i)
- {
- m_normals[i] = new b2Vec2();
- i1 = i;
- i2 = i + 1 < m_vertexCount ? i + 1 : 0;
- //b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
- //var edgeX:Number = m_vertices[i2].x - m_vertices[i1].x;
- //var edgeY:Number = m_vertices[i2].y - m_vertices[i1].y;
- //m_normals[i] = b2Cross(edge, 1.0f);
- m_normals[i].x = m_vertices[i2].y - m_vertices[i1].y;//1.0 * edgeY;
- m_normals[i].y = -(m_vertices[i2].x - m_vertices[i1].x);//-1.0 * edgeX;
- m_normals[i].Normalize();
- }
-
- // Ensure the polygon in convex. TODO_ERIN compute convex hull.
- for (i = 0; i < m_vertexCount; ++i)
- {
- i1 = i;
- i2 = i + 1 < m_vertexCount ? i + 1 : 0;
-
- //b2Settings.b2Assert(b2Math.b2CrossVV(m_normals[i1], m_normals[i2]) > Number.MIN_VALUE);
- }
-
- m_R.SetM(m_body.m_R);
- //m_position.SetV( m_body.m_position + b2Mul(m_body->m_R, m_localCentroid) );
- m_position.x = m_body.m_position.x + (m_R.col1.x * m_localCentroid.x + m_R.col2.x * m_localCentroid.y);
- m_position.y = m_body.m_position.y + (m_R.col1.y * m_localCentroid.x + m_R.col2.y * m_localCentroid.y);
-
- //var R:b2Mat22 = b2Math.b2MulMM(m_R, m_localOBB.R);
- //R.col1 = b2MulMV(m_R, m_localOBB.R.col1);
- tAbsR.col1.x = m_R.col1.x * m_localOBB.R.col1.x + m_R.col2.x * m_localOBB.R.col1.y;
- tAbsR.col1.y = m_R.col1.y * m_localOBB.R.col1.x + m_R.col2.y * m_localOBB.R.col1.y;
- //R.col2 = b2MulMV(m_R, m_localOBB.R.col2)
- tAbsR.col2.x = m_R.col1.x * m_localOBB.R.col2.x + m_R.col2.x * m_localOBB.R.col2.y;
- tAbsR.col2.y = m_R.col1.y * m_localOBB.R.col2.x + m_R.col2.y * m_localOBB.R.col2.y;
- //var absR:b2Mat22 = b2Math.b2AbsM(R);
- tAbsR.Abs()
-
- //h = b2Math.b2MulMV(tAbsR, m_localOBB.extents);
- hX = tAbsR.col1.x * m_localOBB.extents.x + tAbsR.col2.x * m_localOBB.extents.y;
- hY = tAbsR.col1.y * m_localOBB.extents.x + tAbsR.col2.y * m_localOBB.extents.y;
-
- //var position:b2Vec2 = m_position + b2Mul(m_R, m_localOBB.center);
- var positionX:Number = m_position.x + (m_R.col1.x * m_localOBB.center.x + m_R.col2.x * m_localOBB.center.y);
- var positionY:Number = m_position.y + (m_R.col1.y * m_localOBB.center.x + m_R.col2.y * m_localOBB.center.y);
-
- //aabb.minVertex = b2Math.SubtractVV(m_position, h);
- aabb.minVertex.x = positionX - hX;
- aabb.minVertex.y = positionY - hY;
- //aabb.maxVertex = b2Math.AddVV(m_position, h);
- aabb.maxVertex.x = positionX + hX;
- aabb.maxVertex.y = positionY + hY;
-
- var broadPhase:b2BroadPhase = m_body.m_world.m_broadPhase;
- if (broadPhase.InRange(aabb))
- {
- m_proxyId = broadPhase.CreateProxy(aabb, this);
- }
- else
- {
- m_proxyId = b2Pair.b2_nullProxy;
- }
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- m_body.Freeze();
- }
- }
-
- // Temp AABB for Synch function
- private var syncAABB:b2AABB = new b2AABB();
- private var syncMat:b2Mat22 = new b2Mat22();
- public override function Synchronize(position1:b2Vec2, R1:b2Mat22,
- position2:b2Vec2, R2:b2Mat22) : void{
- // The body transform is copied for convenience.
- m_R.SetM(R2);
- //m_position = m_body->m_position + b2Mul(m_body->m_R, m_localCentroid)
- m_position.x = m_body.m_position.x + (R2.col1.x * m_localCentroid.x + R2.col2.x * m_localCentroid.y);
- m_position.y = m_body.m_position.y + (R2.col1.y * m_localCentroid.x + R2.col2.y * m_localCentroid.y);
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- return;
- }
-
- //b2AABB aabb1, aabb2;
- var hX:Number;
- var hY:Number;
-
- //b2Mat22 obbR = b2Mul(R1, m_localOBB.R);
- var v1:b2Vec2 = R1.col1;
- var v2:b2Vec2 = R1.col2;
- var v3:b2Vec2 = m_localOBB.R.col1;
- var v4:b2Vec2 = m_localOBB.R.col2;
- //syncMat.col1 = b2MulMV(R1, m_localOBB.R.col1);
- syncMat.col1.x = v1.x * v3.x + v2.x * v3.y;
- syncMat.col1.y = v1.y * v3.x + v2.y * v3.y;
- //syncMat.col2 = b2MulMV(R1, m_localOBB.R.col2);
- syncMat.col2.x = v1.x * v4.x + v2.x * v4.y;
- syncMat.col2.y = v1.y * v4.x + v2.y * v4.y;
- //b2Mat22 absR = b2Abs(obbR);
- syncMat.Abs();
- //b2Vec2 center = position1 + b2Mul(R1, m_localCentroid + m_localOBB.center);
- hX = m_localCentroid.x + m_localOBB.center.x;
- hY = m_localCentroid.y + m_localOBB.center.y;
- var centerX:Number = position1.x + (R1.col1.x * hX + R1.col2.x * hY);
- var centerY:Number = position1.y + (R1.col1.y * hX + R1.col2.y * hY);
- //b2Vec2 h = b2Mul(syncMat, m_localOBB.extents);
- hX = syncMat.col1.x * m_localOBB.extents.x + syncMat.col2.x * m_localOBB.extents.y;
- hY = syncMat.col1.y * m_localOBB.extents.x + syncMat.col2.y * m_localOBB.extents.y;
- //aabb1.minVertex = center - h;
- syncAABB.minVertex.x = centerX - hX;
- syncAABB.minVertex.y = centerY - hY;
- //aabb1.maxVertex = center + h;
- syncAABB.maxVertex.x = centerX + hX;
- syncAABB.maxVertex.y = centerY + hY;
-
- //b2Mat22 obbR = b2Mul(R2, m_localOBB.R);
- v1 = R2.col1;
- v2 = R2.col2;
- v3 = m_localOBB.R.col1;
- v4 = m_localOBB.R.col2;
- //syncMat.col1 = b2MulMV(R1, m_localOBB.R.col1);
- syncMat.col1.x = v1.x * v3.x + v2.x * v3.y;
- syncMat.col1.y = v1.y * v3.x + v2.y * v3.y;
- //syncMat.col2 = b2MulMV(R1, m_localOBB.R.col2);
- syncMat.col2.x = v1.x * v4.x + v2.x * v4.y;
- syncMat.col2.y = v1.y * v4.x + v2.y * v4.y;
- //b2Mat22 absR = b2Abs(obbR);
- syncMat.Abs();
- //b2Vec2 center = position2 + b2Mul(R2, m_localCentroid + m_localOBB.center);
- hX = m_localCentroid.x + m_localOBB.center.x;
- hY = m_localCentroid.y + m_localOBB.center.y;
- centerX = position2.x + (R2.col1.x * hX + R2.col2.x * hY);
- centerY = position2.y + (R2.col1.y * hX + R2.col2.y * hY);
- //b2Vec2 h = b2Mul(absR, m_localOBB.extents);
- hX = syncMat.col1.x * m_localOBB.extents.x + syncMat.col2.x * m_localOBB.extents.y;
- hY = syncMat.col1.y * m_localOBB.extents.x + syncMat.col2.y * m_localOBB.extents.y;
- //aabb2.minVertex = center - h;
- //aabb2.maxVertex = center + h;
-
- //aabb.minVertex = b2Min(aabb1.minVertex, aabb2.minVertex);
- syncAABB.minVertex.x = Math.min(syncAABB.minVertex.x, centerX - hX);
- syncAABB.minVertex.y = Math.min(syncAABB.minVertex.y, centerY - hY);
- //aabb.maxVertex = b2Max(aabb1.maxVertex, aabb2.maxVertex);
- syncAABB.maxVertex.x = Math.max(syncAABB.maxVertex.x, centerX + hX);
- syncAABB.maxVertex.y = Math.max(syncAABB.maxVertex.y, centerY + hY);
-
- var broadPhase:b2BroadPhase = m_body.m_world.m_broadPhase;
- if (broadPhase.InRange(syncAABB))
- {
- broadPhase.MoveProxy(m_proxyId, syncAABB);
- }
- else
- {
- m_body.Freeze();
- }
- }
-
- public override function QuickSync(position:b2Vec2, R:b2Mat22) : void{
- //m_R = R;
- m_R.SetM(R);
- //m_position = position + b2Mul(R, m_localCentroid);
- m_position.x = position.x + (R.col1.x * m_localCentroid.x + R.col2.x * m_localCentroid.y);
- m_position.y = position.y + (R.col1.y * m_localCentroid.x + R.col2.y * m_localCentroid.y);
- }
-
- public override function ResetProxy(broadPhase:b2BroadPhase) : void{
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- return;
- }
-
- var proxy:b2Proxy = broadPhase.GetProxy(m_proxyId);
-
- broadPhase.DestroyProxy(m_proxyId);
- proxy = null;
-
- var R:b2Mat22 = b2Math.b2MulMM(m_R, m_localOBB.R);
- var absR:b2Mat22 = b2Math.b2AbsM(R);
- var h:b2Vec2 = b2Math.b2MulMV(absR, m_localOBB.extents);
- //var position:b2Vec2 = m_position + b2Mul(m_R, m_localOBB.center);
- var position:b2Vec2 = b2Math.b2MulMV(m_R, m_localOBB.center);
- position.Add(m_position);
-
- var aabb:b2AABB = new b2AABB();
- //aabb.minVertex = position - h;
- aabb.minVertex.SetV(position);
- aabb.minVertex.Subtract(h);
- //aabb.maxVertex = position + h;
- aabb.maxVertex.SetV(position);
- aabb.maxVertex.Add(h);
-
- if (broadPhase.InRange(aabb))
- {
- m_proxyId = broadPhase.CreateProxy(aabb, this);
- }
- else
- {
- m_proxyId = b2Pair.b2_nullProxy;
- }
-
- if (m_proxyId == b2Pair.b2_nullProxy)
- {
- m_body.Freeze();
- }
- }
-
-
- public override function Support(dX:Number, dY:Number, out:b2Vec2):void
- {
- //b2Vec2 dLocal = b2MulT(m_R, d);
- var dLocalX:Number = (dX*m_R.col1.x + dY*m_R.col1.y);
- var dLocalY:Number = (dX*m_R.col2.x + dY*m_R.col2.y);
-
- var bestIndex:int = 0;
- //float32 bestValue = b2Dot(m_vertices[0], dLocal);
- var bestValue:Number = (m_coreVertices[0].x * dLocalX + m_coreVertices[0].y * dLocalY);
- for (var i:int = 1; i < m_vertexCount; ++i)
- {
- //float32 value = b2Dot(m_vertices[i], dLocal);
- var value:Number = (m_coreVertices[i].x * dLocalX + m_coreVertices[i].y * dLocalY);
- if (value > bestValue)
- {
- bestIndex = i;
- bestValue = value;
- }
- }
-
- //return m_position + b2Mul(m_R, m_vertices[bestIndex]);
- out.Set( m_position.x + (m_R.col1.x * m_coreVertices[bestIndex].x + m_R.col2.x * m_coreVertices[bestIndex].y),
- m_position.y + (m_R.col1.y * m_coreVertices[bestIndex].x + m_R.col2.y * m_coreVertices[bestIndex].y));
-
- }
-
-
- // Local position of the shape centroid in parent body frame.
- public var m_localCentroid:b2Vec2 = new b2Vec2();
-
- // Local position oriented bounding box. The OBB center is relative to
- // shape centroid.
- public var m_localOBB:b2OBB = new b2OBB();
- public var m_vertices:Array;
- public var m_coreVertices:Array;
- public var m_vertexCount:int;
- public var m_normals:Array;
-};
-
-}
View
340 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2Shape.as
@@ -1,340 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Common.*
-import Box2D.Dynamics.*
-import Box2D.Collision.*
-
-
-
-// Shapes are created automatically when a body is created.
-// Client code does not normally interact with shapes.
-public class b2Shape
-{
- public virtual function TestPoint(p:b2Vec2):Boolean{return false};
-
- public function GetUserData():* {return m_userData;};
-
- public function GetType():int{
- return m_type;
- }
-
- // Get the parent body of this shape.
- public function GetBody():b2Body{
- return m_body;
- }
-
- public function GetPosition():b2Vec2{
- return m_position;
- }
- public function GetRotationMatrix():b2Mat22{
- return m_R;
- }
-
- // Remove and then add proxy from the broad-phase.
- // This is used to refresh the collision filters.
- public virtual function ResetProxy(broadPhase:b2BroadPhase) : void{};
-
- // Get the next shape in the parent body's shape list.
- public function GetNext():b2Shape{
- return m_next;
- }
-
- //--------------- Internals Below -------------------
-
- static public function Create(def:b2ShapeDef, body:b2Body, center:b2Vec2):b2Shape{
- switch (def.type)
- {
- case e_circleShape:
- {
- //void* mem = body->m_world->m_blockAllocator.Allocate(sizeof(b2CircleShape));
- return new b2CircleShape(def, body, center);
- }
-
- case e_boxShape:
- case e_polyShape:
- {
- //void* mem = body->m_world->m_blockAllocator.Allocate(sizeof(b2PolyShape));
- return new b2PolyShape(def, body, center);
- }
- }
-
- //b2Settings.b2Assert(false);
- return null;
- }
-
- static public function Destroy(shape:b2Shape) : void
- {
- /*b2BlockAllocator& allocator = shape->m_body->m_world->m_blockAllocator;
-
- switch (shape.m_type)
- {
- case e_circleShape:
- shape->~b2Shape();
- allocator.Free(shape, sizeof(b2CircleShape));
- break;
-
- case e_polyShape:
- shape->~b2Shape();
- allocator.Free(shape, sizeof(b2PolyShape));
- break;
-
- default:
- b2Assert(false);
- }
-
- shape = NULL;*/
-
- // FROM DESTRUCTOR
- if (shape.m_proxyId != b2Pair.b2_nullProxy)
- shape.m_body.m_world.m_broadPhase.DestroyProxy(shape.m_proxyId);
- }
-
-
- public function b2Shape(def:b2ShapeDef, body:b2Body){
- m_userData = def.userData;
-
- m_friction = def.friction;
- m_restitution = def.restitution;
- m_body = body;
-
- m_proxyId = b2Pair.b2_nullProxy;
-
- m_maxRadius = 0.0;
-
- m_categoryBits = def.categoryBits;
- m_maskBits = def.maskBits;
- m_groupIndex = def.groupIndex;
- }
-
- // Internal use only. Do not call.
- //b2Shape::~b2Shape()
- //{
- // m_body->m_world->m_broadPhase->DestroyProxy(m_proxyId);
- //}
-
-
- public function DestroyProxy() : void
- {
- if (m_proxyId != b2Pair.b2_nullProxy)
- {
- m_body.m_world.m_broadPhase.DestroyProxy(m_proxyId);
- m_proxyId = b2Pair.b2_nullProxy;
- }
- }
-
-
- // Internal use only. Do not call.
- public virtual function Synchronize(position1:b2Vec2, R1:b2Mat22,
- position2:b2Vec2, R2:b2Mat22) : void{};
- public virtual function QuickSync(position:b2Vec2, R:b2Mat22) : void{};
- public virtual function Support(dX:Number, dY:Number, out:b2Vec2) : void{};
- public function GetMaxRadius():Number{
- return m_maxRadius;
- }
-
- public var m_next:b2Shape;
-
- public var m_R:b2Mat22 = new b2Mat22();
- public var m_position:b2Vec2 = new b2Vec2();
-
- public var m_type:int;
-
- public var m_userData:* = null;
-
- public var m_body:b2Body;
-
- public var m_friction:Number;
- public var m_restitution:Number;
-
- public var m_maxRadius:Number;
-
- public var m_proxyId:uint;
- public var m_categoryBits:uint;
- public var m_maskBits:uint;
- public var m_groupIndex:int;
-
-
-
- // b2ShapeType
- static public const e_unknownShape:int = -1;
- static public const e_circleShape:int = 0;
- static public const e_boxShape:int = 1;
- static public const e_polyShape:int = 2;
- static public const e_meshShape:int = 3;
- static public const e_shapeTypeCount:int = 4;
-
-
-
-
-
-
-
- static public function PolyMass(massData:b2MassData, vs:Array, count:int, rho:Number) : void
- {
- //b2Settings.b2Assert(count >= 3);
-
- //var center:b2Vec2 = new b2Vec2(0.0, 0.0);
- var center:b2Vec2 = new b2Vec2();
- center.SetZero();
-
- var area:Number = 0.0;
- var I:Number = 0.0;
-
- // pRef is the reference point for forming triangles.
- // It's location doesn't change the result (except for rounding error).
- var pRef:b2Vec2 = new b2Vec2(0.0, 0.0);
-
- const inv3:Number = 1.0 / 3.0;
-
- for (var i:int = 0; i < count; ++i)
- {
- // Triangle vertices.
- var p1:b2Vec2 = pRef;
- var p2:b2Vec2 = vs[i];
- var p3:b2Vec2 = i + 1 < count ? vs[i+1] : vs[0];
-
- var e1:b2Vec2 = b2Math.SubtractVV(p2, p1);
- var e2:b2Vec2 = b2Math.SubtractVV(p3, p1);
-
- var D:Number = b2Math.b2CrossVV(e1, e2);
-
- var triangleArea:Number = 0.5 * D;
- area += triangleArea;
-
- // Area weighted centroid
- // center += triangleArea * inv3 * (p1 + p2 + p3);
- var tVec:b2Vec2 = new b2Vec2();
- tVec.SetV(p1);
- tVec.Add(p2);
- tVec.Add(p3);
- tVec.Multiply(inv3*triangleArea);
- center.Add(tVec);
-
- var px:Number = p1.x;
- var py:Number = p1.y;
- var ex1:Number = e1.x;
- var ey1:Number = e1.y;
- var ex2:Number = e2.x;
- var ey2:Number = e2.y;
-
- var intx2:Number = inv3 * (0.25 * (ex1*ex1 + ex2*ex1 + ex2*ex2) + (px*ex1 + px*ex2)) + 0.5*px*px;
- var inty2:Number = inv3 * (0.25 * (ey1*ey1 + ey2*ey1 + ey2*ey2) + (py*ey1 + py*ey2)) + 0.5*py*py;
-
- I += D * (intx2 + inty2);
- }
-
- // Total mass
- massData.mass = rho * area;
-
- // Center of mass
- //b2Settings.b2Assert(area > Number.MIN_VALUE);
- center.Multiply( 1.0 / area );
- massData.center = center;
-
- // Inertia tensor relative to the center.
- I = rho * (I - area * b2Math.b2Dot(center, center));
- massData.I = I;
- }
-
-
- static public function PolyCentroid(vs:Array, count:int, out:b2Vec2):void
- {
- //b2Settings.b2Assert(count >= 3);
-
- //b2Vec2 c; c.Set(0.0f, 0.0f);
- var cX:Number = 0.0;
- var cY:Number = 0.0;
- //float32 area = 0.0f;
- var area:Number = 0.0;
-
- // pRef is the reference point for forming triangles.
- // It's location doesn't change the result (except for rounding error).
- //b2Vec2 pRef(0.0f, 0.0f);
- var pRefX:Number = 0.0;
- var pRefY:Number = 0.0;
- /*
- // This code would put the reference point inside the polygon.
- for (var i:int = 0; i < count; ++i)
- {
- //pRef += vs[i];
- pRef.x += vs[i].x;
- pRef.y += vs[i].y;
- }
- pRef.x *= 1.0 / count;
- pRef.y *= 1.0 / count;
- */
-
- //const float32 inv3 = 1.0f / 3.0f;
- const inv3:Number = 1.0 / 3.0;
-
- for (var i:int = 0; i < count; ++i)
- {
- // Triangle vertices.
- //b2Vec2 p1 = pRef;
- var p1X:Number = pRefX;
- var p1Y:Number = pRefY;
- //b2Vec2 p2 = vs[i];
- var p2X:Number = vs[i].x;
- var p2Y:Number = vs[i].y;
- //b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
- var p3X:Number = i + 1 < count ? vs[i+1].x : vs[0].x;
- var p3Y:Number = i + 1 < count ? vs[i+1].y : vs[0].y;
-
- //b2Vec2 e1 = p2 - p1;
- var e1X:Number = p2X - p1X;
- var e1Y:Number = p2Y - p1Y;
- //b2Vec2 e2 = p3 - p1;
- var e2X:Number = p3X - p1X;
- var e2Y:Number = p3Y - p1Y;
-
- //float32 D = b2Cross(e1, e2);
- var D:Number = (e1X * e2Y - e1Y * e2X);
-
- //float32 triangleArea = 0.5f * D;
- var triangleArea:Number = 0.5 * D;
- area += triangleArea;
-
- // Area weighted centroid
- //c += triangleArea * inv3 * (p1 + p2 + p3);
- cX += triangleArea * inv3 * (p1X + p2X + p3X);
- cY += triangleArea * inv3 * (p1Y + p2Y + p3Y);
- }
-
- // Centroid
- //b2Settings.b2Assert(area > Number.MIN_VALUE);
- cX *= 1.0 / area;
- cY *= 1.0 / area;
-
- // Replace return with 'out' vector
- //return c;
- out.Set(cX, cY);
- }
-
-
-
-};
-
-
-}
View
115 test/Box2DFlashAS3/Box2D/Collision/Shapes/b2ShapeDef.as
@@ -1,115 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision.Shapes{
-
-
-
-import Box2D.Common.Math.*;
-import Box2D.Common.*
-import Box2D.Collision.Shapes.b2Shape;
-
-
-
-public class b2ShapeDef
-{
- public function b2ShapeDef()
- {
- type = b2Shape.e_unknownShape;
- userData = null;
- localPosition = new b2Vec2(0.0, 0.0);
- localRotation = 0.0;
- friction = 0.2;
- restitution = 0.0;
- density = 0.0;
- categoryBits = 0x0001;
- maskBits = 0xFFFF;
- groupIndex = 0;
- }
-
- //virtual ~b2ShapeDef() {}
-
- public function ComputeMass(massData:b2MassData) : void
- {
-
- massData.center = new b2Vec2(0.0, 0.0)
-
- if (density == 0.0)
- {
- massData.mass = 0.0;
- massData.center.Set(0.0, 0.0);
- massData.I = 0.0;
- };
-
- switch (type)
- {
- case b2Shape.e_circleShape:
- {
- var circle:b2CircleDef = this as b2CircleDef;
- massData.mass = density * b2Settings.b2_pi * circle.radius * circle.radius;
- massData.center.Set(0.0, 0.0);
- massData.I = 0.5 * (massData.mass) * circle.radius * circle.radius;
- }
- break;
-
- case b2Shape.e_boxShape:
- {
- var box:b2BoxDef = this as b2BoxDef;
- massData.mass = 4.0 * density * box.extents.x * box.extents.y;
- massData.center.Set(0.0, 0.0);
- massData.I = massData.mass / 3.0 * b2Math.b2Dot(box.extents, box.extents);
- }
- break;
-
- case b2Shape.e_polyShape:
- {
- var poly:b2PolyDef = this as b2PolyDef;
- b2Shape.PolyMass(massData, poly.vertices, poly.vertexCount, density);
- }
- break;
-
- default:
- massData.mass = 0.0;
- massData.center.Set(0.0, 0.0);
- massData.I = 0.0;
- break;
- }
- }
-
- public var type:int;
- public var userData:* = null;
- public var localPosition:b2Vec2;
- public var localRotation:Number;
- public var friction:Number;
- public var restitution:Number;
- public var density:Number;
-
- // The collision category bits. Normally you would just set one bit.
- public var categoryBits:int;
-
- // The collision mask bits. This states the categories that this
- // shape would accept for collision.
- public var maskBits:int;
-
- // Collision groups allow a certain group of objects to never collide (negative)
- // or always collide (positive). Zero means no collision group. Non-zero group
- // filtering always wins against the mask bits.
- public var groupIndex:int;
-};
-
-}
View
45 test/Box2DFlashAS3/Box2D/Collision/b2AABB.as
@@ -1,45 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision{
-
-import Box2D.Collision.*
-import Box2D.Common.Math.*
-
-// A manifold for two touching convex shapes.
-public class b2AABB
-{
- public function IsValid():Boolean{
- //var d:b2Vec2 = b2Math.SubtractVV(maxVertex, minVertex);
- var dX:Number = maxVertex.x;
- var dY:Number = maxVertex.y;
- dX = maxVertex.x;
- dY = maxVertex.y;
- dX -= minVertex.x;
- dY -= minVertex.y;
- var valid:Boolean = dX >= 0.0 && dY >= 0.0;
- valid = valid && minVertex.IsValid() && maxVertex.IsValid();
- return valid;
- }
-
- public var minVertex:b2Vec2 = new b2Vec2();
- public var maxVertex:b2Vec2 = new b2Vec2();
-};
-
-
-}
View
45 test/Box2DFlashAS3/Box2D/Collision/b2Bound.as
@@ -1,45 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision{
-
-
-public class b2Bound{
- public function IsLower():Boolean { return (value & 1) == 0; }
- public function IsUpper():Boolean { return (value & 1) == 1; }
- public function Swap(b:b2Bound) : void{
- var tempValue:uint = value;
- var tempProxyId:uint = proxyId;
- var tempStabbingCount:uint = stabbingCount;
-
- value = b.value;
- proxyId = b.proxyId;
- stabbingCount = b.stabbingCount;
-
- b.value = tempValue;
- b.proxyId = tempProxyId;
- b.stabbingCount = tempStabbingCount;
- }
-
- public var value:uint;
- public var proxyId:uint;
- public var stabbingCount:uint;
-}
-
-
-}
View
28 test/Box2DFlashAS3/Box2D/Collision/b2BoundValues.as
@@ -1,28 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision{
-
-
-public class b2BoundValues{
- public var lowerValues:Array = [0,0];
- public var upperValues:Array = [0,0];
-}
-
-
-}
View
901 test/Box2DFlashAS3/Box2D/Collision/b2BroadPhase.as
@@ -1,901 +0,0 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
-*
-* 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 as such, and must not be
-* misrepresented as being the original software.
-* 3. This notice may not be removed or altered from any source distribution.
-*/
-
-package Box2D.Collision{
-
-
-import Box2D.Common.*
-import Box2D.Collision.*
-import Box2D.Common.Math.*
-
-
-/*
-This broad phase uses the Sweep and Prune algorithm as described in:
-Collision Detection in Interactive 3D Environments by Gino van den Bergen
-Also, some ideas, such as using 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.
-
-public class b2BroadPhase
-{
-//public:
- public function b2BroadPhase(worldAABB:b2AABB, callback:b2PairCallback){
- //b2Settings.b2Assert(worldAABB.IsValid());
- var i:int;
-
- m_pairManager.Initialize(this, callback);
-
- m_worldAABB = worldAABB;
-
- m_proxyCount = 0;
-
- // query results
- for (i = 0; i < b2Settings.b2_maxProxies; i++){
- m_queryResults[i] = 0;
- }
-
- // bounds array
- m_bounds = new Array(2);
- for (i = 0; i < 2; i++){
- m_bounds[i] = new Array(2*b2Settings.b2_maxProxies);
- for (var j:int = 0; j < 2*b2Settings.b2_maxProxies; j++){
- m_bounds[i][j] = new b2Bound();
- }
- }
-
- //var d:b2Vec2 = b2Math.SubtractVV(worldAABB.maxVertex, worldAABB.minVertex);
- var dX:Number = worldAABB.maxVertex.x;
- var dY:Number = worldAABB.maxVertex.y;
- dX -= worldAABB.minVertex.x;
- dY -= worldAABB.minVertex.y;
-
- m_quantizationFactor.x = b2Settings.USHRT_MAX / dX;
- m_quantizationFactor.y = b2Settings.USHRT_MAX / dY;
-
- var tProxy:b2Proxy;
- for (i = 0; i < b2Settings.b2_maxProxies - 1; ++i)
- {
- tProxy = new b2Proxy();
- m_proxyPool[i] = tProxy;
- tProxy.SetNext(i + 1);
- tProxy.timeStamp = 0;
- tProxy.overlapCount = b2_invalid;
- tProxy.userData = null;
- }
- tProxy = new b2Proxy();
- m_proxyPool[b2Settings.b2_maxProxies-1] = tProxy;
- tProxy.SetNext(b2Pair.b2_nullProxy);
- tProxy.timeStamp = 0;
- tProxy.overlapCount = b2_invalid;
- tProxy.userData = null;
- m_freeProxy = 0;
-
- m_timeStamp = 1;
- 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.
- public function InRange(aabb:b2AABB):Boolean{
- //var d:b2Vec2 = b2Math.b2MaxV(b2Math.SubtractVV(aabb.minVertex, m_worldAABB.maxVertex), b2Math.SubtractVV(m_worldAABB.minVertex, aabb.maxVertex));
- var dX:Number;
- var dY:Number;
- var d2X:Number;
- var d2Y:Number;
-
- dX = aabb.minVertex.x;
- dY = aabb.minVertex.y;
- dX -= m_worldAABB.maxVertex.x;
- dY -= m_worldAABB.maxVertex.y;
-
- d2X = m_worldAABB.minVertex.x;
- d2Y = m_worldAABB.minVertex.y;
- d2X -= aabb.maxVertex.x;
- d2Y -= aabb.maxVertex.y;
-
- dX = b2Math.b2Max(dX, d2X);
- dY = b2Math.b2Max(dY, d2Y);
-
- return b2Math.b2Max(dX, dY) < 0.0;
- }
-
- // Get a single proxy. Returns NULL if the id is invalid.
- public function GetProxy(proxyId:int):b2Proxy{
- if (proxyId == b2Pair.b2_nullProxy || m_proxyPool[proxyId].IsValid() == false)
- {
- return null;
- }
-
- return m_proxyPool[ proxyId ];
- }
-
- // Create and destroy proxies. These call Flush first.
- public function CreateProxy(aabb:b2AABB, userData:*):uint{
- var index:uint;
- var proxy:b2Proxy;
-
- //b2Settings.b2Assert(m_proxyCount < b2_maxProxies);
- //b2Settings.b2Assert(m_freeProxy != b2Pair.b2_nullProxy);
-
- var proxyId:uint = m_freeProxy;
- proxy = m_proxyPool[ proxyId ];
- m_freeProxy = proxy.GetNext();
-
- proxy.overlapCount = 0;
- proxy.userData = userData;
-
- var boundCount:uint = 2 * m_proxyCount;
-
- var lowerValues:Array = new Array();
- var upperValues:Array = new Array();
- ComputeBounds(lowerValues, upperValues, aabb);
-
- for (var axis:int = 0; axis < 2; ++axis)
- {
- var bounds:Array = m_bounds[axis];
- var lowerIndex:uint;
- var upperIndex:uint;
- var lowerIndexOut:Array = [lowerIndex];
- var upperIndexOut:Array = [upperIndex];
- 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:Array = new Array();
- var j:int;
- var tEnd:int = boundCount - upperIndex
- var tBound1:b2Bound;
- var tBound2:b2Bound;
- // make temp array
- for (j = 0; j < tEnd; j++){
- tArr[j] = new b2Bound();
- 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:int = 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 b2Bound();
- 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:b2Proxy = m_proxyPool[ bounds[index].proxyId ];
- if (bounds[index].IsLower())
- {
- proxy2.lowerBounds[axis] = index;
- }
- else
- {
- proxy2.upperBounds[axis] = index;
- }
- }
- }
-
- ++m_proxyCount;
-
- //b2Settings.b2Assert(m_queryResultCount < b2Settings.b2_maxProxies);
-
- for (var i:int = 0; i < m_queryResultCount; ++i)
- {
- //b2Settings.b2Assert(m_queryResults[i] < b2_maxProxies);
- //b2Settings.b2Assert(m_proxyPool[m_queryResults[i]].IsValid());
-
- m_pairManager.AddBufferedPair(proxyId, m_queryResults[i]);
- }
-
- m_pairManager.Commit();
-
- // Prepare for next query.
- m_queryResultCount = 0;
- IncrementTimeStamp();
-
- return proxyId;
- }
-
- public function DestroyProxy(proxyId:uint) : void{
-
- //b2Settings.b2Assert(0 < m_proxyCount && m_proxyCount <= b2_maxProxies);
-
- var proxy:b2Proxy = m_proxyPool[ proxyId ];
- //b2Settings.b2Assert(proxy.IsValid());
-
- var boundCount:int = 2 * m_proxyCount;
-
- for (var axis:int = 0; axis < 2; ++axis)
- {
- var bounds:Array = m_bounds[axis];
-
- var lowerIndex:uint = proxy.lowerBounds[axis];
- var upperIndex:uint = proxy.upperBounds[axis];
- var lowerValue:uint = bounds[lowerIndex].value;
- var upperValue:uint = bounds[upperIndex].value;
-
- // replace memmove calls
- //memmove(bounds + lowerIndex, bounds + lowerIndex + 1, (upperIndex - lowerIndex - 1) * sizeof(b2Bound));
- var tArr:Array = new Array();
- var j:int;
- var tEnd:int = upperIndex - lowerIndex - 1;
- var tBound1:b2Bound;
- var tBound2:b2Bound;
- // make temp array
- for (j = 0; j < tEnd; j++){
- tArr[j] = new b2Bound();
- 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:int = 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 b2Bound();
- 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:uint = lowerIndex; index < tEnd; ++index)
- {
- var proxy2:b2Proxy = m_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:int = lowerIndex; index2 < tEnd; ++index2)
- {
- bounds[index2].stabbingCount--;
- }
-
- // 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
- Query([0], [0], lowerValue, upperValue, bounds, boundCount - 2, axis);
- }
-
- //b2Settings.b2Assert(m_queryResultCount < b2Settings.b2_maxProxies);
-
- for (var i:int = 0; i < m_queryResultCount; ++i)
- {
- //b2Settings.b2Assert(m_proxyPool[m_queryResults[i]].IsValid());
-
- m_pairManager.RemoveBufferedPair(proxyId, m_queryResults[i]);
- }
-
- m_pairManager.Commit();
-
- // Prepare for next query.
- m_queryResultCount = 0;
- IncrementTimeStamp();
-
- // Return the proxy to the pool.
- proxy.userData = null;
- proxy.overlapCount = b2_invalid;
- proxy.lowerBounds[0] = b2_invalid;
- proxy.lowerBounds[1] = b2_invalid;
- proxy.upperBounds[0] = b2_invalid;
- proxy.upperBounds[1] = b2_invalid;
-
- proxy.SetNext(m_freeProxy);
- m_freeProxy = proxyId;
- --m_proxyCount;
- }
-
-
- // Call MoveProxy as many times as you like, then when you are done
- // call Commit to finalized the proxy pairs (for your time step).
- public function MoveProxy(proxyId:uint, aabb:b2AABB) : void{
- var axis:uint;
- var index:uint;
- var bound:b2Bound;
- var prevBound:b2Bound
- var nextBound:b2Bound
- var nextProxyId:uint;
- var nextProxy:b2Proxy;
-
- if (proxyId == b2Pair.b2_nullProxy || b2Settings.b2_maxProxies <= proxyId)
- {
- //b2Settings.b2Assert(false);
- return;
- }
-
- if (aabb.IsValid() == false)
- {
- //b2Settings.b2Assert(false);
- return;
- }
-
- var boundCount:uint = 2 * m_proxyCount;
-
- var proxy:b2Proxy = m_proxyPool[ proxyId ];
- // Get new bound values
- var newValues:b2BoundValues = new b2BoundValues();
- ComputeBounds(newValues.lowerValues, newValues.upperValues, aabb);
-
- // Get old bound values
- var oldValues:b2BoundValues = new b2BoundValues();
- for (axis = 0; axis < 2; ++axis)
- {
- oldValues.lowerValues[axis] = m_bounds[axis][proxy.lowerBounds[axis]].value;
- oldValues.upperValues[axis] = m_bounds[axis][proxy.upperBounds[axis]].value;
- }
-
- for (axis = 0; axis < 2; ++axis)
- {
- var bounds:Array = m_bounds[axis];
-
- var lowerIndex:uint = proxy.lowerBounds[axis];
- var upperIndex:uint = proxy.upperBounds[axis];
-
- var lowerValue:uint = newValues.lowerValues[axis];
- var upperValue:uint = newValues.upperValues[axis];
-
- var deltaLower:int = lowerValue - bounds[lowerIndex].value;
- var deltaUpper:int = 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:uint = prevBound.proxyId;
- var prevProxy:b2Proxy = m_proxyPool[ prevBound.proxyId ];
-
- prevBound.stabbingCount++;
-
- if (prevBound.IsUpper() == true)
- {
- if (TestOverlap(newValues, prevProxy))
- {
- m_pairManager.AddBufferedPair(proxyId, prevProxyId);
- }
-
- prevProxy.upperBounds[axis]++;
- bound.stabbingCount++;
- }
- else
- {
- prevProxy.lowerBounds[axis]++;
- bound.stabbingCount--;
- }
-
- proxy.lowerBounds[axis]--;
-
- // swap
- //var temp:b2Bound = bound;
- //bound = prevEdge;
- //prevEdge = temp;
- bound.Swap(prevBound);
- //b2Math.b2Swap(bound, prevEdge);
- --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 = m_proxyPool[ nextProxyId ];
-
- nextBound.stabbingCount++;
-
- if (nextBound.IsLower() == true)
- {
- if (TestOverlap(newValues, nextProxy))
- {
- m_pairManager.AddBufferedPair(proxyId, nextProxyId);
- }
-
- nextProxy.lowerBounds[axis]--;
- bound.stabbingCount++;
- }
- else
- {
- nextProxy.upperBounds[axis]--;
- bound.stabbingCount--;
- }
-
- proxy.upperBounds[axis]++;
- // swap
- //var temp:b2Bound = bound;
- //bound = nextEdge;
- //nextEdge = temp;
- bound.Swap(nextBound);
- //b2Math.b2Swap(bound, nextEdge);
- 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 = m_proxyPool[ nextProxyId ];
-
- nextBound.stabbingCount--;
-
- if (nextBound.IsUpper())
- {
- if (TestOverlap(oldValues, nextProxy))
- {
- m_pairManager.RemoveBufferedPair(proxyId, nextProxyId);
- }
-
- nextProxy.upperBounds[axis]--;
- bound.stabbingCount--;
- }
- else
- {
- nextProxy.lowerBounds[axis]--;
- bound.stabbingCount++;
- }
-
- proxy.lowerBounds[axis]++;
- // swap
- //var temp:b2Bound = bound;
- //bound = nextEdge;
- //nextEdge = temp;
- bound.Swap(nextBound);
- //b2Math.b2Swap(bound, nextEdge);
- 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 = m_proxyPool[ prevProxyId ];
-
- prevBound.stabbingCount--;
-
- if (prevBound.IsLower() == true)
- {
- if (TestOverlap(oldValues, prevProxy))
- {
- m_pairManager.RemoveBufferedPair(proxyId, prevProxyId);
- }
-
- prevProxy.lowerBounds[axis]++;
- bound.stabbingCount--;
- }
- else
- {
- prevProxy.upperBounds[axis]++;
- bound.stabbingCount++;
- }
-
- proxy.upperBounds[axis]--;
- // swap
- //var temp:b2Bound = bound;
- //bound = prevEdge;
- //prevEdge = temp;
- bound.Swap(prevBound);
- //b2Math.b2Swap(bound, prevEdge);
- index--;
- }
- }
- }
- }
-
- public function Commit() : void{
- m_pairManager.Commit();
- }
-
- // Query an AABB for overlapping proxies, returns the user data and
- // the count, up to the supplied maximum count.
- public function QueryAABB(aabb:b2AABB, userData:*, maxCount:int):int{
- var lowerValues:Array = new Array();
- var upperValues:Array = new Array();
- ComputeBounds(lowerValues, upperValues, aabb);
-
- var lowerIndex:uint;
- var upperIndex:uint;
- var lowerIndexOut:Array = [lowerIndex];
- var upperIndexOut:Array = [upperIndex];
- Query(lowerIndexOut, upperIndexOut, lowerValues[0], upperValues[0], m_bounds[0], 2*m_proxyCount, 0);
- Query(lowerIndexOut, upperIndexOut, lowerValues[1], upperValues[1], m_bounds[1], 2*m_proxyCount, 1);