Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DEL obsolete box2d

  • Loading branch information...
commit cfdda16c136c500146d3f433aaadc011a21b8956 1 parent 24cb4f1
unknown authored
Showing with 2,049 additions and 1,816 deletions.
  1. +0 −65 application/lib/box2d/Box2D.h
  2. +0 −168 application/lib/box2d/Collision/b2CollideCircle.cpp
  3. +0 −140 application/lib/box2d/Collision/b2Collision.cpp
  4. +0 −172 application/lib/box2d/Dynamics/Contacts/b2PolyAndCircleContact.cpp
  5. +0 −174 application/lib/box2d/Dynamics/Contacts/b2PolyAndEdgeContact.cpp
  6. +0 −172 application/lib/box2d/Dynamics/Contacts/b2PolyContact.cpp
  7. +67 −0 application/lib/box2d/Include/Box2D.h
  8. +1 −2  application/lib/box2d/{ → Source}/Collision/Shapes/b2CircleShape.cpp
  9. 0  application/lib/box2d/{ → Source}/Collision/Shapes/b2CircleShape.h
  10. +1 −1  application/lib/box2d/{ → Source}/Collision/Shapes/b2EdgeShape.cpp
  11. 0  application/lib/box2d/{ → Source}/Collision/Shapes/b2EdgeShape.h
  12. +11 −0 application/lib/box2d/{ → Source}/Collision/Shapes/b2PolygonShape.cpp
  13. +3 −0  application/lib/box2d/{ → Source}/Collision/Shapes/b2PolygonShape.h
  14. 0  application/lib/box2d/{ → Source}/Collision/Shapes/b2Shape.cpp
  15. 0  application/lib/box2d/{ → Source}/Collision/Shapes/b2Shape.h
  16. 0  application/lib/box2d/{ → Source}/Collision/b2BroadPhase.cpp
  17. 0  application/lib/box2d/{ → Source}/Collision/b2BroadPhase.h
  18. +153 −0 application/lib/box2d/Source/Collision/b2CollideCircle.cpp
  19. +95 −109 application/lib/box2d/{ → Source}/Collision/b2CollideEdge.cpp
  20. +19 −53 application/lib/box2d/{ → Source}/Collision/b2CollidePoly.cpp
  21. +287 −0 application/lib/box2d/Source/Collision/b2Collision.cpp
  22. +78 −11 application/lib/box2d/{ → Source}/Collision/b2Collision.h
  23. 0  application/lib/box2d/{ → Source}/Collision/b2Distance.cpp
  24. 0  application/lib/box2d/{ → Source}/Collision/b2Distance.h
  25. 0  application/lib/box2d/{ → Source}/Collision/b2DynamicTree.cpp
  26. 0  application/lib/box2d/{ → Source}/Collision/b2DynamicTree.h
  27. 0  application/lib/box2d/{ → Source}/Collision/b2PairManager.cpp
  28. 0  application/lib/box2d/{ → Source}/Collision/b2PairManager.h
  29. +8 −6 application/lib/box2d/{ → Source}/Collision/b2TimeOfImpact.cpp
  30. +4 −0 application/lib/box2d/{ → Source}/Collision/b2TimeOfImpact.h
  31. +1 −1  application/lib/box2d/{ → Source}/Common/Fixed.h
  32. 0  application/lib/box2d/{ → Source}/Common/b2BlockAllocator.cpp
  33. 0  application/lib/box2d/{ → Source}/Common/b2BlockAllocator.h
  34. 0  application/lib/box2d/{ → Source}/Common/b2Math.cpp
  35. 0  application/lib/box2d/{ → Source}/Common/b2Math.h
  36. 0  application/lib/box2d/{ → Source}/Common/b2Settings.cpp
  37. +24 −21 application/lib/box2d/{ → Source}/Common/b2Settings.h
  38. 0  application/lib/box2d/{ → Source}/Common/b2StackAllocator.cpp
  39. 0  application/lib/box2d/{ → Source}/Common/b2StackAllocator.h
  40. 0  application/lib/box2d/{ → Source}/Common/jtypes.h
  41. +1 −71 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2CircleContact.cpp
  42. +1 −7 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2CircleContact.h
  43. +8 −41 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2Contact.cpp
  44. +98 −40 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2Contact.h
  45. +270 −292 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2ContactSolver.cpp
  46. +6 −4 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2ContactSolver.h
  47. +4 −71 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2EdgeAndCircleContact.cpp
  48. +1 −8 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2EdgeAndCircleContact.h
  49. +1 −2  application/lib/box2d/{ → Source}/Dynamics/Contacts/b2NullContact.h
  50. +68 −0 application/lib/box2d/Source/Dynamics/Contacts/b2PolyAndCircleContact.cpp
  51. +1 −7 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2PolyAndCircleContact.h
  52. +70 −0 application/lib/box2d/Source/Dynamics/Contacts/b2PolyAndEdgeContact.cpp
  53. +1 −8 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2PolyAndEdgeContact.h
  54. +68 −0 application/lib/box2d/Source/Dynamics/Contacts/b2PolyContact.cpp
  55. +1 −7 application/lib/box2d/{ → Source}/Dynamics/Contacts/b2PolyContact.h
  56. +2 −2 application/lib/box2d/{ → Source}/Dynamics/Controllers/b2BuoyancyController.cpp
  57. +1 −1  application/lib/box2d/{ → Source}/Dynamics/Controllers/b2BuoyancyController.h
  58. +2 −2 application/lib/box2d/{ → Source}/Dynamics/Controllers/b2ConstantAccelController.cpp
  59. +1 −1  application/lib/box2d/{ → Source}/Dynamics/Controllers/b2ConstantAccelController.h
  60. +2 −2 application/lib/box2d/{ → Source}/Dynamics/Controllers/b2ConstantForceController.cpp
  61. +1 −1  application/lib/box2d/{ → Source}/Dynamics/Controllers/b2ConstantForceController.h
  62. 0  application/lib/box2d/{ → Source}/Dynamics/Controllers/b2Controller.cpp
  63. +19 −1 application/lib/box2d/{ → Source}/Dynamics/Controllers/b2Controller.h
  64. +2 −2 application/lib/box2d/{ → Source}/Dynamics/Controllers/b2GravityController.cpp
  65. +1 −1  application/lib/box2d/{ → Source}/Dynamics/Controllers/b2GravityController.h
  66. +2 −2 application/lib/box2d/{ → Source}/Dynamics/Controllers/b2TensorDampingController.cpp
  67. +1 −1  application/lib/box2d/{ → Source}/Dynamics/Controllers/b2TensorDampingController.h
  68. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2DistanceJoint.cpp
  69. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2DistanceJoint.h
  70. +149 −0 application/lib/box2d/Source/Dynamics/Joints/b2FixedJoint.cpp
  71. +57 −0 application/lib/box2d/Source/Dynamics/Joints/b2FixedJoint.h
  72. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2GearJoint.cpp
  73. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2GearJoint.h
  74. +12 −0 application/lib/box2d/{ → Source}/Dynamics/Joints/b2Joint.cpp
  75. +4 −3 application/lib/box2d/{ → Source}/Dynamics/Joints/b2Joint.h
  76. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2LineJoint.cpp
  77. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2LineJoint.h
  78. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2MouseJoint.cpp
  79. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2MouseJoint.h
  80. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2PrismaticJoint.cpp
  81. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2PrismaticJoint.h
  82. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2PulleyJoint.cpp
  83. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2PulleyJoint.h
  84. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2RevoluteJoint.cpp
  85. 0  application/lib/box2d/{ → Source}/Dynamics/Joints/b2RevoluteJoint.h
  86. +0 −33 application/lib/box2d/{ → Source}/Dynamics/b2Body.cpp
  87. +29 −2 application/lib/box2d/{ → Source}/Dynamics/b2Body.h
  88. +126 −31 application/lib/box2d/{ → Source}/Dynamics/b2ContactManager.cpp
  89. +14 −1 application/lib/box2d/{ → Source}/Dynamics/b2ContactManager.h
  90. 0  application/lib/box2d/{ → Source}/Dynamics/b2EdgeChain.cpp
  91. 0  application/lib/box2d/{ → Source}/Dynamics/b2EdgeChain.h
  92. 0  application/lib/box2d/{ → Source}/Dynamics/b2Fixture.cpp
  93. 0  application/lib/box2d/{ → Source}/Dynamics/b2Fixture.h
  94. +35 −28 application/lib/box2d/{ → Source}/Dynamics/b2Island.cpp
  95. +1 −1  application/lib/box2d/{ → Source}/Dynamics/b2Island.h
  96. +38 −27 application/lib/box2d/{ → Source}/Dynamics/b2World.cpp
  97. +12 −1 application/lib/box2d/{ → Source}/Dynamics/b2World.h
  98. +0 −2  application/lib/box2d/{ → Source}/Dynamics/b2WorldCallbacks.cpp
  99. +43 −18 application/lib/box2d/{ → Source}/Dynamics/b2WorldCallbacks.h
  100. +144 −0 application/lib/box2d/Source/Makefile
View
65 application/lib/box2d/Box2D.h
@@ -1,65 +0,0 @@
-/*
-* Copyright (c) 2006-2009 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.
-*/
-
-#ifndef BOX2D_H
-#define BOX2D_H
-
-/**
-\mainpage Box2D API Documentation
-
-\section intro_sec Getting Started
-
-For tutorials please see http://www.box2d.org/manual.html
-
-For discussion please visit http://www.box2d.org/forum
-*/
-
-// These include files constitute the main Box2D API
-
-#include "Common/b2Settings.h"
-
-#include "Collision/Shapes/b2CircleShape.h"
-#include "Collision/Shapes/b2PolygonShape.h"
-#include "Collision/Shapes/b2EdgeShape.h"
-#include "Collision/b2BroadPhase.h"
-#include "Collision/b2Distance.h"
-#include "Collision/b2DynamicTree.h"
-#include "Collision/b2TimeOfImpact.h"
-#include "Dynamics/b2Body.h"
-#include "Dynamics/b2EdgeChain.h"
-#include "Dynamics/b2Fixture.h"
-#include "Dynamics/b2WorldCallbacks.h"
-#include "Dynamics/b2World.h"
-
-#include "Dynamics/Contacts/b2Contact.h"
-
-#include "Dynamics/Joints/b2DistanceJoint.h"
-#include "Dynamics/Joints/b2GearJoint.h"
-#include "Dynamics/Joints/b2LineJoint.h"
-#include "Dynamics/Joints/b2MouseJoint.h"
-#include "Dynamics/Joints/b2PrismaticJoint.h"
-#include "Dynamics/Joints/b2PulleyJoint.h"
-#include "Dynamics/Joints/b2RevoluteJoint.h"
-
-#include "Dynamics/Controllers/b2BuoyancyController.h"
-#include "Dynamics/Controllers/b2ConstantForceController.h"
-#include "Dynamics/Controllers/b2ConstantAccelController.h"
-#include "Dynamics/Controllers/b2GravityController.h"
-#include "Dynamics/Controllers/b2TensorDampingController.h"
-
-#endif
View
168 application/lib/box2d/Collision/b2CollideCircle.cpp
@@ -1,168 +0,0 @@
-/*
-* Copyright (c) 2007-2009 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.
-*/
-
-#include "b2Collision.h"
-#include "Shapes/b2CircleShape.h"
-#include "Shapes/b2PolygonShape.h"
-
-void b2CollideCircles(
- b2Manifold* manifold,
- const b2CircleShape* circle1, const b2XForm& xf1,
- const b2CircleShape* circle2, const b2XForm& xf2)
-{
- manifold->pointCount = 0;
-
- b2Vec2 p1 = b2Mul(xf1, circle1->m_p);
- b2Vec2 p2 = b2Mul(xf2, circle2->m_p);
-
- b2Vec2 d = p2 - p1;
- float32 distSqr = b2Dot(d, d);
- float32 r1 = circle1->m_radius;
- float32 r2 = circle2->m_radius;
- float32 radiusSum = r1 + r2;
- if (distSqr > radiusSum * radiusSum)
- {
- return;
- }
-
- float32 separation;
- if (distSqr < B2_FLT_EPSILON)
- {
- separation = -radiusSum;
- manifold->normal.Set(0.0f, 1.0f);
- }
- else
- {
- float32 dist = b2Sqrt(distSqr);
- separation = dist - radiusSum;
- float32 a = 1.0f / dist;
- manifold->normal.x = a * d.x;
- manifold->normal.y = a * d.y;
- }
-
- manifold->pointCount = 1;
- manifold->points[0].id.key = 0;
- manifold->points[0].separation = separation;
-
- p1 += r1 * manifold->normal;
- p2 -= r2 * manifold->normal;
-
- b2Vec2 p = 0.5f * (p1 + p2);
-
- manifold->points[0].localPointA = b2MulT(xf1, p);
- manifold->points[0].localPointB = b2MulT(xf2, p);
-}
-
-void b2CollidePolygonAndCircle(
- b2Manifold* manifold,
- const b2PolygonShape* polygon, const b2XForm& xf1,
- const b2CircleShape* circle, const b2XForm& xf2)
-{
- manifold->pointCount = 0;
-
- // Compute circle position in the frame of the polygon.
- b2Vec2 c = b2Mul(xf2, circle->m_p);
- b2Vec2 cLocal = b2MulT(xf1, c);
-
- // Find the min separating edge.
- int32 normalIndex = 0;
- float32 separation = -B2_FLT_MAX;
- float32 radius = polygon->m_radius + circle->m_radius;
- int32 vertexCount = polygon->m_vertexCount;
- const b2Vec2* vertices = polygon->m_vertices;
- const b2Vec2* normals = polygon->m_normals;
-
- for (int32 i = 0; i < vertexCount; ++i)
- {
- float32 s = b2Dot(normals[i], cLocal - vertices[i]);
-
- if (s > radius)
- {
- // Early out.
- return;
- }
-
- if (s > separation)
- {
- separation = s;
- normalIndex = i;
- }
- }
-
- // If the center is inside the polygon ...
- if (separation < B2_FLT_EPSILON)
- {
- manifold->pointCount = 1;
- manifold->normal = b2Mul(xf1.R, normals[normalIndex]);
- manifold->points[0].id.features.incidentEdge = (uint8)normalIndex;
- manifold->points[0].id.features.incidentVertex = b2_nullFeature;
- manifold->points[0].id.features.referenceEdge = 0;
- manifold->points[0].id.features.flip = 0;
- b2Vec2 position = c - radius * manifold->normal;
- manifold->points[0].localPointA = b2MulT(xf1, position);
- manifold->points[0].localPointB = b2MulT(xf2, position);
- manifold->points[0].separation = separation - radius;
- return;
- }
-
- // Project the circle center onto the edge segment.
- int32 vertIndex1 = normalIndex;
- int32 vertIndex2 = vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0;
- b2Vec2 e = vertices[vertIndex2] - vertices[vertIndex1];
-
- float32 length = e.Normalize();
- b2Assert(length > B2_FLT_EPSILON);
-
- // Project the center onto the edge.
- float32 u = b2Dot(cLocal - vertices[vertIndex1], e);
- b2Vec2 p;
- if (u <= 0.0f)
- {
- p = vertices[vertIndex1];
- manifold->points[0].id.features.incidentEdge = b2_nullFeature;
- manifold->points[0].id.features.incidentVertex = (uint8)vertIndex1;
- }
- else if (u >= length)
- {
- p = vertices[vertIndex2];
- manifold->points[0].id.features.incidentEdge = b2_nullFeature;
- manifold->points[0].id.features.incidentVertex = (uint8)vertIndex2;
- }
- else
- {
- p = vertices[vertIndex1] + u * e;
- manifold->points[0].id.features.incidentEdge = (uint8)normalIndex;
- manifold->points[0].id.features.incidentVertex = b2_nullFeature;
- }
-
- b2Vec2 d = cLocal - p;
- float32 dist = d.Normalize();
- if (dist > radius)
- {
- return;
- }
-
- manifold->pointCount = 1;
- manifold->normal = b2Mul(xf1.R, d);
- b2Vec2 position = c - radius * manifold->normal;
- manifold->points[0].localPointA = b2MulT(xf1, position);
- manifold->points[0].localPointB = b2MulT(xf2, position);
- manifold->points[0].separation = dist - radius;
- manifold->points[0].id.features.referenceEdge = 0;
- manifold->points[0].id.features.flip = 0;
-}
View
140 application/lib/box2d/Collision/b2Collision.cpp
@@ -1,140 +0,0 @@
-/*
-* Copyright (c) 2007-2009 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.
-*/
-
-#include "b2Collision.h"
-
-// Collision Detection in Interactive 3D Environments by Gino van den Bergen
-// From Section 3.4.1
-// x = mu1 * p1 + mu2 * p2
-// mu1 + mu2 = 1 && mu1 >= 0 && mu2 >= 0
-// mu1 = 1 - mu2;
-// x = (1 - mu2) * p1 + mu2 * p2
-// = p1 + mu2 * (p2 - p1)
-// x = s + a * r (s := start, r := end - start)
-// s + a * r = p1 + mu2 * d (d := p2 - p1)
-// -a * r + mu2 * d = b (b := s - p1)
-// [-r d] * [a; mu2] = b
-// Cramer's rule:
-// denom = det[-r d]
-// a = det[b d] / denom
-// mu2 = det[-r b] / denom
-bool b2Segment::TestSegment(float32* lambda, b2Vec2* normal, const b2Segment& segment, float32 maxLambda) const
-{
- b2Vec2 s = segment.p1;
- b2Vec2 r = segment.p2 - s;
- b2Vec2 d = p2 - p1;
- b2Vec2 n = b2Cross(d, 1.0f);
-
- const float32 k_slop = 100.0f * B2_FLT_EPSILON;
- float32 denom = -b2Dot(r, n);
-
- // Cull back facing collision and ignore parallel segments.
- if (denom > k_slop)
- {
- // Does the segment intersect the infinite line associated with this segment?
- b2Vec2 b = s - p1;
- float32 a = b2Dot(b, n);
-
- if (0.0f <= a && a <= maxLambda * denom)
- {
- float32 mu2 = -r.x * b.y + r.y * b.x;
-
- // Does the segment intersect this segment?
- if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0f + k_slop))
- {
- a /= denom;
- n.Normalize();
- *lambda = a;
- *normal = n;
- return true;
- }
- }
- }
-
- return false;
-}
-
-// From Real-time Collision Detection, p179.
-void b2AABB::RayCast(b2RayCastOutput* output, const b2RayCastInput& input)
-{
- float32 tmin = -B2_FLT_MAX;
- float32 tmax = B2_FLT_MAX;
-
- output->hit = false;
-
- b2Vec2 p = input.p1;
- b2Vec2 d = input.p2 - input.p1;
- b2Vec2 absD = b2Abs(d);
-
- b2Vec2 normal;
-
- for (int32 i = 0; i < 2; ++i)
- {
- if (absD(i) < B2_FLT_EPSILON)
- {
- // Parallel.
- if (p(i) < lowerBound(i) || upperBound(i) < p(i))
- {
- return;
- }
- }
- else
- {
- float32 inv_d = 1.0f / d(i);
- float32 t1 = (lowerBound(i) - p(i)) * inv_d;
- float32 t2 = (upperBound(i) - p(i)) * inv_d;
-
- // Sign of the normal vector.
- float32 s = -1.0f;
-
- if (t1 > t2)
- {
- b2Swap(t1, t2);
- s = 1.0f;
- }
-
- // Push the min up
- if (t1 > tmin)
- {
- normal.SetZero();
- normal(i) = s;
- tmin = t1;
- }
-
- // Pull the max down
- tmax = b2Min(tmax, t2);
-
- if (tmin > tmax)
- {
- return;
- }
- }
- }
-
- // Does the ray start inside the box?
- // Does the ray intersect beyond the max fraction?
- if (tmin < 0.0f || input.maxFraction < tmin)
- {
- return;
- }
-
- // Intersection.
- output->fraction = tmin;
- output->normal = normal;
- output->hit = true;
-}
View
172 application/lib/box2d/Dynamics/Contacts/b2PolyAndCircleContact.cpp
@@ -1,172 +0,0 @@
-/*
-* Copyright (c) 2006-2009 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.
-*/
-
-#include "b2PolyAndCircleContact.h"
-#include "../b2Body.h"
-#include "../b2Fixture.h"
-#include "../b2WorldCallbacks.h"
-#include "../../Collision/b2TimeOfImpact.h"
-#include "../../Common/b2BlockAllocator.h"
-
-#include <new.h>
-#include <string.h>
-
-b2Contact* b2PolyAndCircleContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)
-{
- void* mem = allocator->Allocate(sizeof(b2PolyAndCircleContact));
- return new (mem) b2PolyAndCircleContact(fixtureA, fixtureB);
-}
-
-void b2PolyAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
-{
- ((b2PolyAndCircleContact*)contact)->~b2PolyAndCircleContact();
- allocator->Free(contact, sizeof(b2PolyAndCircleContact));
-}
-
-b2PolyAndCircleContact::b2PolyAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
-: b2Contact(fixtureA, fixtureB)
-{
- b2Assert(m_fixtureA->GetType() == b2_polygonShape);
- b2Assert(m_fixtureB->GetType() == b2_circleShape);
- m_manifold.pointCount = 0;
-}
-
-void b2PolyAndCircleContact::Evaluate(b2ContactListener* listener)
-{
- b2Body* bodyA = m_fixtureA->GetBody();
- b2Body* bodyB = m_fixtureB->GetBody();
-
- b2Manifold m0;
- memcpy(&m0, &m_manifold, sizeof(b2Manifold));
-
- b2CollidePolygonAndCircle( &m_manifold,
- (b2PolygonShape*)m_fixtureA->GetShape(), bodyA->GetXForm(),
- (b2CircleShape*)m_fixtureB->GetShape(), bodyB->GetXForm());
-
- bool persisted[b2_maxManifoldPoints] = {false, false};
-
- b2ContactPoint cp;
- cp.fixtureA = m_fixtureA;
- cp.fixtureB = m_fixtureB;
- cp.friction = b2MixFriction(m_fixtureA->GetFriction(), m_fixtureB->GetFriction());
- cp.restitution = b2MixRestitution(m_fixtureA->GetRestitution(), m_fixtureB->GetRestitution());
-
- // Match contact ids to facilitate warm starting.
- if (m_manifold.pointCount > 0)
- {
- // Match old contact ids to new contact ids and copy the
- // stored impulses to warm start the solver.
- for (int32 i = 0; i < m_manifold.pointCount; ++i)
- {
- b2ManifoldPoint* mp = m_manifold.points + i;
- mp->normalImpulse = 0.0f;
- mp->tangentImpulse = 0.0f;
- bool found = false;
- b2ContactID id = mp->id;
-
- for (int32 j = 0; j < m0.pointCount; ++j)
- {
- if (persisted[j] == true)
- {
- continue;
- }
-
- b2ManifoldPoint* mp0 = m0.points + j;
-
- if (mp0->id.key == id.key)
- {
- persisted[j] = true;
- mp->normalImpulse = mp0->normalImpulse;
- mp->tangentImpulse = mp0->tangentImpulse;
-
- // A persistent point.
- found = true;
-
- // Report persistent point.
- if (listener != NULL)
- {
- cp.position = bodyA->GetWorldPoint(mp->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m_manifold.normal;
- cp.separation = mp->separation;
- cp.id = id;
- listener->Persist(&cp);
- }
- break;
- }
- }
-
- // Report added point.
- if (found == false && listener != NULL)
- {
- cp.position = bodyA->GetWorldPoint(mp->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m_manifold.normal;
- cp.separation = mp->separation;
- cp.id = id;
- listener->Add(&cp);
- }
- }
-
- m_manifoldCount = 1;
- }
- else
- {
- m_manifoldCount = 0;
- }
-
- if (listener == NULL)
- {
- return;
- }
-
- // Report removed points.
- for (int32 i = 0; i < m0.pointCount; ++i)
- {
- if (persisted[i])
- {
- continue;
- }
-
- b2ManifoldPoint* mp0 = m0.points + i;
- cp.position = bodyA->GetWorldPoint(mp0->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp0->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp0->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m0.normal;
- cp.separation = mp0->separation;
- cp.id = mp0->id;
- listener->Remove(&cp);
- }
-}
-
-float32 b2PolyAndCircleContact::ComputeTOI(const b2Sweep& sweepA, const b2Sweep& sweepB) const
-{
- b2TOIInput input;
- input.sweepA = sweepA;
- input.sweepB = sweepB;
- input.sweepRadiusA = m_fixtureA->ComputeSweepRadius(sweepA.localCenter);
- input.sweepRadiusB = m_fixtureB->ComputeSweepRadius(sweepB.localCenter);
- input.tolerance = b2_linearSlop;
-
- return b2TimeOfImpact(&input, (const b2PolygonShape*)m_fixtureA->GetShape(), (const b2CircleShape*)m_fixtureB->GetShape());
-}
View
174 application/lib/box2d/Dynamics/Contacts/b2PolyAndEdgeContact.cpp
@@ -1,174 +0,0 @@
-/*
-* Copyright (c) 2006-2009 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.
-*/
-
-#include "b2PolyAndEdgeContact.h"
-#include "../b2Body.h"
-#include "../b2Fixture.h"
-#include "../b2WorldCallbacks.h"
-#include "../../Collision/Shapes/b2EdgeShape.h"
-#include "../../Collision/Shapes/b2PolygonShape.h"
-#include "../../Collision/b2TimeOfImpact.h"
-#include "../../Common/b2BlockAllocator.h"
-
-#include <new.h>
-#include <string.h>
-
-b2Contact* b2PolyAndEdgeContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)
-{
- void* mem = allocator->Allocate(sizeof(b2PolyAndEdgeContact));
- return new (mem) b2PolyAndEdgeContact(fixtureA, fixtureB);
-}
-
-void b2PolyAndEdgeContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
-{
- ((b2PolyAndEdgeContact*)contact)->~b2PolyAndEdgeContact();
- allocator->Free(contact, sizeof(b2PolyAndEdgeContact));
-}
-
-b2PolyAndEdgeContact::b2PolyAndEdgeContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
-: b2Contact(fixtureA, fixtureB)
-{
- b2Assert(m_fixtureA->GetType() == b2_polygonShape);
- b2Assert(m_fixtureB->GetType() == b2_edgeShape);
- m_manifold.pointCount = 0;
-}
-
-void b2PolyAndEdgeContact::Evaluate(b2ContactListener* listener)
-{
- b2Body* bodyA = m_fixtureA->GetBody();
- b2Body* bodyB = m_fixtureB->GetBody();
-
- b2Manifold m0;
- memcpy(&m0, &m_manifold, sizeof(b2Manifold));
-
- b2CollidePolyAndEdge( &m_manifold,
- (b2PolygonShape*)m_fixtureA->GetShape(), bodyA->GetXForm(),
- (b2EdgeShape*)m_fixtureB->GetShape(), bodyB->GetXForm());
-
- bool persisted[b2_maxManifoldPoints] = {false, false};
-
- b2ContactPoint cp;
- cp.fixtureA = m_fixtureA;
- cp.fixtureB = m_fixtureB;
- cp.friction = b2MixFriction(m_fixtureA->GetFriction(), m_fixtureB->GetFriction());
- cp.restitution = b2MixRestitution(m_fixtureA->GetRestitution(), m_fixtureB->GetRestitution());
-
- // Match contact ids to facilitate warm starting.
- if (m_manifold.pointCount > 0)
- {
- // Match old contact ids to new contact ids and copy the
- // stored impulses to warm start the solver.
- for (int32 i = 0; i < m_manifold.pointCount; ++i)
- {
- b2ManifoldPoint* mp = m_manifold.points + i;
- mp->normalImpulse = 0.0f;
- mp->tangentImpulse = 0.0f;
- bool found = false;
- b2ContactID id = mp->id;
-
- for (int32 j = 0; j < m0.pointCount; ++j)
- {
- if (persisted[j] == true)
- {
- continue;
- }
-
- b2ManifoldPoint* mp0 = m0.points + j;
-
- if (mp0->id.key == id.key)
- {
- persisted[j] = true;
- mp->normalImpulse = mp0->normalImpulse;
- mp->tangentImpulse = mp0->tangentImpulse;
-
- // A persistent point.
- found = true;
-
- // Report persistent point.
- if (listener != NULL)
- {
- cp.position = bodyA->GetWorldPoint(mp->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m_manifold.normal;
- cp.separation = mp->separation;
- cp.id = id;
- listener->Persist(&cp);
- }
- break;
- }
- }
-
- // Report added point.
- if (found == false && listener != NULL)
- {
- cp.position = bodyA->GetWorldPoint(mp->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m_manifold.normal;
- cp.separation = mp->separation;
- cp.id = id;
- listener->Add(&cp);
- }
- }
-
- m_manifoldCount = 1;
- }
- else
- {
- m_manifoldCount = 0;
- }
-
- if (listener == NULL)
- {
- return;
- }
-
- // Report removed points.
- for (int32 i = 0; i < m0.pointCount; ++i)
- {
- if (persisted[i])
- {
- continue;
- }
-
- b2ManifoldPoint* mp0 = m0.points + i;
- cp.position = bodyA->GetWorldPoint(mp0->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp0->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp0->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m0.normal;
- cp.separation = mp0->separation;
- cp.id = mp0->id;
- listener->Remove(&cp);
- }
-}
-
-float32 b2PolyAndEdgeContact::ComputeTOI(const b2Sweep& sweepA, const b2Sweep& sweepB) const
-{
- b2TOIInput input;
- input.sweepA = sweepA;
- input.sweepB = sweepB;
- input.sweepRadiusA = m_fixtureA->ComputeSweepRadius(sweepA.localCenter);
- input.sweepRadiusB = m_fixtureB->ComputeSweepRadius(sweepB.localCenter);
- input.tolerance = b2_linearSlop;
-
- return b2TimeOfImpact(&input, (const b2PolygonShape*)m_fixtureA->GetShape(), (const b2EdgeShape*)m_fixtureB->GetShape());
-}
View
172 application/lib/box2d/Dynamics/Contacts/b2PolyContact.cpp
@@ -1,172 +0,0 @@
-/*
-* Copyright (c) 2006-2009 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.
-*/
-
-#include "b2PolyContact.h"
-#include "../b2Body.h"
-#include "../b2Fixture.h"
-#include "../b2WorldCallbacks.h"
-#include "../../Collision/b2TimeOfImpact.h"
-#include "../../Common/b2BlockAllocator.h"
-
-#include <new>
-#include <string.h>
-
-b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)
-{
- void* mem = allocator->Allocate(sizeof(b2PolygonContact));
- return new (mem) b2PolygonContact(fixtureA, fixtureB);
-}
-
-void b2PolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
-{
- ((b2PolygonContact*)contact)->~b2PolygonContact();
- allocator->Free(contact, sizeof(b2PolygonContact));
-}
-
-b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB)
- : b2Contact(fixtureA, fixtureB)
-{
- b2Assert(m_fixtureA->GetType() == b2_polygonShape);
- b2Assert(m_fixtureB->GetType() == b2_polygonShape);
- m_manifold.pointCount = 0;
-}
-
-void b2PolygonContact::Evaluate(b2ContactListener* listener)
-{
- b2Body* bodyA = m_fixtureA->GetBody();
- b2Body* bodyB = m_fixtureB->GetBody();
-
- b2Manifold m0;
- memcpy(&m0, &m_manifold, sizeof(b2Manifold));
-
- b2CollidePolygons( &m_manifold,
- (b2PolygonShape*)m_fixtureA->GetShape(), bodyA->GetXForm(),
- (b2PolygonShape*)m_fixtureB->GetShape(), bodyB->GetXForm());
-
- bool persisted[b2_maxManifoldPoints] = {false, false};
-
- b2ContactPoint cp;
- cp.fixtureA = m_fixtureA;
- cp.fixtureB = m_fixtureB;
- cp.friction = b2MixFriction(m_fixtureA->GetFriction(), m_fixtureB->GetFriction());
- cp.restitution = b2MixRestitution(m_fixtureA->GetRestitution(), m_fixtureB->GetRestitution());
-
- // Match contact ids to facilitate warm starting.
- if (m_manifold.pointCount > 0)
- {
- // Match old contact ids to new contact ids and copy the
- // stored impulses to warm start the solver.
- for (int32 i = 0; i < m_manifold.pointCount; ++i)
- {
- b2ManifoldPoint* mp = m_manifold.points + i;
- mp->normalImpulse = 0.0f;
- mp->tangentImpulse = 0.0f;
- bool found = false;
- b2ContactID id = mp->id;
-
- for (int32 j = 0; j < m0.pointCount; ++j)
- {
- if (persisted[j] == true)
- {
- continue;
- }
-
- b2ManifoldPoint* mp0 = m0.points + j;
-
- if (mp0->id.key == id.key)
- {
- persisted[j] = true;
- mp->normalImpulse = mp0->normalImpulse;
- mp->tangentImpulse = mp0->tangentImpulse;
-
- // A persistent point.
- found = true;
-
- // Report persistent point.
- if (listener != NULL)
- {
- cp.position = bodyA->GetWorldPoint(mp->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m_manifold.normal;
- cp.separation = mp->separation;
- cp.id = id;
- listener->Persist(&cp);
- }
- break;
- }
- }
-
- // Report added point.
- if (found == false && listener != NULL)
- {
- cp.position = bodyA->GetWorldPoint(mp->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m_manifold.normal;
- cp.separation = mp->separation;
- cp.id = id;
- listener->Add(&cp);
- }
- }
-
- m_manifoldCount = 1;
- }
- else
- {
- m_manifoldCount = 0;
- }
-
- if (listener == NULL)
- {
- return;
- }
-
- // Report removed points.
- for (int32 i = 0; i < m0.pointCount; ++i)
- {
- if (persisted[i])
- {
- continue;
- }
-
- b2ManifoldPoint* mp0 = m0.points + i;
- cp.position = bodyA->GetWorldPoint(mp0->localPointA);
- b2Vec2 vA = bodyA->GetLinearVelocityFromLocalPoint(mp0->localPointA);
- b2Vec2 vB = bodyB->GetLinearVelocityFromLocalPoint(mp0->localPointB);
- cp.velocity = vB - vA;
- cp.normal = m0.normal;
- cp.separation = mp0->separation;
- cp.id = mp0->id;
- listener->Remove(&cp);
- }
-}
-
-float32 b2PolygonContact::ComputeTOI(const b2Sweep& sweepA, const b2Sweep& sweepB) const
-{
- b2TOIInput input;
- input.sweepA = sweepA;
- input.sweepB = sweepB;
- input.sweepRadiusA = m_fixtureA->ComputeSweepRadius(sweepA.localCenter);
- input.sweepRadiusB = m_fixtureB->ComputeSweepRadius(sweepB.localCenter);
- input.tolerance = b2_linearSlop;
-
- return b2TimeOfImpact(&input, (const b2PolygonShape*)m_fixtureA->GetShape(), (const b2PolygonShape*)m_fixtureB->GetShape());
-}
View
67 application/lib/box2d/Include/Box2D.h
@@ -0,0 +1,67 @@
+/*
+* Copyright (c) 2006-2009 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.
+*/
+
+#ifndef BOX2D_H
+#define BOX2D_H
+
+/**
+\mainpage Box2D API Documentation
+
+\section intro_sec Getting Started
+
+For tutorials please see http://www.box2d.org/manual.html
+
+For discussion please visit http://www.box2d.org/forum
+*/
+
+// These include files constitute the main Box2D API
+
+#include "../Source/Common/b2Settings.h"
+
+#include "../Source/Collision/Shapes/b2CircleShape.h"
+#include "../Source/Collision/Shapes/b2PolygonShape.h"
+#include "../Source/Collision/Shapes/b2EdgeShape.h"
+#include "../Source/Collision/b2BroadPhase.h"
+#include "../Source/Collision/b2Distance.h"
+#include "../Source/Collision/b2DynamicTree.h"
+#include "../Source/Collision/b2TimeOfImpact.h"
+#include "../Source/Dynamics/b2Body.h"
+#include "../Source/Dynamics/b2EdgeChain.h"
+#include "../Source/Dynamics/b2Fixture.h"
+#include "../Source/Dynamics/b2WorldCallbacks.h"
+#include "../Source/Dynamics/b2World.h"
+
+#include "../Source/Dynamics/Contacts/b2Contact.h"
+
+#include "../Source/Dynamics/Joints/b2DistanceJoint.h"
+#include "../Source/Dynamics/Joints/b2GearJoint.h"
+#include "../Source/Dynamics/Joints/b2LineJoint.h"
+#include "../Source/Dynamics/Joints/b2MouseJoint.h"
+#include "../Source/Dynamics/Joints/b2PrismaticJoint.h"
+#include "../Source/Dynamics/Joints/b2PulleyJoint.h"
+#include "../Source/Dynamics/Joints/b2RevoluteJoint.h"
+#include "../Source/Dynamics/Joints/b2FixedJoint.h"
+
+
+#include "../Source/Dynamics/Controllers/b2BuoyancyController.h"
+#include "../Source/Dynamics/Controllers/b2ConstantForceController.h"
+#include "../Source/Dynamics/Controllers/b2ConstantAccelController.h"
+#include "../Source/Dynamics/Controllers/b2GravityController.h"
+#include "../Source/Dynamics/Controllers/b2TensorDampingController.h"
+
+#endif
View
3  ...tion/lib/box2d/Collision/Shapes/b2CircleShape.cpp → ...b/box2d/Source/Collision/Shapes/b2CircleShape.cpp
@@ -111,8 +111,7 @@ float32 b2CircleShape::ComputeSubmergedArea( const b2Vec2& normal,
//Magic
float32 r2 = m_radius*m_radius;
float32 l2 = l*l;
- //TODO: write b2Sqrt to handle fixed point case.
- float32 area = r2 * (asin(l/m_radius) + b2_pi/2.0f)+ l * b2Sqrt(r2 - l2);
+ float32 area = r2 * (asinf(l/m_radius) + b2_pi/2.0f)+ l * b2Sqrt(r2 - l2);
float32 com = -2.0f/3.0f*pow(r2-l2,1.5f)/area;
c->x = p.x + normal.x * com;
View
0  ...cation/lib/box2d/Collision/Shapes/b2CircleShape.h → ...lib/box2d/Source/Collision/Shapes/b2CircleShape.h
File renamed without changes
View
2  ...cation/lib/box2d/Collision/Shapes/b2EdgeShape.cpp → ...lib/box2d/Source/Collision/Shapes/b2EdgeShape.cpp
@@ -46,7 +46,7 @@ void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)
m_direction = m_v2 - m_v1;
m_length = m_direction.Normalize();
- m_normal.Set(m_direction.y, -m_direction.x);
+ m_normal = b2Cross(m_direction, 1.0f);
m_cornerDir1 = m_normal;
m_cornerDir2 = -1.0f * m_normal;
View
0  application/lib/box2d/Collision/Shapes/b2EdgeShape.h → ...n/lib/box2d/Source/Collision/Shapes/b2EdgeShape.h
File renamed without changes
View
11 ...ion/lib/box2d/Collision/Shapes/b2PolygonShape.cpp → .../box2d/Source/Collision/Shapes/b2PolygonShape.cpp
@@ -57,6 +57,17 @@ void b2PolygonShape::SetAsBox(float32 hx, float32 hy, const b2Vec2& center, floa
}
}
+void b2PolygonShape::SetAsEdge(const b2Vec2& v1, const b2Vec2& v2)
+{
+ m_vertexCount = 2;
+ m_vertices[0] = v1;
+ m_vertices[1] = v2;
+ m_centroid = 0.5f * (v1 + v2);
+ m_normals[0] = b2Cross(v2 - v1, 1.0f);
+ m_normals[0].Normalize();
+ m_normals[1] = -m_normals[0];
+}
+
static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)
{
b2Assert(count >= 3);
View
3  ...ation/lib/box2d/Collision/Shapes/b2PolygonShape.h → ...ib/box2d/Source/Collision/Shapes/b2PolygonShape.h
@@ -44,6 +44,9 @@ class b2PolygonShape : public b2Shape
/// @param angle the rotation of the box in local coordinates.
void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
+ /// Set this as a single edge.
+ void SetAsEdge(const b2Vec2& v1, const b2Vec2& v2);
+
/// @see b2Shape::TestPoint
bool TestPoint(const b2XForm& transform, const b2Vec2& p) const;
View
0  application/lib/box2d/Collision/Shapes/b2Shape.cpp → ...ion/lib/box2d/Source/Collision/Shapes/b2Shape.cpp
File renamed without changes
View
0  application/lib/box2d/Collision/Shapes/b2Shape.h → ...ation/lib/box2d/Source/Collision/Shapes/b2Shape.h
File renamed without changes
View
0  application/lib/box2d/Collision/b2BroadPhase.cpp → ...ation/lib/box2d/Source/Collision/b2BroadPhase.cpp
File renamed without changes
View
0  application/lib/box2d/Collision/b2BroadPhase.h → ...ication/lib/box2d/Source/Collision/b2BroadPhase.h
File renamed without changes
View
153 application/lib/box2d/Source/Collision/b2CollideCircle.cpp
@@ -0,0 +1,153 @@
+/*
+* Copyright (c) 2007-2009 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.
+*/
+
+#include "b2Collision.h"
+#include "Shapes/b2CircleShape.h"
+#include "Shapes/b2PolygonShape.h"
+
+void b2CollideCircles(
+ b2Manifold* manifold,
+ const b2CircleShape* circle1, const b2XForm& xf1,
+ const b2CircleShape* circle2, const b2XForm& xf2)
+{
+ manifold->m_pointCount = 0;
+
+ b2Vec2 p1 = b2Mul(xf1, circle1->m_p);
+ b2Vec2 p2 = b2Mul(xf2, circle2->m_p);
+
+ b2Vec2 d = p2 - p1;
+ float32 distSqr = b2Dot(d, d);
+ float32 radius = circle1->m_radius + circle2->m_radius;
+ if (distSqr > radius * radius)
+ {
+ return;
+ }
+
+ manifold->m_type = b2Manifold::e_circles;
+ manifold->m_localPoint = circle1->m_p;
+ manifold->m_localPlaneNormal.SetZero();
+ manifold->m_pointCount = 1;
+
+ manifold->m_points[0].m_localPoint = circle2->m_p;
+ manifold->m_points[0].m_id.key = 0;
+}
+
+void b2CollidePolygonAndCircle(
+ b2Manifold* manifold,
+ const b2PolygonShape* polygon, const b2XForm& xf1,
+ const b2CircleShape* circle, const b2XForm& xf2)
+{
+ manifold->m_pointCount = 0;
+
+ // Compute circle position in the frame of the polygon.
+ b2Vec2 c = b2Mul(xf2, circle->m_p);
+ b2Vec2 cLocal = b2MulT(xf1, c);
+
+ // Find the min separating edge.
+ int32 normalIndex = 0;
+ float32 separation = -B2_FLT_MAX;
+ float32 radius = polygon->m_radius + circle->m_radius;
+ int32 vertexCount = polygon->m_vertexCount;
+ const b2Vec2* vertices = polygon->m_vertices;
+ const b2Vec2* normals = polygon->m_normals;
+
+ for (int32 i = 0; i < vertexCount; ++i)
+ {
+ float32 s = b2Dot(normals[i], cLocal - vertices[i]);
+
+ if (s > radius)
+ {
+ // Early out.
+ return;
+ }
+
+ if (s > separation)
+ {
+ separation = s;
+ normalIndex = i;
+ }
+ }
+
+ // Vertices that subtend the incident face.
+ int32 vertIndex1 = normalIndex;
+ int32 vertIndex2 = vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0;
+ b2Vec2 v1 = vertices[vertIndex1];
+ b2Vec2 v2 = vertices[vertIndex2];
+
+ // If the center is inside the polygon ...
+ if (separation < B2_FLT_EPSILON)
+ {
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = normals[normalIndex];
+ manifold->m_localPoint = 0.5f * (v1 + v2);
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
+ return;
+ }
+
+ // Compute barycentric coordinates
+ float32 u1 = b2Dot(cLocal - v1, v2 - v1);
+ float32 u2 = b2Dot(cLocal - v2, v1 - v2);
+ if (u1 <= 0.0f)
+ {
+ if (b2DistanceSquared(cLocal, v1) > radius * radius)
+ {
+ return;
+ }
+
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = cLocal - v1;
+ manifold->m_localPlaneNormal.Normalize();
+ manifold->m_localPoint = v1;
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
+ }
+ else if (u2 <= 0.0f)
+ {
+ if (b2DistanceSquared(cLocal, v2) > radius * radius)
+ {
+ return;
+ }
+
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = cLocal - v2;
+ manifold->m_localPlaneNormal.Normalize();
+ manifold->m_localPoint = v2;
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
+ }
+ else
+ {
+ b2Vec2 faceCenter = 0.5f * (v1 + v2);
+ float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
+ if (separation > radius)
+ {
+ return;
+ }
+
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = normals[vertIndex1];
+ manifold->m_localPoint = faceCenter;
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
+ }
+}
View
204 application/lib/box2d/Collision/b2CollideEdge.cpp → ...tion/lib/box2d/Source/Collision/b2CollideEdge.cpp
@@ -21,96 +21,98 @@
#include "Shapes/b2EdgeShape.h"
#include "Shapes/b2PolygonShape.h"
+
+// This implements 2-sided edge vs circle collision.
void b2CollideEdgeAndCircle(b2Manifold* manifold,
const b2EdgeShape* edge,
const b2XForm& transformA,
const b2CircleShape* circle,
const b2XForm& transformB)
{
- manifold->pointCount = 0;
- b2Vec2 d;
- b2Vec2 c = b2Mul(transformB, circle->m_p);
- b2Vec2 cLocal = b2MulT(transformA, c);
- b2Vec2 n = edge->GetNormalVector();
- b2Vec2 v1 = edge->GetVertex1();
- b2Vec2 v2 = edge->GetVertex2();
+ manifold->m_pointCount = 0;
+ b2Vec2 cLocal = b2MulT(transformA, b2Mul(transformB, circle->m_p));
+ b2Vec2 normal = edge->m_normal;
+ b2Vec2 v1 = edge->m_v1;
+ b2Vec2 v2 = edge->m_v2;
float32 radius = edge->m_radius + circle->m_radius;
- float32 separation;
- float32 dirDist = b2Dot((cLocal - v1), edge->GetDirectionVector());
+ // Barycentric coordinates
+ float32 u1 = b2Dot(cLocal - v1, v2 - v1);
+ float32 u2 = b2Dot(cLocal - v2, v1 - v2);
- if (dirDist <= 0.0f)
+ if (u1 <= 0.0f)
{
// Behind v1
- d = cLocal - v1;
- if (b2Dot(d, edge->GetCorner1Vector()) < 0.0f)
+ if (b2DistanceSquared(cLocal, v1) > radius * radius)
{
- // Contact handled by previous edge
return;
}
- d = c - b2Mul(transformA, v1);
+
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = cLocal - v1;
+ manifold->m_localPlaneNormal.Normalize();
+ manifold->m_localPoint = v1;
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
}
- else if (dirDist >= edge->GetLength())
+ else if (u2 <= 0.0f)
{
// Ahead of v2
- d = cLocal - v2;
- if (b2Dot(d, edge->GetCorner2Vector()) > 0.0f)
+ if (b2DistanceSquared(cLocal, v2) > radius * radius)
{
- // Contact handled by next edge
return;
}
- d = c - b2Mul(transformA, v2);
+
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = cLocal - v2;
+ manifold->m_localPlaneNormal.Normalize();
+ manifold->m_localPoint = v2;
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
}
else
{
- separation = b2Dot(cLocal - v1, n);
- if (separation > radius || separation < -radius)
+ float32 separation = b2Dot(cLocal - v1, normal);
+ if (separation < -radius || radius < separation)
{
return;
}
- separation -= radius;
- manifold->normal = b2Mul(transformA.R, n);
- manifold->pointCount = 1;
- manifold->points[0].id.key = 0;
- manifold->points[0].separation = separation;
- c = c - radius * manifold->normal;
- manifold->points[0].localPointA = b2MulT(transformA, c);
- manifold->points[0].localPointB = b2MulT(transformB, c);
- return;
+
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA;
+ manifold->m_localPlaneNormal = separation < 0.0f ? -normal : normal;
+ manifold->m_localPoint = 0.5f * (v1 + v2);
+ manifold->m_points[0].m_localPoint = circle->m_p;
+ manifold->m_points[0].m_id.key = 0;
}
+}
- float32 distSqr = d.LengthSquared();
- if (distSqr > radius * radius)
- {
- return;
- }
+#if 1
- if (distSqr < B2_FLT_EPSILON)
- {
- separation = -radius;
- manifold->normal = b2Mul(transformA.R, n);
- }
- else
- {
- separation = d.Normalize() - radius;
- manifold->normal = d;
- }
+// Polygon versus 2-sided edge.
+void b2CollidePolyAndEdge(b2Manifold* manifold,
+ const b2PolygonShape* polygon,
+ const b2XForm& transformA,
+ const b2EdgeShape* edge,
+ const b2XForm& transformB)
+{
+ b2PolygonShape polygonB;
+ polygonB.SetAsEdge(edge->m_v1, edge->m_v2);
- manifold->pointCount = 1;
- manifold->points[0].id.key = 0;
- manifold->points[0].separation = separation;
- c = c - radius * manifold->normal;
- manifold->points[0].localPointA = b2MulT(transformA, c);
- manifold->points[0].localPointB = b2MulT(transformB, c);
+ b2CollidePolygons(manifold, polygon, transformA, &polygonB, transformB);
}
+#else
+
void b2CollidePolyAndEdge(b2Manifold* manifold,
const b2PolygonShape* polygon,
const b2XForm& transformA,
const b2EdgeShape* edge,
const b2XForm& transformB)
{
- manifold->pointCount = 0;
+ manifold->m_pointCount = 0;
b2Vec2 v1 = b2Mul(transformB, edge->GetVertex1());
b2Vec2 v2 = b2Mul(transformB, edge->GetVertex2());
b2Vec2 n = b2Mul(transformB.R, edge->GetNormalVector());
@@ -251,45 +253,44 @@ void b2CollidePolyAndEdge(b2Manifold* manifold,
}
}
- manifold->pointCount = 1;
- manifold->normal = b2Mul(transformA.R, normals[separationIndex]);
- manifold->points[0].separation = separationMax - totalRadius;
- manifold->points[0].id.features.incidentEdge = (uint8)separationIndex;
- manifold->points[0].id.features.incidentVertex = b2_nullFeature;
- manifold->points[0].id.features.referenceEdge = 0;
- manifold->points[0].id.features.flip = 0;
+ manifold->m_pointCount = 1;
+ manifold->m_type = b2Manifold::e_faceA
+ manifold->m_localPlaneNormal = normals[separationIndex];
+ manifold->m_points[0].m_id.key = 0;
+ manifold->m_points[0].m_id.features.incidentEdge = (uint8)separationIndex;
+ manifold->m_points[0].m_id.features.incidentVertex = b2_nullFeature;
+ manifold->m_points[0].m_id.features.referenceEdge = 0;
+ manifold->m_points[0].m_id.features.flip = 0;
if (separationV1)
{
- manifold->points[0].localPointA = v1Local;
- manifold->points[0].localPointB = edge->GetVertex1();
+ manifold->m_points[0].m_localPoint = edge->GetVertex1();
}
else
{
- manifold->points[0].localPointA = v2Local;
- manifold->points[0].localPointB = edge->GetVertex2();
+ manifold->m_points[0].m_localPoint = edge->GetVertex2();
}
return;
}
}
// We're going to use the edge's normal now.
- manifold->normal = -n;
+ manifold->m_localPlaneNormal = edge->GetNormalVector();
+ manifold->m_localPoint = 0.5f * (edge->m_v1 + edge->m_v2);
// Check whether we only need one contact point.
if (enterEndIndex == exitStartIndex)
{
- manifold->pointCount = 1;
- manifold->points[0].id.features.incidentEdge = (uint8)enterEndIndex;
- manifold->points[0].id.features.incidentVertex = b2_nullFeature;
- manifold->points[0].id.features.referenceEdge = 0;
- manifold->points[0].id.features.flip = 0;
- manifold->points[0].localPointA = vertices[enterEndIndex];
- manifold->points[0].localPointB = b2MulT(transformB, b2Mul(transformA, vertices[enterEndIndex]));
- manifold->points[0].separation = enterSepN - totalRadius;
+ manifold->m_pointCount = 1;
+ manifold->m_points[0].m_id.key = 0;
+ manifold->m_points[0].m_id.features.incidentEdge = (uint8)enterEndIndex;
+ manifold->m_points[0].m_id.features.incidentVertex = b2_nullFeature;
+ manifold->m_points[0].m_id.features.referenceEdge = 0;
+ manifold->m_points[0].m_id.features.flip = 0;
+ manifold->m_points[0].m_localPoint = vertices[enterEndIndex];
return;
}
- manifold->pointCount = 2;
+ manifold->m_pointCount = 2;
// dirLocal should be the edge's direction vector, but in the frame of the polygon.
b2Vec2 dirLocal = b2Cross(nLocal, -1.0f); // TODO: figure out why this optimization didn't work
@@ -309,55 +310,40 @@ void b2CollidePolyAndEdge(b2Manifold* manifold,
}
dirProj2 = b2Dot(dirLocal, vertices[exitStartIndex] - v1Local);
- manifold->points[0].id.features.incidentEdge = (uint8)enterEndIndex;
- manifold->points[0].id.features.incidentVertex = b2_nullFeature;
- manifold->points[0].id.features.referenceEdge = 0;
- manifold->points[0].id.features.flip = 0;
+ manifold->m_points[0].m_id.key = 0;
+ manifold->m_points[0].m_id.features.incidentEdge = (uint8)enterEndIndex;
+ manifold->m_points[0].m_id.features.incidentVertex = b2_nullFeature;
+ manifold->m_points[0].m_id.features.referenceEdge = 0;
+ manifold->m_points[0].m_id.features.flip = 0;
if (dirProj1 > edge->GetLength())
{
- manifold->points[0].localPointA = v2Local;
- manifold->points[0].localPointB = edge->GetVertex2();
- float32 ratio = (edge->GetLength() - dirProj2) / (dirProj1 - dirProj2);
- if (ratio > 100.0f * B2_FLT_EPSILON && ratio < 1.0f)
- {
- manifold->points[0].separation = exitSepN * (1.0f - ratio) + enterSepN * ratio - totalRadius;
- }
- else
- {
- manifold->points[0].separation = enterSepN - totalRadius;
- }
+ manifold->m_points[0].localPointA = v2Local;
+ manifold->m_points[0].localPointB = edge->GetVertex2();
}
else
{
- manifold->points[0].localPointA = vertices[enterEndIndex];
- manifold->points[0].localPointB = b2MulT(transformB, b2Mul(transformA, vertices[enterEndIndex]));
- manifold->points[0].separation = enterSepN - totalRadius;
+ manifold->m_points[0].localPointA = vertices[enterEndIndex];
+ manifold->m_points[0].localPointB = b2MulT(transformB, b2Mul(transformA, vertices[enterEndIndex]));
}
- manifold->points[1].id.features.incidentEdge = (uint8)exitStartIndex;
- manifold->points[1].id.features.incidentVertex = b2_nullFeature;
- manifold->points[1].id.features.referenceEdge = 0;
- manifold->points[1].id.features.flip = 0;
+ manifold->m_points[1].m_id.key = 0;
+ manifold->m_points[1].m_id.features.incidentEdge = (uint8)exitStartIndex;
+ manifold->m_points[1].m_id.features.incidentVertex = b2_nullFeature;
+ manifold->m_points[1].m_id.features.referenceEdge = 0;
+ manifold->m_points[1].m_id.features.flip = 0;
if (dirProj2 < 0.0f)
{
- manifold->points[1].localPointA = v1Local;
- manifold->points[1].localPointB = edge->GetVertex1();
- float32 ratio = (-dirProj1) / (dirProj2 - dirProj1);
- if (ratio > 100.0f * B2_FLT_EPSILON && ratio < 1.0f)
- {
- manifold->points[1].separation = enterSepN * (1.0f - ratio) + exitSepN * ratio - totalRadius;
- }
- else
- {
- manifold->points[1].separation = exitSepN - totalRadius;
- }
+ manifold->m_points[1].localPointA = v1Local;
+ manifold->m_points[1].localPointB = edge->GetVertex1();
}
else
{
- manifold->points[1].localPointA = vertices[exitStartIndex];
- manifold->points[1].localPointB = b2MulT(transformB, b2Mul(transformA, vertices[exitStartIndex]));
- manifold->points[1].separation = exitSepN - totalRadius;
+ manifold->m_points[1].localPointA = vertices[exitStartIndex];
+ manifold->m_points[1].localPointB = b2MulT(transformB, b2Mul(transformA, vertices[exitStartIndex]));
+ manifold->m_points[1].separation = exitSepN - totalRadius;
}
}
+
+#endif
View
72 application/lib/box2d/Collision/b2CollidePoly.cpp → ...tion/lib/box2d/Source/Collision/b2CollidePoly.cpp
@@ -19,46 +19,6 @@
#include "b2Collision.h"
#include "Shapes/b2PolygonShape.h"
-struct ClipVertex
-{
- b2Vec2 v;
- b2ContactID id;
-};
-
-static int32 b2ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
- const b2Vec2& normal, float32 offset)
-{
- // Start with no output points
- int32 numOut = 0;
-
- // Calculate the distance of end points to the line
- float32 distance0 = b2Dot(normal, vIn[0].v) - offset;
- float32 distance1 = b2Dot(normal, vIn[1].v) - offset;
-
- // If the points are behind the plane
- if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
- if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
-
- // If the points are on different sides of the plane
- if (distance0 * distance1 < 0.0f)
- {
- // Find intersection point of edge and plane
- float32 interp = distance0 / (distance0 - distance1);
- vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);
- if (distance0 > 0.0f)
- {
- vOut[numOut].id = vIn[0].id;
- }
- else
- {
- vOut[numOut].id = vIn[1].id;
- }
- ++numOut;
- }
-
- return numOut;
-}
-
// Find the separation between poly1 and poly2 for a give edge normal on poly1.
static float32 b2EdgeSeparation(const b2PolygonShape* poly1, const b2XForm& xf1, int32 edge1,
const b2PolygonShape* poly2, const b2XForm& xf2)
@@ -179,7 +139,7 @@ static float32 b2FindMaxSeparation(int32* edgeIndex,
return bestSeparation;
}
-static void b2FindIncidentEdge(ClipVertex c[2],
+static void b2FindIncidentEdge(b2ClipVertex c[2],
const b2PolygonShape* poly1, const b2XForm& xf1, int32 edge1,
const b2PolygonShape* poly2, const b2XForm& xf2)
{
@@ -234,7 +194,7 @@ void b2CollidePolygons(b2Manifold* manifold,
const b2PolygonShape* polyA, const b2XForm& xfA,
const b2PolygonShape* polyB, const b2XForm& xfB)
{
- manifold->pointCount = 0;
+ manifold->m_pointCount = 0;
float32 totalRadius = polyA->m_radius + polyB->m_radius;
int32 edgeA = 0;
@@ -262,6 +222,7 @@ void b2CollidePolygons(b2Manifold* manifold,
xf1 = xfB;
xf2 = xfA;
edge1 = edgeB;
+ manifold->m_type = b2Manifold::e_faceB;
flip = 1;
}
else
@@ -271,10 +232,11 @@ void b2CollidePolygons(b2Manifold* manifold,
xf1 = xfA;
xf2 = xfB;
edge1 = edgeA;
+ manifold->m_type = b2Manifold::e_faceA;
flip = 0;
}
- ClipVertex incidentEdge[2];
+ b2ClipVertex incidentEdge[2];
b2FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
int32 count1 = poly1->m_vertexCount;
@@ -284,6 +246,11 @@ void b2CollidePolygons(b2Manifold* manifold,
b2Vec2 v12 = edge1 + 1 < count1 ? vertices1[edge1+1] : vertices1[0];
b2Vec2 dv = v12 - v11;
+
+ b2Vec2 localNormal = b2Cross(dv, 1.0f);
+ localNormal.Normalize();
+ b2Vec2 planePoint = 0.5f * (v11 + v12);
+
b2Vec2 sideNormal = b2Mul(xf1.R, v12 - v11);
sideNormal.Normalize();
b2Vec2 frontNormal = b2Cross(sideNormal, 1.0f);
@@ -296,8 +263,8 @@ void b2CollidePolygons(b2Manifold* manifold,
float32 sideOffset2 = b2Dot(sideNormal, v12);
// Clip incident edge against extruded edge1 side edges.
- ClipVertex clipPoints1[2];
- ClipVertex clipPoints2[2];
+ b2ClipVertex clipPoints1[2];
+ b2ClipVertex clipPoints2[2];
int np;
// Clip to box side 1
@@ -315,7 +282,8 @@ void b2CollidePolygons(b2Manifold* manifold,
}
// Now clipPoints2 contains the clipped points.
- manifold->normal = flip ? -frontNormal : frontNormal;
+ manifold->m_localPlaneNormal = localNormal;
+ manifold->m_localPoint = planePoint;
int32 pointCount = 0;
for (int32 i = 0; i < b2_maxManifoldPoints; ++i)
@@ -324,15 +292,13 @@ void b2CollidePolygons(b2Manifold* manifold,
if (separation <= totalRadius)
{
- b2ManifoldPoint* cp = manifold->points + pointCount;
- cp->separation = separation - totalRadius;
- cp->localPointA = b2MulT(xfA, clipPoints2[i].v);
- cp->localPointB = b2MulT(xfB, clipPoints2[i].v);
- cp->id = clipPoints2[i].id;
- cp->id.features.flip = flip;
+ b2ManifoldPoint* cp = manifold->m_points + pointCount;
+ cp->m_localPoint = b2MulT(xf2, clipPoints2[i].v);
+ cp->m_id = clipPoints2[i].id;
+ cp->m_id.features.flip = flip;
++pointCount;
}
}
- manifold->pointCount = pointCount;
+ manifold->m_pointCount = pointCount;
}
View
287 application/lib/box2d/Source/Collision/b2Collision.cpp
@@ -0,0 +1,287 @@
+/*
+* Copyright (c) 2007-2009 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.
+*/
+
+#include "b2Collision.h"
+
+void b2WorldManifold::Initialize(const b2Manifold* manifold,
+ const b2XForm& xfA, float32 radiusA,
+ const b2XForm& xfB, float32 radiusB)
+{
+ if (manifold->m_pointCount == 0)
+ {
+ return;
+ }
+
+ switch (manifold->m_type)
+ {
+ case b2Manifold::e_circles:
+ {
+ b2Vec2 pointA = b2Mul(xfA, manifold->m_localPoint);
+ b2Vec2 pointB = b2Mul(xfB, manifold->m_points[0].m_localPoint);
+ b2Vec2 normal(1.0f, 0.0f);
+ if (b2DistanceSquared(pointA, pointB) > B2_FLT_EPSILON * B2_FLT_EPSILON)
+ {
+ normal = pointB - pointA;
+ normal.Normalize();
+ }
+
+ m_normal = normal;
+
+ b2Vec2 cA = pointA + radiusA * normal;
+ b2Vec2 cB = pointB - radiusB * normal;
+ m_points[0] = 0.5f * (cA + cB);
+ }
+ break;
+
+ case b2Manifold::e_faceA:
+ {
+ b2Vec2 normal = b2Mul(xfA.R, manifold->m_localPlaneNormal);
+ b2Vec2 planePoint = b2Mul(xfA, manifold->m_localPoint);
+
+ // Ensure normal points from A to B.
+ m_normal = normal;
+
+ for (int32 i = 0; i < manifold->m_pointCount; ++i)
+ {
+ b2Vec2 clipPoint = b2Mul(xfB, manifold->m_points[i].m_localPoint);
+ b2Vec2 cA = clipPoint + (radiusA - b2Dot(clipPoint - planePoint, normal)) * normal;
+ b2Vec2 cB = clipPoint - radiusB * normal;
+ m_points[i] = 0.5f * (cA + cB);
+ }
+ }
+ break;
+
+ case b2Manifold::e_faceB:
+ {
+ b2Vec2 normal = b2Mul(xfB.R, manifold->m_localPlaneNormal);
+ b2Vec2 planePoint = b2Mul(xfB, manifold->m_localPoint);
+
+ // Ensure normal points from A to B.
+ m_normal = -normal;
+
+ for (int32 i = 0; i < manifold->m_pointCount; ++i)
+ {
+ b2Vec2 clipPoint = b2Mul(xfA, manifold->m_points[i].m_localPoint);
+ b2Vec2 cA = clipPoint - radiusA * normal;
+ b2Vec2 cB = clipPoint + (radiusB - b2Dot(clipPoint - planePoint, normal)) * normal;
+ m_points[i] = 0.5f * (cA + cB);
+ }
+ }
+ break;
+ }
+}
+
+void b2GetPointStates(b2PointState state1[b2_maxManifoldPoints], b2PointState state2[b2_maxManifoldPoints],
+ const b2Manifold* manifold1, const b2Manifold* manifold2)
+{
+ for (int32 i = 0; i < b2_maxManifoldPoints; ++i)
+ {
+ state1[i] = b2_nullState;
+ state2[i] = b2_nullState;
+ }
+
+ // Detect persists and removes.
+ for (int32 i = 0; i < manifold1->m_pointCount; ++i)
+ {
+ b2ContactID id = manifold1->m_points[i].m_id;
+
+ state1[i] = b2_removeState;
+
+ for (int32 j = 0; j < manifold2->m_pointCount; ++j)
+ {
+ if (manifold2->m_points[j].m_id.key == id.key)
+ {
+ state1[i] = b2_persistState;
+ break;
+ }
+ }
+ }
+
+ // Detect persists and adds.
+ for (int32 i = 0; i < manifold2->m_pointCount; ++i)
+ {
+ b2ContactID id = manifold2->m_points[i].m_id;
+
+ state2[i] = b2_addState;
+
+ for (int32 j = 0; j < manifold1->m_pointCount; ++j)
+ {
+ if (manifold1->m_points[j].m_id.key == id.key)
+ {
+ state2[i] = b2_persistState;
+ break;
+ }
+ }
+ }
+}
+
+// Collision Detection in Interactive 3D Environments by Gino van den Bergen
+// From Section 3.4.1
+// x = mu1 * p1 + mu2 * p2
+// mu1 + mu2 = 1 && mu1 >= 0 && mu2 >= 0
+// mu1 = 1 - mu2;
+// x = (1 - mu2) * p1 + mu2 * p2
+// = p1 + mu2 * (p2 - p1)
+// x = s + a * r (s := start, r := end - start)
+// s + a * r = p1 + mu2 * d (d := p2 - p1)
+// -a * r + mu2 * d = b (b := s - p1)
+// [-r d] * [a; mu2] = b
+// Cramer's rule:
+// denom = det[-r d]
+// a = det[b d] / denom
+// mu2 = det[-r b] / denom
+bool b2Segment::TestSegment(float32* lambda, b2Vec2* normal, const b2Segment& segment, float32 maxLambda) const
+{
+ b2Vec2 s = segment.p1;
+ b2Vec2 r = segment.p2 - s;
+ b2Vec2 d = p2 - p1;
+ b2Vec2 n = b2Cross(d, 1.0f);
+
+ const float32 k_slop = 100.0f * B2_FLT_EPSILON;
+ float32 denom = -b2Dot(r, n);
+
+ // Cull back facing collision and ignore parallel segments.
+ if (denom > k_slop)
+ {
+ // Does the segment intersect the infinite line associated with this segment?
+ b2Vec2 b = s - p1;
+ float32 a = b2Dot(b, n);
+
+ if (0.0f <= a && a <= maxLambda * denom)
+ {
+ float32 mu2 = -r.x * b.y + r.y * b.x;
+
+ // Does the segment intersect this segment?
+ if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0f + k_slop))
+ {
+ a /= denom;
+ n.Normalize();
+ *lambda = a;
+ *normal = n;
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+// From Real-time Collision Detection, p179.
+void b2AABB::RayCast(b2RayCastOutput* output, const b2RayCastInput& input)
+{
+ float32 tmin = -B2_FLT_MAX;
+ float32 tmax = B2_FLT_MAX;
+
+ output->hit = false;
+
+ b2Vec2 p = input.p1;
+ b2Vec2 d = input.p2 - input.p1;
+ b2Vec2 absD = b2Abs(d);
+
+ b2Vec2 normal;
+
+ for (int32 i = 0; i < 2; ++i)
+ {
+ if (absD(i) < B2_FLT_EPSILON)
+ {
+ // Parallel.
+ if (p(i) < lowerBound(i) || upperBound(i) < p(i))
+ {
+ return;
+ }
+ }
+ else
+ {
+ float32 inv_d = 1.0f / d(i);
+ float32 t1 = (lowerBound(i) - p(i)) * inv_d;
+ float32 t2 = (upperBound(i) - p(i)) * inv_d;
+
+ // Sign of the normal vector.
+ float32 s = -1.0f;
+
+ if (t1 > t2)
+ {
+ b2Swap(t1, t2);
+ s = 1.0f;
+ }
+
+ // Push the min up
+ if (t1 > tmin)
+ {
+ normal.SetZero();
+ normal(i) = s;
+ tmin = t1;
+ }
+
+ // Pull the max down
+ tmax = b2Min(tmax, t2);
+
+ if (tmin > tmax)
+ {
+ return;
+ }
+ }
+ }
+
+ // Does the ray start inside the box?
+ // Does the ray intersect beyond the max fraction?
+ if (tmin < 0.0f || input.maxFraction < tmin)
+ {
+ return;
+ }
+
+ // Intersection.
+ output->fraction = tmin;
+ output->normal = normal;
+ output->hit = true;
+}
+
+// Sutherland-Hodgman clipping.
+int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],
+ const b2Vec2& normal, float32 offset)
+{
+ // Start with no output points
+ int32 numOut = 0;
+
+ // Calculate the distance of end points to the line
+ float32 distance0 = b2Dot(normal, vIn[0].v) - offset;
+ float32 distance1 = b2Dot(normal, vIn[1].v) - offset;
+
+ // If the points are behind the plane
+ if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
+ if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
+
+ // If the points are on different sides of the plane
+ if (distance0 * distance1 < 0.0f)
+ {
+ // Find intersection point of edge and plane
+ float32 interp = distance0 / (distance0 - distance1);
+ vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);
+ if (distance0 > 0.0f)
+ {
+ vOut[numOut].id = vIn[0].id;
+ }
+ else
+ {
+ vOut[numOut].id = vIn[1].id;
+ }
+ ++numOut;
+ }
+
+ return numOut;
+}
View
89 application/lib/box2d/Collision/b2Collision.h → application/lib/box2d/Source/Collision/b2Collision.h
@@ -50,24 +50,87 @@ union b2ContactID
/// A manifold point is a contact point belonging to a contact
/// manifold. It holds details related to the geometry and dynamics
/// of the contact points.
-/// The point is stored in local coordinates because CCD
-/// requires sub-stepping in which the separation is stale.
+/// The local point usage depends on the manifold type:
+/// -e_circles: the local center of circleB
+/// -e_faceA: the local center of cirlceB or the clip point of polygonB
+/// -e_faceB: the clip point of polygonA
+/// This structure is stored across time steps, so we keep it small.
+/// Note: the impulses are used for internal caching and may not
+/// provide reliable contact forces, especially for high speed collisions.
struct b2ManifoldPoint
{
- b2Vec2 localPointA; ///< local position of the contact point in bodyA
- b2Vec2 localPointB; ///< local position of the contact point in bodyB
- float32 separation; ///< the separation of the shapes along the normal vector
- float32 normalImpulse; ///< the non-penetration impulse
- float32 tangentImpulse; ///< the friction impulse
- b2ContactID id; ///< uniquely identifies a contact point between two shapes
+ b2Vec2 m_localPoint; ///< usage depends on manifold type
+ float32 m_normalImpulse; ///< the non-penetration impulse
+ float32 m_tangentImpulse; ///< the friction impulse
+ b2ContactID m_id; ///< uniquely identifies a contact point between two shapes
};
/// A manifold for two touching convex shapes.
+/// Box2D supports multiple types of contact:
+/// - clip point versus plane with radius
+/// - point versus point with radius (circles)
+/// The local point usage depends on the manifold type:
+/// -e_circles: the local center of circleA
+/// -e_faceA: the center of faceA
+/// -e_faceB: the center of faceB
+/// Similarly the local normal usage:
+/// -e_circles: not used
+/// -e_faceA: the normal on polygonA
+/// -e_faceB: the normal on polygonB
+/// We store contacts in this way so that position correction can
+/// account for movement, which is critical for continuous physics.
+/// All contact scenarios must be expressed in one of these types.
+/// This structure is stored across time steps, so we keep it small.
struct b2Manifold
{
- b2ManifoldPoint points[b2_maxManifoldPoints]; ///< the points of contact
- b2Vec2 normal; ///< the shared unit normal vector, this points from shapeA to shapeB.
- int32 pointCount; ///< the number of manifold points
+ enum Type
+ {
+ e_circles,
+ e_faceA,
+ e_faceB
+ };
+
+ b2ManifoldPoint m_points[b2_maxManifoldPoints]; ///< the points of contact
+ b2Vec2 m_localPlaneNormal; ///< not use for Type::e_points
+ b2Vec2 m_localPoint; ///< usage depends on manifold type
+ Type m_type;
+ int32 m_pointCount; ///< the number of manifold points
+};
+
+/// This is used to compute the current state of a contact manifold.
+struct b2WorldManifold
+{
+ /// Evaluate the manifold with supplied transforms. This assumes
+ /// modest motion from the original state. This does not change the
+ /// point count, impulses, etc. The radii must come from the shapes
+ /// that generated the manifold.
+ void Initialize(const b2Manifold* manifold,
+ const b2XForm& xfA, float32 radiusA,
+ const b2XForm& xfB, float32 radiusB);
+
+ b2Vec2 m_normal; ///< world vector pointing from A to B
+ b2Vec2 m_points[b2_maxManifoldPoints]; ///< world contact point (point of intersection)
+};
+
+/// This is used for determining the state of contact points.
+enum b2PointState
+{
+ b2_nullState, ///< point does not exist
+ b2_addState, ///< point was added in the update
+ b2_persistState, ///< point persisted across the update
+ b2_removeState ///< point was removed in the update
+};
+
+/// Compute the point states given two manifolds. The states pertain to the transition from manifold1
+/// to manifold2. So state1 is either persist or remove while state2 is either add or persist.
+void b2GetPointStates(b2PointState state1[b2_maxManifoldPoints], b2PointState state2[b2_maxManifoldPoints],
+ const b2Manifold* manifold1, const b2Manifold* manifold2);
+
+/// Used for computing contact manifolds.
+struct b2ClipVertex
+{
+ b2Vec2 v;
+ b2ContactID id;
};
/// Ray-cast input data.
@@ -162,6 +225,10 @@ void b2CollidePolyAndEdge(b2Manifold* manifold,
const b2PolygonShape* poly, const b2XForm& xf1,
const b2EdgeShape* edge, const b2XForm& xf2);
+/// Clipping for contact manifolds.
+int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],
+ const b2Vec2& normal, float32 offset);
+
// ---------------- Inline Functions ------------------------------------------
View
0  application/lib/box2d/Collision/b2Distance.cpp → ...ication/lib/box2d/Source/Collision/b2Distance.cpp
File renamed without changes
View
0  application/lib/box2d/Collision/b2Distance.h → application/lib/box2d/Source/Collision/b2Distance.h
File renamed without changes
View
0  application/lib/box2d/Collision/b2DynamicTree.cpp → ...tion/lib/box2d/Source/Collision/b2DynamicTree.cpp
File renamed without changes
View
0  application/lib/box2d/Collision/b2DynamicTree.h → ...cation/lib/box2d/Source/Collision/b2DynamicTree.h
File renamed without changes
View
0  application/lib/box2d/Collision/b2PairManager.cpp → ...tion/lib/box2d/Source/Collision/b2PairManager.cpp
File renamed without changes
View
0  application/lib/box2d/Collision/b2PairManager.h → ...cation/lib/box2d/Source/Collision/b2PairManager.h
File renamed without changes
View
14 application/lib/box2d/Collision/b2TimeOfImpact.cpp → ...ion/lib/box2d/Source/Collision/b2TimeOfImpact.cpp
@@ -28,7 +28,7 @@
int32 b2_maxToiIters = 0;
int32 b2_maxToiRootIters = 0;
-#if 1
+#if 0
// This algorithm uses conservative advancement to compute the time of
// impact (TOI) of two shapes.
// Refs: Bullet, Young Kim
@@ -283,6 +283,7 @@ float32 b2TimeOfImpact(const b2TOIInput* input, const TA* shapeA, const TB* shap
b2Assert(sweepA.t0 == sweepB.t0);
b2Assert(1.0f - sweepA.t0 > B2_FLT_EPSILON);
+ float32 radius = shapeA->m_radius + shapeB->m_radius;
float32 tolerance = input->tolerance;
float32 alpha = 0.0f;
@@ -328,18 +329,19 @@ float32 b2TimeOfImpact(const b2TOIInput* input, const TA* shapeA, const TB* shap
if (iter == 0)
{
// Compute a reasonable target distance to give some breathing room
- // for conservative advancement.
- if (separation > 2.0f * tolerance)
+ // for conservative advancement. We take advantage of the shape radii
+ // to create additional clearance.
+ if (separation > radius)
{
- target = 1.5f * tolerance;
+ target = b2Max(radius - tolerance, 0.75f * radius);
}
else
{
- target = b2Max(0.05f * tolerance, separation - 0.5f * tolerance);
+ target = b2Max(separation - tolerance, 0.02f * radius);
}
}
- if (separation - target < 0.03f * tolerance)
+ if (separation - target < 0.5f * tolerance)
{
if (iter == 0)
{
View
4 application/lib/box2d/Collision/b2TimeOfImpact.h → ...ation/lib/box2d/Source/Collision/b2TimeOfImpact.h
@@ -22,6 +22,7 @@
#include "../Common/b2Math.h"
#include <limits.h>
+/// Inpute parameters for b2TimeOfImpact
struct b2TOIInput
{
b2Sweep sweepA;
@@ -32,6 +33,9 @@ struct b2TOIInput
};
/// Compute the time when two shapes begin to touch or touch at a closer distance.
+/// TOI considers the shape radii. It attempts to have the radii overlap by the tolerance.
+/// Iterations terminate with the overlap is within 0.5 * tolerance. The tolerance should be
+/// smaller than sum of the shape radii.
/// @warning the sweeps must have the same time interval.
/// @return the fraction between [0,1] in which the shapes first touch.
/// fraction=0 means the shapes begin touching/overlapped, and fraction=1 means the shapes don't touch.
View
2  application/lib/box2d/Common/Fixed.h → application/lib/box2d/Source/Common/Fixed.h
@@ -196,7 +196,7 @@ inline Fixed::operator float() { return g * (float)STEP(); }
inline Fixed::operator double() { return g * (double)STEP(); }
inline Fixed::operator int() { return g>>BP; }
inline Fixed::operator long() { return g>>BP; }
-//#pragma warning(disable: 4244) //HARDWIRE added pragma to prevent VS2005 compilation error
+#pragma warning(disable: 4244) //HARDWIRE added pragma to prevent VS2005 compilation error
inline Fixed::operator unsigned short() { return g>>BP; }
inline Fixed::operator float() const { return g / (float)(1<<BP); }
View
0  application/lib/box2d/Common/b2BlockAllocator.cpp → ...tion/lib/box2d/Source/Common/b2BlockAllocator.cpp
File renamed without changes
View
0  application/lib/box2d/Common/b2BlockAllocator.h → ...cation/lib/box2d/Source/Common/b2BlockAllocator.h
File renamed without changes
View
0  application/lib/box2d/Common/b2Math.cpp → application/lib/box2d/Source/Common/b2Math.cpp
File renamed without changes
View
0  application/lib/box2d/Common/b2Math.h → application/lib/box2d/Source/Common/b2Math.h
File renamed without changes
View
0  application/lib/box2d/Common/b2Settings.cpp → application/lib/box2d/Source/Common/b2Settings.cpp
File renamed without changes
View
45 application/lib/box2d/Common/b2Settings.h → application/lib/box2d/Source/Common/b2Settings.h
@@ -63,7 +63,7 @@ typedef float float32;
#endif
-const float32 b2_pi = 3.14159265359f;
+#define b2_pi 3.14159265359f
/// @file
/// Global tuning constants based on meters-kilograms-seconds (MKS) units.
@@ -90,62 +90,65 @@ const float32 b2_pi = 3.14159265359f;
/// This must be a power of two
#define b2_maxPairs (8 * b2_maxProxies)
-/// The radius of the polygon/edge shape skin.
-#define b2_polygonRadius 0.01f
-
-// Dynamics
-
/// A small length used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant.
-const float32 b2_linearSlop = 0.005f; // 0.5 cm
+#define b2_linearSlop 0.005f
/// A small angle used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant.
-const float32 b2_angularSlop = 2.0f / 180.0f * b2_pi; // 2 degrees
+#define b2_angularSlop (2.0f / 180.0f * b2_pi)
+
+/// The radius of the polygon/edge shape skin. This should not be modified. Making
+/// this smaller means polygons will have and insufficient for continuous collision.
+/// Making it larger may create artifacts for vertex collision.
+#define b2_polygonRadius (2.0f * b2_linearSlop)
+
+
+// Dynamics
/// Maximum number of contacts to be handled to solve a TOI island.
-const int32 b2_maxTOIContactsPerIsland = 32;
+#define b2_maxTOIContactsPerIsland 32
/// Maximum number of joints to be handled to solve a TOI island.
-const int32 b2_maxTOIJointsPerIsland = 32;
+#define b2_maxTOIJointsPerIsland 32
/// A velocity threshold for elastic collisions. Any collision with a relative linear
/// velocity below this threshold will be treated as inelastic.
-const float32 b2_velocityThreshold = 1.0f; // 1 m/s
+#define b2_velocityThreshold 1.0f
/// The maximum linear position correction used when solving constraints. This helps to
/// prevent overshoot.
-const float32 b2_maxLinearCorrection = 0.2f; // 20 cm
+#define b2_maxLinearCorrection 0.2f
/// The maximum angular position correction used when solving constraints. This helps to
/// prevent overshoot.
-const float32 b2_maxAngularCorrection = 8.0f / 180.0f * b2_pi; // 8 degrees
+#define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
/// The maximum linear velocity of a body. This limit is very large and is used
/// to prevent numerical problems. You shouldn't need to adjust this.
-#define b2_maxTranslation 2.0f
-#define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
+#define b2_maxTranslation 2.0f
+#define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
/// The maximum angular velocity of a body. This limit is very large and is used
/// to prevent numerical problems. You shouldn't need to adjust this.
-#define b2_maxRotation (0.5f * b2_pi)
-#define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
+#define b2_maxRotation (0.5f * b2_pi)
+#define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
/// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
/// that overlap is removed in one time step. However using values close to 1 often lead
/// to overshoot.
-const float32 b2_contactBaumgarte = 0.2f;
+#define b2_contactBaumgarte 0.2f
// Sleep
/// The time that a body must be still before it will go to sleep.
-const float32 b2_timeToSleep = 0.5f; // half a second
+#define b2_timeToSleep 0.5f
/// A body cannot sleep if its linear velocity is above this tolerance.
-const float32 b2_linearSleepTolerance = 0.01f; // 1 cm/s
+#define b2_linearSleepTolerance 0.01f
/// A body cannot sleep if its angular velocity is above this tolerance.
-const float32 b2_angularSleepTolerance = 2.0f / 180.0f * b2_pi; // 2 degrees/s
+#define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
// Memory Allocation