Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merging integration into master, fixing build errors on Chrome, iOS, …

…OSX and Android
  • Loading branch information...
commit 9fd136e5d2e0002527d4f73cba37d126089719fa 2 parents 08bb28e + 6e7d6f6
Adam Villalobos authored
Showing with 23,438 additions and 23,438 deletions.
  1. +171 −171 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2ChainShape.cpp
  2. +100 −100 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2CircleShape.cpp
  3. +139 −139 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2EdgeShape.cpp
  4. +361 −361 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2PolygonShape.cpp
  5. +217 −217 3rdparty/box2d-2.2.1/Box2D/Common/b2BlockAllocator.cpp
  6. +94 −94 3rdparty/box2d-2.2.1/Box2D/Common/b2Math.cpp
  7. +83 −83 3rdparty/box2d-2.2.1/Box2D/Common/b2StackAllocator.cpp
  8. +100 −100 3rdparty/box2d-2.2.1/Box2D/Common/b2Timer.cpp
  9. +513 −513 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2Body.cpp
  10. +846 −846 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2Body.h
  11. +293 −293 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2ContactManager.cpp
  12. +303 −303 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2Fixture.cpp
  13. +540 −540 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2Island.cpp
  14. +95 −95 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2Island.h
  15. +1,352 −1,352 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2World.cpp
  16. +36 −36 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2WorldCallbacks.cpp
  17. +259 −259 3rdparty/box2d-2.2.1/Box2D/Rope/b2Rope.cpp
  18. +115 −115 3rdparty/box2d-2.2.1/Box2D/Rope/b2Rope.h
  19. +106 −106 3rdparty/box2d-2.2.1/HelloWorld/HelloWorld.cpp
  20. +447 −447 3rdparty/box2d-2.2.1/Testbed/Framework/Main.cpp
  21. +197 −197 3rdparty/box2d-2.2.1/Testbed/Framework/Render.cpp
  22. +51 −51 3rdparty/box2d-2.2.1/Testbed/Framework/Render.h
  23. +447 −447 3rdparty/box2d-2.2.1/Testbed/Framework/Test.cpp
  24. +189 −189 3rdparty/box2d-2.2.1/Testbed/Framework/Test.h
  25. +51 −51 3rdparty/box2d-2.2.1/Testbed/Tests/AddPair.h
  26. +180 −180 3rdparty/box2d-2.2.1/Testbed/Tests/ApplyForce.h
  27. +159 −159 3rdparty/box2d-2.2.1/Testbed/Tests/BodyTypes.h
  28. +155 −155 3rdparty/box2d-2.2.1/Testbed/Tests/Breakable.h
  29. +125 −125 3rdparty/box2d-2.2.1/Testbed/Tests/Bridge.h
  30. +136 −136 3rdparty/box2d-2.2.1/Testbed/Tests/BulletTest.h
  31. +211 −211 3rdparty/box2d-2.2.1/Testbed/Tests/Cantilever.h
  32. +286 −286 3rdparty/box2d-2.2.1/Testbed/Tests/Car.h
  33. +74 −74 3rdparty/box2d-2.2.1/Testbed/Tests/Chain.h
  34. +253 −253 3rdparty/box2d-2.2.1/Testbed/Tests/CharacterCollision.h
  35. +176 −176 3rdparty/box2d-2.2.1/Testbed/Tests/CollisionFiltering.h
  36. +188 −188 3rdparty/box2d-2.2.1/Testbed/Tests/CollisionProcessing.h
  37. +143 −143 3rdparty/box2d-2.2.1/Testbed/Tests/CompoundShapes.h
  38. +167 −167 3rdparty/box2d-2.2.1/Testbed/Tests/Confined.h
  39. +137 −137 3rdparty/box2d-2.2.1/Testbed/Tests/ContinuousTest.h
  40. +215 −215 3rdparty/box2d-2.2.1/Testbed/Tests/Dominos.h
  41. +267 −267 3rdparty/box2d-2.2.1/Testbed/Tests/DumpShell.h
  42. +357 −357 3rdparty/box2d-2.2.1/Testbed/Tests/DynamicTreeTest.h
  43. +249 −249 3rdparty/box2d-2.2.1/Testbed/Tests/EdgeShapes.h
  44. +109 −109 3rdparty/box2d-2.2.1/Testbed/Tests/EdgeTest.h
  45. +187 −187 3rdparty/box2d-2.2.1/Testbed/Tests/Gears.h
  46. +120 −120 3rdparty/box2d-2.2.1/Testbed/Tests/OneSidedPlatform.h
  47. +169 −169 3rdparty/box2d-2.2.1/Testbed/Tests/Pinball.h
  48. +122 −122 3rdparty/box2d-2.2.1/Testbed/Tests/PolyCollision.h
  49. +295 −295 3rdparty/box2d-2.2.1/Testbed/Tests/PolyShapes.h
  50. +107 −107 3rdparty/box2d-2.2.1/Testbed/Tests/Prismatic.h
  51. +106 −106 3rdparty/box2d-2.2.1/Testbed/Tests/Pulleys.h
  52. +89 −89 3rdparty/box2d-2.2.1/Testbed/Tests/Pyramid.h
  53. +440 −440 3rdparty/box2d-2.2.1/Testbed/Tests/RayCast.h
  54. +166 −166 3rdparty/box2d-2.2.1/Testbed/Tests/Revolute.h
  55. +101 −101 3rdparty/box2d-2.2.1/Testbed/Tests/Rope.h
  56. +145 −145 3rdparty/box2d-2.2.1/Testbed/Tests/RopeJoint.h
  57. +181 −181 3rdparty/box2d-2.2.1/Testbed/Tests/SensorTest.h
  58. +105 −105 3rdparty/box2d-2.2.1/Testbed/Tests/ShapeEditing.h
  59. +156 −156 3rdparty/box2d-2.2.1/Testbed/Tests/SliderCrank.h
  60. +86 −86 3rdparty/box2d-2.2.1/Testbed/Tests/SphereStack.h
  61. +125 −125 3rdparty/box2d-2.2.1/Testbed/Tests/TestEntries.cpp
  62. +256 −256 3rdparty/box2d-2.2.1/Testbed/Tests/TheoJansen.h
  63. +156 −156 3rdparty/box2d-2.2.1/Testbed/Tests/Tiles.h
  64. +131 −131 3rdparty/box2d-2.2.1/Testbed/Tests/TimeOfImpact.h
  65. +99 −99 3rdparty/box2d-2.2.1/Testbed/Tests/Tumbler.h
  66. +124 −124 3rdparty/box2d-2.2.1/Testbed/Tests/VaryingFriction.h
  67. +69 −69 3rdparty/box2d-2.2.1/Testbed/Tests/VaryingRestitution.h
  68. +165 −165 3rdparty/box2d-2.2.1/Testbed/Tests/VerticalStack.h
  69. +209 −209 3rdparty/box2d-2.2.1/Testbed/Tests/Web.h
  70. +453 −453 3rdparty/box2d-2.2.1/freeglut/freeglut_spaceball.c
  71. +1,609 −1,609 3rdparty/box2d-2.2.1/glui/algebra3.cpp
  72. +475 −475 3rdparty/box2d-2.2.1/glui/algebra3.h
  73. +237 −237 3rdparty/box2d-2.2.1/glui/arcball.cpp
  74. +97 −97 3rdparty/box2d-2.2.1/glui/arcball.h
  75. +2,105 −2,105 3rdparty/box2d-2.2.1/glui/glui.cpp
  76. +2,568 −2,568 3rdparty/box2d-2.2.1/glui/glui.h
  77. +319 −319 3rdparty/box2d-2.2.1/glui/glui_add_controls.cpp
  78. +138 −138 3rdparty/box2d-2.2.1/glui/glui_bitmap_img_data.cpp
  79. +176 −176 3rdparty/box2d-2.2.1/glui/glui_bitmaps.cpp
  80. +186 −186 3rdparty/box2d-2.2.1/glui/glui_button.cpp
  81. +188 −188 3rdparty/box2d-2.2.1/glui/glui_checkbox.cpp
  82. +89 −89 3rdparty/box2d-2.2.1/glui/glui_column.cpp
  83. +197 −197 3rdparty/box2d-2.2.1/glui/glui_commandline.cpp
Sorry, we could not display the entire diff because too many files (888) changed.
View
342 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2ChainShape.cpp
@@ -1,171 +1,171 @@
-/*
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Collision/Shapes/b2ChainShape.h>
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>
-#include <new>
-#include <cstring>
-using namespace std;
-
-b2ChainShape::~b2ChainShape()
-{
- b2Free(m_vertices);
- m_vertices = NULL;
- m_count = 0;
-}
-
-void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
-{
- b2Assert(m_vertices == NULL && m_count == 0);
- b2Assert(count >= 3);
- m_count = count + 1;
- m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
- memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
- m_vertices[count] = m_vertices[0];
- m_prevVertex = m_vertices[m_count - 2];
- m_nextVertex = m_vertices[1];
- m_hasPrevVertex = true;
- m_hasNextVertex = true;
-}
-
-void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
-{
- b2Assert(m_vertices == NULL && m_count == 0);
- b2Assert(count >= 2);
- m_count = count;
- m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
- memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
- m_hasPrevVertex = false;
- m_hasNextVertex = false;
-}
-
-void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
-{
- m_prevVertex = prevVertex;
- m_hasPrevVertex = true;
-}
-
-void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
-{
- m_nextVertex = nextVertex;
- m_hasNextVertex = true;
-}
-
-b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
-{
- void* mem = allocator->Allocate(sizeof(b2ChainShape));
- b2ChainShape* clone = new (mem) b2ChainShape;
- clone->CreateChain(m_vertices, m_count);
- clone->m_prevVertex = m_prevVertex;
- clone->m_nextVertex = m_nextVertex;
- clone->m_hasPrevVertex = m_hasPrevVertex;
- clone->m_hasNextVertex = m_hasNextVertex;
- return clone;
-}
-
-int32 b2ChainShape::GetChildCount() const
-{
- // edge count = vertex count - 1
- return m_count - 1;
-}
-
-void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
-{
- b2Assert(0 <= index && index < m_count - 1);
- edge->m_type = b2Shape::e_edge;
- edge->m_radius = m_radius;
-
- edge->m_vertex1 = m_vertices[index + 0];
- edge->m_vertex2 = m_vertices[index + 1];
-
- if (index > 0)
- {
- edge->m_vertex0 = m_vertices[index - 1];
- edge->m_hasVertex0 = true;
- }
- else
- {
- edge->m_vertex0 = m_prevVertex;
- edge->m_hasVertex0 = m_hasPrevVertex;
- }
-
- if (index < m_count - 2)
- {
- edge->m_vertex3 = m_vertices[index + 2];
- edge->m_hasVertex3 = true;
- }
- else
- {
- edge->m_vertex3 = m_nextVertex;
- edge->m_hasVertex3 = m_hasNextVertex;
- }
-}
-
-bool b2ChainShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
-{
- B2_NOT_USED(xf);
- B2_NOT_USED(p);
- return false;
-}
-
-bool b2ChainShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
- const b2Transform& xf, int32 childIndex) const
-{
- b2Assert(childIndex < m_count);
-
- b2EdgeShape edgeShape;
-
- int32 i1 = childIndex;
- int32 i2 = childIndex + 1;
- if (i2 == m_count)
- {
- i2 = 0;
- }
-
- edgeShape.m_vertex1 = m_vertices[i1];
- edgeShape.m_vertex2 = m_vertices[i2];
-
- return edgeShape.RayCast(output, input, xf, 0);
-}
-
-void b2ChainShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
-{
- b2Assert(childIndex < m_count);
-
- int32 i1 = childIndex;
- int32 i2 = childIndex + 1;
- if (i2 == m_count)
- {
- i2 = 0;
- }
-
- b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
- b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
-
- aabb->lowerBound = b2Min(v1, v2);
- aabb->upperBound = b2Max(v1, v2);
-}
-
-void b2ChainShape::ComputeMass(b2MassData* massData, float32 density) const
-{
- B2_NOT_USED(density);
-
- massData->mass = 0.0f;
- massData->center.SetZero();
- massData->I = 0.0f;
-}
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Collision/Shapes/b2ChainShape.h>
+#include <Box2D/Collision/Shapes/b2EdgeShape.h>
+#include <new>
+#include <cstring>
+using namespace std;
+
+b2ChainShape::~b2ChainShape()
+{
+ b2Free(m_vertices);
+ m_vertices = NULL;
+ m_count = 0;
+}
+
+void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
+{
+ b2Assert(m_vertices == NULL && m_count == 0);
+ b2Assert(count >= 3);
+ m_count = count + 1;
+ m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
+ memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
+ m_vertices[count] = m_vertices[0];
+ m_prevVertex = m_vertices[m_count - 2];
+ m_nextVertex = m_vertices[1];
+ m_hasPrevVertex = true;
+ m_hasNextVertex = true;
+}
+
+void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
+{
+ b2Assert(m_vertices == NULL && m_count == 0);
+ b2Assert(count >= 2);
+ m_count = count;
+ m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
+ memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
+ m_hasPrevVertex = false;
+ m_hasNextVertex = false;
+}
+
+void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
+{
+ m_prevVertex = prevVertex;
+ m_hasPrevVertex = true;
+}
+
+void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
+{
+ m_nextVertex = nextVertex;
+ m_hasNextVertex = true;
+}
+
+b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2ChainShape));
+ b2ChainShape* clone = new (mem) b2ChainShape;
+ clone->CreateChain(m_vertices, m_count);
+ clone->m_prevVertex = m_prevVertex;
+ clone->m_nextVertex = m_nextVertex;
+ clone->m_hasPrevVertex = m_hasPrevVertex;
+ clone->m_hasNextVertex = m_hasNextVertex;
+ return clone;
+}
+
+int32 b2ChainShape::GetChildCount() const
+{
+ // edge count = vertex count - 1
+ return m_count - 1;
+}
+
+void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
+{
+ b2Assert(0 <= index && index < m_count - 1);
+ edge->m_type = b2Shape::e_edge;
+ edge->m_radius = m_radius;
+
+ edge->m_vertex1 = m_vertices[index + 0];
+ edge->m_vertex2 = m_vertices[index + 1];
+
+ if (index > 0)
+ {
+ edge->m_vertex0 = m_vertices[index - 1];
+ edge->m_hasVertex0 = true;
+ }
+ else
+ {
+ edge->m_vertex0 = m_prevVertex;
+ edge->m_hasVertex0 = m_hasPrevVertex;
+ }
+
+ if (index < m_count - 2)
+ {
+ edge->m_vertex3 = m_vertices[index + 2];
+ edge->m_hasVertex3 = true;
+ }
+ else
+ {
+ edge->m_vertex3 = m_nextVertex;
+ edge->m_hasVertex3 = m_hasNextVertex;
+ }
+}
+
+bool b2ChainShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
+{
+ B2_NOT_USED(xf);
+ B2_NOT_USED(p);
+ return false;
+}
+
+bool b2ChainShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& xf, int32 childIndex) const
+{
+ b2Assert(childIndex < m_count);
+
+ b2EdgeShape edgeShape;
+
+ int32 i1 = childIndex;
+ int32 i2 = childIndex + 1;
+ if (i2 == m_count)
+ {
+ i2 = 0;
+ }
+
+ edgeShape.m_vertex1 = m_vertices[i1];
+ edgeShape.m_vertex2 = m_vertices[i2];
+
+ return edgeShape.RayCast(output, input, xf, 0);
+}
+
+void b2ChainShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
+{
+ b2Assert(childIndex < m_count);
+
+ int32 i1 = childIndex;
+ int32 i2 = childIndex + 1;
+ if (i2 == m_count)
+ {
+ i2 = 0;
+ }
+
+ b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
+ b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
+
+ aabb->lowerBound = b2Min(v1, v2);
+ aabb->upperBound = b2Max(v1, v2);
+}
+
+void b2ChainShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ B2_NOT_USED(density);
+
+ massData->mass = 0.0f;
+ massData->center.SetZero();
+ massData->I = 0.0f;
+}
View
200 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2CircleShape.cpp
@@ -1,100 +1,100 @@
-/*
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Collision/Shapes/b2CircleShape.h>
-#include <new>
-using namespace std;
-
-b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
-{
- void* mem = allocator->Allocate(sizeof(b2CircleShape));
- b2CircleShape* clone = new (mem) b2CircleShape;
- *clone = *this;
- return clone;
-}
-
-int32 b2CircleShape::GetChildCount() const
-{
- return 1;
-}
-
-bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
-{
- b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
- b2Vec2 d = p - center;
- return b2Dot(d, d) <= m_radius * m_radius;
-}
-
-// Collision Detection in Interactive 3D Environments by Gino van den Bergen
-// From Section 3.1.2
-// x = s + a * r
-// norm(x) = radius
-bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
- const b2Transform& transform, int32 childIndex) const
-{
- B2_NOT_USED(childIndex);
-
- b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
- b2Vec2 s = input.p1 - position;
- float32 b = b2Dot(s, s) - m_radius * m_radius;
-
- // Solve quadratic equation.
- b2Vec2 r = input.p2 - input.p1;
- float32 c = b2Dot(s, r);
- float32 rr = b2Dot(r, r);
- float32 sigma = c * c - rr * b;
-
- // Check for negative discriminant and short segment.
- if (sigma < 0.0f || rr < b2_epsilon)
- {
- return false;
- }
-
- // Find the point of intersection of the line with the circle.
- float32 a = -(c + b2Sqrt(sigma));
-
- // Is the intersection point on the segment?
- if (0.0f <= a && a <= input.maxFraction * rr)
- {
- a /= rr;
- output->fraction = a;
- output->normal = s + a * r;
- output->normal.Normalize();
- return true;
- }
-
- return false;
-}
-
-void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const
-{
- B2_NOT_USED(childIndex);
-
- b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
- aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
- aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
-}
-
-void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
-{
- massData->mass = density * b2_pi * m_radius * m_radius;
- massData->center = m_p;
-
- // inertia about the local origin
- massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
-}
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Collision/Shapes/b2CircleShape.h>
+#include <new>
+using namespace std;
+
+b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2CircleShape));
+ b2CircleShape* clone = new (mem) b2CircleShape;
+ *clone = *this;
+ return clone;
+}
+
+int32 b2CircleShape::GetChildCount() const
+{
+ return 1;
+}
+
+bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
+{
+ b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
+ b2Vec2 d = p - center;
+ return b2Dot(d, d) <= m_radius * m_radius;
+}
+
+// Collision Detection in Interactive 3D Environments by Gino van den Bergen
+// From Section 3.1.2
+// x = s + a * r
+// norm(x) = radius
+bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& transform, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
+ b2Vec2 s = input.p1 - position;
+ float32 b = b2Dot(s, s) - m_radius * m_radius;
+
+ // Solve quadratic equation.
+ b2Vec2 r = input.p2 - input.p1;
+ float32 c = b2Dot(s, r);
+ float32 rr = b2Dot(r, r);
+ float32 sigma = c * c - rr * b;
+
+ // Check for negative discriminant and short segment.
+ if (sigma < 0.0f || rr < b2_epsilon)
+ {
+ return false;
+ }
+
+ // Find the point of intersection of the line with the circle.
+ float32 a = -(c + b2Sqrt(sigma));
+
+ // Is the intersection point on the segment?
+ if (0.0f <= a && a <= input.maxFraction * rr)
+ {
+ a /= rr;
+ output->fraction = a;
+ output->normal = s + a * r;
+ output->normal.Normalize();
+ return true;
+ }
+
+ return false;
+}
+
+void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
+ aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
+ aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
+}
+
+void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ massData->mass = density * b2_pi * m_radius * m_radius;
+ massData->center = m_p;
+
+ // inertia about the local origin
+ massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
+}
View
278 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2EdgeShape.cpp
@@ -1,139 +1,139 @@
-/*
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Collision/Shapes/b2EdgeShape.h>
-#include <new>
-using namespace std;
-
-void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)
-{
- m_vertex1 = v1;
- m_vertex2 = v2;
- m_hasVertex0 = false;
- m_hasVertex3 = false;
-}
-
-b2Shape* b2EdgeShape::Clone(b2BlockAllocator* allocator) const
-{
- void* mem = allocator->Allocate(sizeof(b2EdgeShape));
- b2EdgeShape* clone = new (mem) b2EdgeShape;
- *clone = *this;
- return clone;
-}
-
-int32 b2EdgeShape::GetChildCount() const
-{
- return 1;
-}
-
-bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
-{
- B2_NOT_USED(xf);
- B2_NOT_USED(p);
- return false;
-}
-
-// p = p1 + t * d
-// v = v1 + s * e
-// p1 + t * d = v1 + s * e
-// s * e - t * d = p1 - v1
-bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
- const b2Transform& xf, int32 childIndex) const
-{
- B2_NOT_USED(childIndex);
-
- // Put the ray into the edge's frame of reference.
- b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
- b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
- b2Vec2 d = p2 - p1;
-
- b2Vec2 v1 = m_vertex1;
- b2Vec2 v2 = m_vertex2;
- b2Vec2 e = v2 - v1;
- b2Vec2 normal(e.y, -e.x);
- normal.Normalize();
-
- // q = p1 + t * d
- // dot(normal, q - v1) = 0
- // dot(normal, p1 - v1) + t * dot(normal, d) = 0
- float32 numerator = b2Dot(normal, v1 - p1);
- float32 denominator = b2Dot(normal, d);
-
- if (denominator == 0.0f)
- {
- return false;
- }
-
- float32 t = numerator / denominator;
- if (t < 0.0f || input.maxFraction < t)
- {
- return false;
- }
-
- b2Vec2 q = p1 + t * d;
-
- // q = v1 + s * r
- // s = dot(q - v1, r) / dot(r, r)
- b2Vec2 r = v2 - v1;
- float32 rr = b2Dot(r, r);
- if (rr == 0.0f)
- {
- return false;
- }
-
- float32 s = b2Dot(q - v1, r) / rr;
- if (s < 0.0f || 1.0f < s)
- {
- return false;
- }
-
- output->fraction = t;
- if (numerator > 0.0f)
- {
- output->normal = -normal;
- }
- else
- {
- output->normal = normal;
- }
- return true;
-}
-
-void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
-{
- B2_NOT_USED(childIndex);
-
- b2Vec2 v1 = b2Mul(xf, m_vertex1);
- b2Vec2 v2 = b2Mul(xf, m_vertex2);
-
- b2Vec2 lower = b2Min(v1, v2);
- b2Vec2 upper = b2Max(v1, v2);
-
- b2Vec2 r(m_radius, m_radius);
- aabb->lowerBound = lower - r;
- aabb->upperBound = upper + r;
-}
-
-void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const
-{
- B2_NOT_USED(density);
-
- massData->mass = 0.0f;
- massData->center = 0.5f * (m_vertex1 + m_vertex2);
- massData->I = 0.0f;
-}
+/*
+* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Collision/Shapes/b2EdgeShape.h>
+#include <new>
+using namespace std;
+
+void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)
+{
+ m_vertex1 = v1;
+ m_vertex2 = v2;
+ m_hasVertex0 = false;
+ m_hasVertex3 = false;
+}
+
+b2Shape* b2EdgeShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2EdgeShape));
+ b2EdgeShape* clone = new (mem) b2EdgeShape;
+ *clone = *this;
+ return clone;
+}
+
+int32 b2EdgeShape::GetChildCount() const
+{
+ return 1;
+}
+
+bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
+{
+ B2_NOT_USED(xf);
+ B2_NOT_USED(p);
+ return false;
+}
+
+// p = p1 + t * d
+// v = v1 + s * e
+// p1 + t * d = v1 + s * e
+// s * e - t * d = p1 - v1
+bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ // Put the ray into the edge's frame of reference.
+ b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
+ b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
+ b2Vec2 d = p2 - p1;
+
+ b2Vec2 v1 = m_vertex1;
+ b2Vec2 v2 = m_vertex2;
+ b2Vec2 e = v2 - v1;
+ b2Vec2 normal(e.y, -e.x);
+ normal.Normalize();
+
+ // q = p1 + t * d
+ // dot(normal, q - v1) = 0
+ // dot(normal, p1 - v1) + t * dot(normal, d) = 0
+ float32 numerator = b2Dot(normal, v1 - p1);
+ float32 denominator = b2Dot(normal, d);
+
+ if (denominator == 0.0f)
+ {
+ return false;
+ }
+
+ float32 t = numerator / denominator;
+ if (t < 0.0f || input.maxFraction < t)
+ {
+ return false;
+ }
+
+ b2Vec2 q = p1 + t * d;
+
+ // q = v1 + s * r
+ // s = dot(q - v1, r) / dot(r, r)
+ b2Vec2 r = v2 - v1;
+ float32 rr = b2Dot(r, r);
+ if (rr == 0.0f)
+ {
+ return false;
+ }
+
+ float32 s = b2Dot(q - v1, r) / rr;
+ if (s < 0.0f || 1.0f < s)
+ {
+ return false;
+ }
+
+ output->fraction = t;
+ if (numerator > 0.0f)
+ {
+ output->normal = -normal;
+ }
+ else
+ {
+ output->normal = normal;
+ }
+ return true;
+}
+
+void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 v1 = b2Mul(xf, m_vertex1);
+ b2Vec2 v2 = b2Mul(xf, m_vertex2);
+
+ b2Vec2 lower = b2Min(v1, v2);
+ b2Vec2 upper = b2Max(v1, v2);
+
+ b2Vec2 r(m_radius, m_radius);
+ aabb->lowerBound = lower - r;
+ aabb->upperBound = upper + r;
+}
+
+void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ B2_NOT_USED(density);
+
+ massData->mass = 0.0f;
+ massData->center = 0.5f * (m_vertex1 + m_vertex2);
+ massData->I = 0.0f;
+}
View
722 3rdparty/box2d-2.2.1/Box2D/Collision/Shapes/b2PolygonShape.cpp
@@ -1,361 +1,361 @@
-/*
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Collision/Shapes/b2PolygonShape.h>
-#include <new>
-
-b2Shape* b2PolygonShape::Clone(b2BlockAllocator* allocator) const
-{
- void* mem = allocator->Allocate(sizeof(b2PolygonShape));
- b2PolygonShape* clone = new (mem) b2PolygonShape;
- *clone = *this;
- return clone;
-}
-
-void b2PolygonShape::SetAsBox(float32 hx, float32 hy)
-{
- m_vertexCount = 4;
- m_vertices[0].Set(-hx, -hy);
- m_vertices[1].Set( hx, -hy);
- m_vertices[2].Set( hx, hy);
- m_vertices[3].Set(-hx, hy);
- m_normals[0].Set(0.0f, -1.0f);
- m_normals[1].Set(1.0f, 0.0f);
- m_normals[2].Set(0.0f, 1.0f);
- m_normals[3].Set(-1.0f, 0.0f);
- m_centroid.SetZero();
-}
-
-void b2PolygonShape::SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle)
-{
- m_vertexCount = 4;
- m_vertices[0].Set(-hx, -hy);
- m_vertices[1].Set( hx, -hy);
- m_vertices[2].Set( hx, hy);
- m_vertices[3].Set(-hx, hy);
- m_normals[0].Set(0.0f, -1.0f);
- m_normals[1].Set(1.0f, 0.0f);
- m_normals[2].Set(0.0f, 1.0f);
- m_normals[3].Set(-1.0f, 0.0f);
- m_centroid = center;
-
- b2Transform xf;
- xf.p = center;
- xf.q.Set(angle);
-
- // Transform vertices and normals.
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- m_vertices[i] = b2Mul(xf, m_vertices[i]);
- m_normals[i] = b2Mul(xf.q, m_normals[i]);
- }
-}
-
-int32 b2PolygonShape::GetChildCount() const
-{
- return 1;
-}
-
-static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)
-{
- b2Assert(count >= 3);
-
- b2Vec2 c; c.Set(0.0f, 0.0f);
- float32 area = 0.0f;
-
- // 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);
-#if 0
- // This code would put the reference point inside the polygon.
- for (int32 i = 0; i < count; ++i)
- {
- pRef += vs[i];
- }
- pRef *= 1.0f / count;
-#endif
-
- const float32 inv3 = 1.0f / 3.0f;
-
- for (int32 i = 0; i < count; ++i)
- {
- // Triangle vertices.
- b2Vec2 p1 = pRef;
- b2Vec2 p2 = vs[i];
- b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
-
- b2Vec2 e1 = p2 - p1;
- b2Vec2 e2 = p3 - p1;
-
- float32 D = b2Cross(e1, e2);
-
- float32 triangleArea = 0.5f * D;
- area += triangleArea;
-
- // Area weighted centroid
- c += triangleArea * inv3 * (p1 + p2 + p3);
- }
-
- // Centroid
- b2Assert(area > b2_epsilon);
- c *= 1.0f / area;
- return c;
-}
-
-void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)
-{
- b2Assert(3 <= count && count <= b2_maxPolygonVertices);
- m_vertexCount = count;
-
- // Copy vertices.
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- m_vertices[i] = vertices[i];
- }
-
- // Compute normals. Ensure the edges have non-zero length.
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- int32 i1 = i;
- int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
- b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
- b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
- m_normals[i] = b2Cross(edge, 1.0f);
- m_normals[i].Normalize();
- }
-
-#ifdef _DEBUG
- // Ensure the polygon is convex and the interior
- // is to the left of each edge.
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- int32 i1 = i;
- int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
- b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
-
- for (int32 j = 0; j < m_vertexCount; ++j)
- {
- // Don't check vertices on the current edge.
- if (j == i1 || j == i2)
- {
- continue;
- }
-
- b2Vec2 r = m_vertices[j] - m_vertices[i1];
-
- // If this crashes, your polygon is non-convex, has colinear edges,
- // or the winding order is wrong.
- float32 s = b2Cross(edge, r);
- b2Assert(s > 0.0f && "ERROR: Please ensure your polygon is convex and has a CCW winding order");
- }
- }
-#endif
-
- // Compute the polygon centroid.
- m_centroid = ComputeCentroid(m_vertices, m_vertexCount);
-}
-
-bool b2PolygonShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
-{
- b2Vec2 pLocal = b2MulT(xf.q, p - xf.p);
-
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- float32 dot = b2Dot(m_normals[i], pLocal - m_vertices[i]);
- if (dot > 0.0f)
- {
- return false;
- }
- }
-
- return true;
-}
-
-bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
- const b2Transform& xf, int32 childIndex) const
-{
- B2_NOT_USED(childIndex);
-
- // Put the ray into the polygon's frame of reference.
- b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
- b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
- b2Vec2 d = p2 - p1;
-
- float32 lower = 0.0f, upper = input.maxFraction;
-
- int32 index = -1;
-
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- // p = p1 + a * d
- // dot(normal, p - v) = 0
- // dot(normal, p1 - v) + a * dot(normal, d) = 0
- float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);
- float32 denominator = b2Dot(m_normals[i], d);
-
- if (denominator == 0.0f)
- {
- if (numerator < 0.0f)
- {
- return false;
- }
- }
- else
- {
- // Note: we want this predicate without division:
- // lower < numerator / denominator, where denominator < 0
- // Since denominator < 0, we have to flip the inequality:
- // lower < numerator / denominator <==> denominator * lower > numerator.
- if (denominator < 0.0f && numerator < lower * denominator)
- {
- // Increase lower.
- // The segment enters this half-space.
- lower = numerator / denominator;
- index = i;
- }
- else if (denominator > 0.0f && numerator < upper * denominator)
- {
- // Decrease upper.
- // The segment exits this half-space.
- upper = numerator / denominator;
- }
- }
-
- // The use of epsilon here causes the assert on lower to trip
- // in some cases. Apparently the use of epsilon was to make edge
- // shapes work, but now those are handled separately.
- //if (upper < lower - b2_epsilon)
- if (upper < lower)
- {
- return false;
- }
- }
-
- b2Assert(0.0f <= lower && lower <= input.maxFraction);
-
- if (index >= 0)
- {
- output->fraction = lower;
- output->normal = b2Mul(xf.q, m_normals[index]);
- return true;
- }
-
- return false;
-}
-
-void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
-{
- B2_NOT_USED(childIndex);
-
- b2Vec2 lower = b2Mul(xf, m_vertices[0]);
- b2Vec2 upper = lower;
-
- for (int32 i = 1; i < m_vertexCount; ++i)
- {
- b2Vec2 v = b2Mul(xf, m_vertices[i]);
- lower = b2Min(lower, v);
- upper = b2Max(upper, v);
- }
-
- b2Vec2 r(m_radius, m_radius);
- aabb->lowerBound = lower - r;
- aabb->upperBound = upper + r;
-}
-
-void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const
-{
- // Polygon mass, centroid, and inertia.
- // Let rho be the polygon density in mass per unit area.
- // Then:
- // mass = rho * int(dA)
- // centroid.x = (1/mass) * rho * int(x * dA)
- // centroid.y = (1/mass) * rho * int(y * dA)
- // I = rho * int((x*x + y*y) * dA)
- //
- // We can compute these integrals by summing all the integrals
- // for each triangle of the polygon. To evaluate the integral
- // for a single triangle, we make a change of variables to
- // the (u,v) coordinates of the triangle:
- // x = x0 + e1x * u + e2x * v
- // y = y0 + e1y * u + e2y * v
- // where 0 <= u && 0 <= v && u + v <= 1.
- //
- // We integrate u from [0,1-v] and then v from [0,1].
- // We also need to use the Jacobian of the transformation:
- // D = cross(e1, e2)
- //
- // Simplification: triangle centroid = (1/3) * (p1 + p2 + p3)
- //
- // The rest of the derivation is handled by computer algebra.
-
- b2Assert(m_vertexCount >= 3);
-
- b2Vec2 center; center.Set(0.0f, 0.0f);
- float32 area = 0.0f;
- float32 I = 0.0f;
-
- // s is the reference point for forming triangles.
- // It's location doesn't change the result (except for rounding error).
- b2Vec2 s(0.0f, 0.0f);
-
- // This code would put the reference point inside the polygon.
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- s += m_vertices[i];
- }
- s *= 1.0f / m_vertexCount;
-
- const float32 k_inv3 = 1.0f / 3.0f;
-
- for (int32 i = 0; i < m_vertexCount; ++i)
- {
- // Triangle vertices.
- b2Vec2 e1 = m_vertices[i] - s;
- b2Vec2 e2 = i + 1 < m_vertexCount ? m_vertices[i+1] - s : m_vertices[0] - s;
-
- float32 D = b2Cross(e1, e2);
-
- float32 triangleArea = 0.5f * D;
- area += triangleArea;
-
- // Area weighted centroid
- center += triangleArea * k_inv3 * (e1 + e2);
-
- float32 ex1 = e1.x, ey1 = e1.y;
- float32 ex2 = e2.x, ey2 = e2.y;
-
- float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;
- float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;
-
- I += (0.25f * k_inv3 * D) * (intx2 + inty2);
- }
-
- // Total mass
- massData->mass = density * area;
-
- // Center of mass
- b2Assert(area > b2_epsilon);
- center *= 1.0f / area;
- massData->center = center + s;
-
- // Inertia tensor relative to the local origin (point s).
- massData->I = density * I;
-
- // Shift to center of mass then to original body origin.
- massData->I += massData->mass * (b2Dot(massData->center, massData->center) - b2Dot(center, center));
-}
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Collision/Shapes/b2PolygonShape.h>
+#include <new>
+
+b2Shape* b2PolygonShape::Clone(b2BlockAllocator* allocator) const
+{
+ void* mem = allocator->Allocate(sizeof(b2PolygonShape));
+ b2PolygonShape* clone = new (mem) b2PolygonShape;
+ *clone = *this;
+ return clone;
+}
+
+void b2PolygonShape::SetAsBox(float32 hx, float32 hy)
+{
+ m_vertexCount = 4;
+ m_vertices[0].Set(-hx, -hy);
+ m_vertices[1].Set( hx, -hy);
+ m_vertices[2].Set( hx, hy);
+ m_vertices[3].Set(-hx, hy);
+ m_normals[0].Set(0.0f, -1.0f);
+ m_normals[1].Set(1.0f, 0.0f);
+ m_normals[2].Set(0.0f, 1.0f);
+ m_normals[3].Set(-1.0f, 0.0f);
+ m_centroid.SetZero();
+}
+
+void b2PolygonShape::SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle)
+{
+ m_vertexCount = 4;
+ m_vertices[0].Set(-hx, -hy);
+ m_vertices[1].Set( hx, -hy);
+ m_vertices[2].Set( hx, hy);
+ m_vertices[3].Set(-hx, hy);
+ m_normals[0].Set(0.0f, -1.0f);
+ m_normals[1].Set(1.0f, 0.0f);
+ m_normals[2].Set(0.0f, 1.0f);
+ m_normals[3].Set(-1.0f, 0.0f);
+ m_centroid = center;
+
+ b2Transform xf;
+ xf.p = center;
+ xf.q.Set(angle);
+
+ // Transform vertices and normals.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ m_vertices[i] = b2Mul(xf, m_vertices[i]);
+ m_normals[i] = b2Mul(xf.q, m_normals[i]);
+ }
+}
+
+int32 b2PolygonShape::GetChildCount() const
+{
+ return 1;
+}
+
+static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)
+{
+ b2Assert(count >= 3);
+
+ b2Vec2 c; c.Set(0.0f, 0.0f);
+ float32 area = 0.0f;
+
+ // 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);
+#if 0
+ // This code would put the reference point inside the polygon.
+ for (int32 i = 0; i < count; ++i)
+ {
+ pRef += vs[i];
+ }
+ pRef *= 1.0f / count;
+#endif
+
+ const float32 inv3 = 1.0f / 3.0f;
+
+ for (int32 i = 0; i < count; ++i)
+ {
+ // Triangle vertices.
+ b2Vec2 p1 = pRef;
+ b2Vec2 p2 = vs[i];
+ b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
+
+ b2Vec2 e1 = p2 - p1;
+ b2Vec2 e2 = p3 - p1;
+
+ float32 D = b2Cross(e1, e2);
+
+ float32 triangleArea = 0.5f * D;
+ area += triangleArea;
+
+ // Area weighted centroid
+ c += triangleArea * inv3 * (p1 + p2 + p3);
+ }
+
+ // Centroid
+ b2Assert(area > b2_epsilon);
+ c *= 1.0f / area;
+ return c;
+}
+
+void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)
+{
+ b2Assert(3 <= count && count <= b2_maxPolygonVertices);
+ m_vertexCount = count;
+
+ // Copy vertices.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ m_vertices[i] = vertices[i];
+ }
+
+ // Compute normals. Ensure the edges have non-zero length.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ int32 i1 = i;
+ int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
+ b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
+ b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
+ m_normals[i] = b2Cross(edge, 1.0f);
+ m_normals[i].Normalize();
+ }
+
+#ifdef _DEBUG
+ // Ensure the polygon is convex and the interior
+ // is to the left of each edge.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ int32 i1 = i;
+ int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
+ b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
+
+ for (int32 j = 0; j < m_vertexCount; ++j)
+ {
+ // Don't check vertices on the current edge.
+ if (j == i1 || j == i2)
+ {
+ continue;
+ }
+
+ b2Vec2 r = m_vertices[j] - m_vertices[i1];
+
+ // If this crashes, your polygon is non-convex, has colinear edges,
+ // or the winding order is wrong.
+ float32 s = b2Cross(edge, r);
+ b2Assert(s > 0.0f && "ERROR: Please ensure your polygon is convex and has a CCW winding order");
+ }
+ }
+#endif
+
+ // Compute the polygon centroid.
+ m_centroid = ComputeCentroid(m_vertices, m_vertexCount);
+}
+
+bool b2PolygonShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
+{
+ b2Vec2 pLocal = b2MulT(xf.q, p - xf.p);
+
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ float32 dot = b2Dot(m_normals[i], pLocal - m_vertices[i]);
+ if (dot > 0.0f)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
+ const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ // Put the ray into the polygon's frame of reference.
+ b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
+ b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
+ b2Vec2 d = p2 - p1;
+
+ float32 lower = 0.0f, upper = input.maxFraction;
+
+ int32 index = -1;
+
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ // p = p1 + a * d
+ // dot(normal, p - v) = 0
+ // dot(normal, p1 - v) + a * dot(normal, d) = 0
+ float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);
+ float32 denominator = b2Dot(m_normals[i], d);
+
+ if (denominator == 0.0f)
+ {
+ if (numerator < 0.0f)
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // Note: we want this predicate without division:
+ // lower < numerator / denominator, where denominator < 0
+ // Since denominator < 0, we have to flip the inequality:
+ // lower < numerator / denominator <==> denominator * lower > numerator.
+ if (denominator < 0.0f && numerator < lower * denominator)
+ {
+ // Increase lower.
+ // The segment enters this half-space.
+ lower = numerator / denominator;
+ index = i;
+ }
+ else if (denominator > 0.0f && numerator < upper * denominator)
+ {
+ // Decrease upper.
+ // The segment exits this half-space.
+ upper = numerator / denominator;
+ }
+ }
+
+ // The use of epsilon here causes the assert on lower to trip
+ // in some cases. Apparently the use of epsilon was to make edge
+ // shapes work, but now those are handled separately.
+ //if (upper < lower - b2_epsilon)
+ if (upper < lower)
+ {
+ return false;
+ }
+ }
+
+ b2Assert(0.0f <= lower && lower <= input.maxFraction);
+
+ if (index >= 0)
+ {
+ output->fraction = lower;
+ output->normal = b2Mul(xf.q, m_normals[index]);
+ return true;
+ }
+
+ return false;
+}
+
+void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
+{
+ B2_NOT_USED(childIndex);
+
+ b2Vec2 lower = b2Mul(xf, m_vertices[0]);
+ b2Vec2 upper = lower;
+
+ for (int32 i = 1; i < m_vertexCount; ++i)
+ {
+ b2Vec2 v = b2Mul(xf, m_vertices[i]);
+ lower = b2Min(lower, v);
+ upper = b2Max(upper, v);
+ }
+
+ b2Vec2 r(m_radius, m_radius);
+ aabb->lowerBound = lower - r;
+ aabb->upperBound = upper + r;
+}
+
+void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const
+{
+ // Polygon mass, centroid, and inertia.
+ // Let rho be the polygon density in mass per unit area.
+ // Then:
+ // mass = rho * int(dA)
+ // centroid.x = (1/mass) * rho * int(x * dA)
+ // centroid.y = (1/mass) * rho * int(y * dA)
+ // I = rho * int((x*x + y*y) * dA)
+ //
+ // We can compute these integrals by summing all the integrals
+ // for each triangle of the polygon. To evaluate the integral
+ // for a single triangle, we make a change of variables to
+ // the (u,v) coordinates of the triangle:
+ // x = x0 + e1x * u + e2x * v
+ // y = y0 + e1y * u + e2y * v
+ // where 0 <= u && 0 <= v && u + v <= 1.
+ //
+ // We integrate u from [0,1-v] and then v from [0,1].
+ // We also need to use the Jacobian of the transformation:
+ // D = cross(e1, e2)
+ //
+ // Simplification: triangle centroid = (1/3) * (p1 + p2 + p3)
+ //
+ // The rest of the derivation is handled by computer algebra.
+
+ b2Assert(m_vertexCount >= 3);
+
+ b2Vec2 center; center.Set(0.0f, 0.0f);
+ float32 area = 0.0f;
+ float32 I = 0.0f;
+
+ // s is the reference point for forming triangles.
+ // It's location doesn't change the result (except for rounding error).
+ b2Vec2 s(0.0f, 0.0f);
+
+ // This code would put the reference point inside the polygon.
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ s += m_vertices[i];
+ }
+ s *= 1.0f / m_vertexCount;
+
+ const float32 k_inv3 = 1.0f / 3.0f;
+
+ for (int32 i = 0; i < m_vertexCount; ++i)
+ {
+ // Triangle vertices.
+ b2Vec2 e1 = m_vertices[i] - s;
+ b2Vec2 e2 = i + 1 < m_vertexCount ? m_vertices[i+1] - s : m_vertices[0] - s;
+
+ float32 D = b2Cross(e1, e2);
+
+ float32 triangleArea = 0.5f * D;
+ area += triangleArea;
+
+ // Area weighted centroid
+ center += triangleArea * k_inv3 * (e1 + e2);
+
+ float32 ex1 = e1.x, ey1 = e1.y;
+ float32 ex2 = e2.x, ey2 = e2.y;
+
+ float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;
+ float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;
+
+ I += (0.25f * k_inv3 * D) * (intx2 + inty2);
+ }
+
+ // Total mass
+ massData->mass = density * area;
+
+ // Center of mass
+ b2Assert(area > b2_epsilon);
+ center *= 1.0f / area;
+ massData->center = center + s;
+
+ // Inertia tensor relative to the local origin (point s).
+ massData->I = density * I;
+
+ // Shift to center of mass then to original body origin.
+ massData->I += massData->mass * (b2Dot(massData->center, massData->center) - b2Dot(center, center));
+}
View
434 3rdparty/box2d-2.2.1/Box2D/Common/b2BlockAllocator.cpp
@@ -1,217 +1,217 @@
-/*
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Common/b2BlockAllocator.h>
-#include <cstdlib>
-#include <climits>
-#include <cstring>
-#include <memory>
-using namespace std;
-
-int32 b2BlockAllocator::s_blockSizes[b2_blockSizes] =
-{
- 16, // 0
- 32, // 1
- 64, // 2
- 96, // 3
- 128, // 4
- 160, // 5
- 192, // 6
- 224, // 7
- 256, // 8
- 320, // 9
- 384, // 10
- 448, // 11
- 512, // 12
- 640, // 13
-};
-uint8 b2BlockAllocator::s_blockSizeLookup[b2_maxBlockSize + 1];
-bool b2BlockAllocator::s_blockSizeLookupInitialized;
-
-struct b2Chunk
-{
- int32 blockSize;
- b2Block* blocks;
-};
-
-struct b2Block
-{
- b2Block* next;
-};
-
-b2BlockAllocator::b2BlockAllocator()
-{
- b2Assert(b2_blockSizes < UCHAR_MAX);
-
- m_chunkSpace = b2_chunkArrayIncrement;
- m_chunkCount = 0;
- m_chunks = (b2Chunk*)b2Alloc(m_chunkSpace * sizeof(b2Chunk));
-
- memset(m_chunks, 0, m_chunkSpace * sizeof(b2Chunk));
- memset(m_freeLists, 0, sizeof(m_freeLists));
-
- if (s_blockSizeLookupInitialized == false)
- {
- int32 j = 0;
- for (int32 i = 1; i <= b2_maxBlockSize; ++i)
- {
- b2Assert(j < b2_blockSizes);
- if (i <= s_blockSizes[j])
- {
- s_blockSizeLookup[i] = (uint8)j;
- }
- else
- {
- ++j;
- s_blockSizeLookup[i] = (uint8)j;
- }
- }
-
- s_blockSizeLookupInitialized = true;
- }
-}
-
-b2BlockAllocator::~b2BlockAllocator()
-{
- for (int32 i = 0; i < m_chunkCount; ++i)
- {
- b2Free(m_chunks[i].blocks);
- }
-
- b2Free(m_chunks);
-}
-
-void* b2BlockAllocator::Allocate(int32 size)
-{
- if (size == 0)
- return NULL;
-
- b2Assert(0 < size);
-
- if (size > b2_maxBlockSize)
- {
- return b2Alloc(size);
- }
-
- int32 index = s_blockSizeLookup[size];
- b2Assert(0 <= index && index < b2_blockSizes);
-
- if (m_freeLists[index])
- {
- b2Block* block = m_freeLists[index];
- m_freeLists[index] = block->next;
- return block;
- }
- else
- {
- if (m_chunkCount == m_chunkSpace)
- {
- b2Chunk* oldChunks = m_chunks;
- m_chunkSpace += b2_chunkArrayIncrement;
- m_chunks = (b2Chunk*)b2Alloc(m_chunkSpace * sizeof(b2Chunk));
- memcpy(m_chunks, oldChunks, m_chunkCount * sizeof(b2Chunk));
- memset(m_chunks + m_chunkCount, 0, b2_chunkArrayIncrement * sizeof(b2Chunk));
- b2Free(oldChunks);
- }
-
- b2Chunk* chunk = m_chunks + m_chunkCount;
- chunk->blocks = (b2Block*)b2Alloc(b2_chunkSize);
-#if defined(_DEBUG)
- memset(chunk->blocks, 0xcd, b2_chunkSize);
-#endif
- int32 blockSize = s_blockSizes[index];
- chunk->blockSize = blockSize;
- int32 blockCount = b2_chunkSize / blockSize;
- b2Assert(blockCount * blockSize <= b2_chunkSize);
- for (int32 i = 0; i < blockCount - 1; ++i)
- {
- b2Block* block = (b2Block*)((int8*)chunk->blocks + blockSize * i);
- b2Block* next = (b2Block*)((int8*)chunk->blocks + blockSize * (i + 1));
- block->next = next;
- }
- b2Block* last = (b2Block*)((int8*)chunk->blocks + blockSize * (blockCount - 1));
- last->next = NULL;
-
- m_freeLists[index] = chunk->blocks->next;
- ++m_chunkCount;
-
- return chunk->blocks;
- }
-}
-
-void b2BlockAllocator::Free(void* p, int32 size)
-{
- if (size == 0)
- {
- return;
- }
-
- b2Assert(0 < size);
-
- if (size > b2_maxBlockSize)
- {
- b2Free(p);
- return;
- }
-
- int32 index = s_blockSizeLookup[size];
- b2Assert(0 <= index && index < b2_blockSizes);
-
-#ifdef _DEBUG
- // Verify the memory address and size is valid.
- int32 blockSize = s_blockSizes[index];
- bool found = false;
- for (int32 i = 0; i < m_chunkCount; ++i)
- {
- b2Chunk* chunk = m_chunks + i;
- if (chunk->blockSize != blockSize)
- {
- b2Assert( (int8*)p + blockSize <= (int8*)chunk->blocks ||
- (int8*)chunk->blocks + b2_chunkSize <= (int8*)p);
- }
- else
- {
- if ((int8*)chunk->blocks <= (int8*)p && (int8*)p + blockSize <= (int8*)chunk->blocks + b2_chunkSize)
- {
- found = true;
- }
- }
- }
-
- b2Assert(found);
-
- memset(p, 0xfd, blockSize);
-#endif
-
- b2Block* block = (b2Block*)p;
- block->next = m_freeLists[index];
- m_freeLists[index] = block;
-}
-
-void b2BlockAllocator::Clear()
-{
- for (int32 i = 0; i < m_chunkCount; ++i)
- {
- b2Free(m_chunks[i].blocks);
- }
-
- m_chunkCount = 0;
- memset(m_chunks, 0, m_chunkSpace * sizeof(b2Chunk));
-
- memset(m_freeLists, 0, sizeof(m_freeLists));
-}
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Common/b2BlockAllocator.h>
+#include <cstdlib>
+#include <climits>
+#include <cstring>
+#include <memory>
+using namespace std;
+
+int32 b2BlockAllocator::s_blockSizes[b2_blockSizes] =
+{
+ 16, // 0
+ 32, // 1
+ 64, // 2
+ 96, // 3
+ 128, // 4
+ 160, // 5
+ 192, // 6
+ 224, // 7
+ 256, // 8
+ 320, // 9
+ 384, // 10
+ 448, // 11
+ 512, // 12
+ 640, // 13
+};
+uint8 b2BlockAllocator::s_blockSizeLookup[b2_maxBlockSize + 1];
+bool b2BlockAllocator::s_blockSizeLookupInitialized;
+
+struct b2Chunk
+{
+ int32 blockSize;
+ b2Block* blocks;
+};
+
+struct b2Block
+{
+ b2Block* next;
+};
+
+b2BlockAllocator::b2BlockAllocator()
+{
+ b2Assert(b2_blockSizes < UCHAR_MAX);
+
+ m_chunkSpace = b2_chunkArrayIncrement;
+ m_chunkCount = 0;
+ m_chunks = (b2Chunk*)b2Alloc(m_chunkSpace * sizeof(b2Chunk));
+
+ memset(m_chunks, 0, m_chunkSpace * sizeof(b2Chunk));
+ memset(m_freeLists, 0, sizeof(m_freeLists));
+
+ if (s_blockSizeLookupInitialized == false)
+ {
+ int32 j = 0;
+ for (int32 i = 1; i <= b2_maxBlockSize; ++i)
+ {
+ b2Assert(j < b2_blockSizes);
+ if (i <= s_blockSizes[j])
+ {
+ s_blockSizeLookup[i] = (uint8)j;
+ }
+ else
+ {
+ ++j;
+ s_blockSizeLookup[i] = (uint8)j;
+ }
+ }
+
+ s_blockSizeLookupInitialized = true;
+ }
+}
+
+b2BlockAllocator::~b2BlockAllocator()
+{
+ for (int32 i = 0; i < m_chunkCount; ++i)
+ {
+ b2Free(m_chunks[i].blocks);
+ }
+
+ b2Free(m_chunks);
+}
+
+void* b2BlockAllocator::Allocate(int32 size)
+{
+ if (size == 0)
+ return NULL;
+
+ b2Assert(0 < size);
+
+ if (size > b2_maxBlockSize)
+ {
+ return b2Alloc(size);
+ }
+
+ int32 index = s_blockSizeLookup[size];
+ b2Assert(0 <= index && index < b2_blockSizes);
+
+ if (m_freeLists[index])
+ {
+ b2Block* block = m_freeLists[index];
+ m_freeLists[index] = block->next;
+ return block;
+ }
+ else
+ {
+ if (m_chunkCount == m_chunkSpace)
+ {
+ b2Chunk* oldChunks = m_chunks;
+ m_chunkSpace += b2_chunkArrayIncrement;
+ m_chunks = (b2Chunk*)b2Alloc(m_chunkSpace * sizeof(b2Chunk));
+ memcpy(m_chunks, oldChunks, m_chunkCount * sizeof(b2Chunk));
+ memset(m_chunks + m_chunkCount, 0, b2_chunkArrayIncrement * sizeof(b2Chunk));
+ b2Free(oldChunks);
+ }
+
+ b2Chunk* chunk = m_chunks + m_chunkCount;
+ chunk->blocks = (b2Block*)b2Alloc(b2_chunkSize);
+#if defined(_DEBUG)
+ memset(chunk->blocks, 0xcd, b2_chunkSize);
+#endif
+ int32 blockSize = s_blockSizes[index];
+ chunk->blockSize = blockSize;
+ int32 blockCount = b2_chunkSize / blockSize;
+ b2Assert(blockCount * blockSize <= b2_chunkSize);
+ for (int32 i = 0; i < blockCount - 1; ++i)
+ {
+ b2Block* block = (b2Block*)((int8*)chunk->blocks + blockSize * i);
+ b2Block* next = (b2Block*)((int8*)chunk->blocks + blockSize * (i + 1));
+ block->next = next;
+ }
+ b2Block* last = (b2Block*)((int8*)chunk->blocks + blockSize * (blockCount - 1));
+ last->next = NULL;
+
+ m_freeLists[index] = chunk->blocks->next;
+ ++m_chunkCount;
+
+ return chunk->blocks;
+ }
+}
+
+void b2BlockAllocator::Free(void* p, int32 size)
+{
+ if (size == 0)
+ {
+ return;
+ }
+
+ b2Assert(0 < size);
+
+ if (size > b2_maxBlockSize)
+ {
+ b2Free(p);
+ return;
+ }
+
+ int32 index = s_blockSizeLookup[size];
+ b2Assert(0 <= index && index < b2_blockSizes);
+
+#ifdef _DEBUG
+ // Verify the memory address and size is valid.
+ int32 blockSize = s_blockSizes[index];
+ bool found = false;
+ for (int32 i = 0; i < m_chunkCount; ++i)
+ {
+ b2Chunk* chunk = m_chunks + i;
+ if (chunk->blockSize != blockSize)
+ {
+ b2Assert( (int8*)p + blockSize <= (int8*)chunk->blocks ||
+ (int8*)chunk->blocks + b2_chunkSize <= (int8*)p);
+ }
+ else
+ {
+ if ((int8*)chunk->blocks <= (int8*)p && (int8*)p + blockSize <= (int8*)chunk->blocks + b2_chunkSize)
+ {
+ found = true;
+ }
+ }
+ }
+
+ b2Assert(found);
+
+ memset(p, 0xfd, blockSize);
+#endif
+
+ b2Block* block = (b2Block*)p;
+ block->next = m_freeLists[index];
+ m_freeLists[index] = block;
+}
+
+void b2BlockAllocator::Clear()
+{
+ for (int32 i = 0; i < m_chunkCount; ++i)
+ {
+ b2Free(m_chunks[i].blocks);
+ }
+
+ m_chunkCount = 0;
+ memset(m_chunks, 0, m_chunkSpace * sizeof(b2Chunk));
+
+ memset(m_freeLists, 0, sizeof(m_freeLists));
+}
View
188 3rdparty/box2d-2.2.1/Box2D/Common/b2Math.cpp
@@ -1,94 +1,94 @@
-/*
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Common/b2Math.h>
-
-const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
-
-/// Solve A * x = b, where b is a column vector. This is more efficient
-/// than computing the inverse in one-shot cases.
-b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const
-{
- float32 det = b2Dot(ex, b2Cross(ey, ez));
- if (det != 0.0f)
- {
- det = 1.0f / det;
- }
- b2Vec3 x;
- x.x = det * b2Dot(b, b2Cross(ey, ez));
- x.y = det * b2Dot(ex, b2Cross(b, ez));
- x.z = det * b2Dot(ex, b2Cross(ey, b));
- return x;
-}
-
-/// Solve A * x = b, where b is a column vector. This is more efficient
-/// than computing the inverse in one-shot cases.
-b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const
-{
- float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
- float32 det = a11 * a22 - a12 * a21;
- if (det != 0.0f)
- {
- det = 1.0f / det;
- }
- b2Vec2 x;
- x.x = det * (a22 * b.x - a12 * b.y);
- x.y = det * (a11 * b.y - a21 * b.x);
- return x;
-}
-
-///
-void b2Mat33::GetInverse22(b2Mat33* M) const
-{
- float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
- float32 det = a * d - b * c;
- if (det != 0.0f)
- {
- det = 1.0f / det;
- }
-
- M->ex.x = det * d; M->ey.x = -det * b; M->ex.z = 0.0f;
- M->ex.y = -det * c; M->ey.y = det * a; M->ey.z = 0.0f;
- M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f;
-}
-
-/// Returns the zero matrix if singular.
-void b2Mat33::GetSymInverse33(b2Mat33* M) const
-{
- float32 det = b2Dot(ex, b2Cross(ey, ez));
- if (det != 0.0f)
- {
- det = 1.0f / det;
- }
-
- float32 a11 = ex.x, a12 = ey.x, a13 = ez.x;
- float32 a22 = ey.y, a23 = ez.y;
- float32 a33 = ez.z;
-
- M->ex.x = det * (a22 * a33 - a23 * a23);
- M->ex.y = det * (a13 * a23 - a12 * a33);
- M->ex.z = det * (a12 * a23 - a13 * a22);
-
- M->ey.x = M->ex.y;
- M->ey.y = det * (a11 * a33 - a13 * a13);
- M->ey.z = det * (a13 * a12 - a11 * a23);
-
- M->ez.x = M->ex.z;
- M->ez.y = M->ey.z;
- M->ez.z = det * (a11 * a22 - a12 * a12);
-}
+/*
+* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Common/b2Math.h>
+
+const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
+
+/// Solve A * x = b, where b is a column vector. This is more efficient
+/// than computing the inverse in one-shot cases.
+b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const
+{
+ float32 det = b2Dot(ex, b2Cross(ey, ez));
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+ b2Vec3 x;
+ x.x = det * b2Dot(b, b2Cross(ey, ez));
+ x.y = det * b2Dot(ex, b2Cross(b, ez));
+ x.z = det * b2Dot(ex, b2Cross(ey, b));
+ return x;
+}
+
+/// Solve A * x = b, where b is a column vector. This is more efficient
+/// than computing the inverse in one-shot cases.
+b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const
+{
+ float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
+ float32 det = a11 * a22 - a12 * a21;
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+ b2Vec2 x;
+ x.x = det * (a22 * b.x - a12 * b.y);
+ x.y = det * (a11 * b.y - a21 * b.x);
+ return x;
+}
+
+///
+void b2Mat33::GetInverse22(b2Mat33* M) const
+{
+ float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
+ float32 det = a * d - b * c;
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+
+ M->ex.x = det * d; M->ey.x = -det * b; M->ex.z = 0.0f;
+ M->ex.y = -det * c; M->ey.y = det * a; M->ey.z = 0.0f;
+ M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f;
+}
+
+/// Returns the zero matrix if singular.
+void b2Mat33::GetSymInverse33(b2Mat33* M) const
+{
+ float32 det = b2Dot(ex, b2Cross(ey, ez));
+ if (det != 0.0f)
+ {
+ det = 1.0f / det;
+ }
+
+ float32 a11 = ex.x, a12 = ey.x, a13 = ez.x;
+ float32 a22 = ey.y, a23 = ez.y;
+ float32 a33 = ez.z;
+
+ M->ex.x = det * (a22 * a33 - a23 * a23);
+ M->ex.y = det * (a13 * a23 - a12 * a33);
+ M->ex.z = det * (a12 * a23 - a13 * a22);
+
+ M->ey.x = M->ex.y;
+ M->ey.y = det * (a11 * a33 - a13 * a13);
+ M->ey.z = det * (a13 * a12 - a11 * a23);
+
+ M->ez.x = M->ex.z;
+ M->ez.y = M->ey.z;
+ M->ez.z = det * (a11 * a22 - a12 * a12);
+}
View
166 3rdparty/box2d-2.2.1/Box2D/Common/b2StackAllocator.cpp
@@ -1,83 +1,83 @@
-/*
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Common/b2StackAllocator.h>
-#include <Box2D/Common/b2Math.h>
-
-b2StackAllocator::b2StackAllocator()
-{
- m_index = 0;
- m_allocation = 0;
- m_maxAllocation = 0;
- m_entryCount = 0;
-}
-
-b2StackAllocator::~b2StackAllocator()
-{
- b2Assert(m_index == 0);
- b2Assert(m_entryCount == 0);
-}
-
-void* b2StackAllocator::Allocate(int32 size)
-{
- b2Assert(m_entryCount < b2_maxStackEntries);
-
- b2StackEntry* entry = m_entries + m_entryCount;
- entry->size = size;
- if (m_index + size > b2_stackSize)
- {
- entry->data = (char*)b2Alloc(size);
- entry->usedMalloc = true;
- }
- else
- {
- entry->data = m_data + m_index;
- entry->usedMalloc = false;
- m_index += size;
- }
-
- m_allocation += size;
- m_maxAllocation = b2Max(m_maxAllocation, m_allocation);
- ++m_entryCount;
-
- return entry->data;
-}
-
-void b2StackAllocator::Free(void* p)
-{
- b2Assert(m_entryCount > 0);
- b2StackEntry* entry = m_entries + m_entryCount - 1;
- b2Assert(p == entry->data);
- if (entry->usedMalloc)
- {
- b2Free(p);
- }
- else
- {
- m_index -= entry->size;
- }
- m_allocation -= entry->size;
- --m_entryCount;
-
- p = NULL;
-}
-
-int32 b2StackAllocator::GetMaxAllocation() const
-{
- return m_maxAllocation;
-}
+/*
+* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+*
+* 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 <Box2D/Common/b2StackAllocator.h>
+#include <Box2D/Common/b2Math.h>
+
+b2StackAllocator::b2StackAllocator()
+{
+ m_index = 0;
+ m_allocation = 0;
+ m_maxAllocation = 0;
+ m_entryCount = 0;
+}
+
+b2StackAllocator::~b2StackAllocator()
+{
+ b2Assert(m_index == 0);
+ b2Assert(m_entryCount == 0);
+}
+
+void* b2StackAllocator::Allocate(int32 size)
+{
+ b2Assert(m_entryCount < b2_maxStackEntries);
+
+ b2StackEntry* entry = m_entries + m_entryCount;
+ entry->size = size;
+ if (m_index + size > b2_stackSize)
+ {
+ entry->data = (char*)b2Alloc(size);
+ entry->usedMalloc = true;
+ }
+ else
+ {
+ entry->data = m_data + m_index;
+ entry->usedMalloc = false;
+ m_index += size;
+ }
+
+ m_allocation += size;
+ m_maxAllocation = b2Max(m_maxAllocation, m_allocation);
+ ++m_entryCount;
+
+ return entry->data;
+}
+
+void b2StackAllocator::Free(void* p)
+{
+ b2Assert(m_entryCount > 0);
+ b2StackEntry* entry = m_entries + m_entryCount - 1;
+ b2Assert(p == entry->data);
+ if (entry->usedMalloc)
+ {
+ b2Free(p);
+ }
+ else
+ {
+ m_index -= entry->size;
+ }
+ m_allocation -= entry->size;
+ --m_entryCount;
+
+ p = NULL;
+}
+
+int32 b2StackAllocator::GetMaxAllocation() const
+{
+ return m_maxAllocation;
+}
View
200 3rdparty/box2d-2.2.1/Box2D/Common/b2Timer.cpp
@@ -1,100 +1,100 @@
-/*
-* Copyright (c) 2011 Erin Catto http://box2d.org
-*
-* 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 <Box2D/Common/b2Timer.h>
-
-#if defined(_WIN32)
-
-float64 b2Timer::s_invFrequency = 0.0f;
-
-#include <windows.h>
-
-b2Timer::b2Timer()
-{
- LARGE_INTEGER largeInteger;
-
- if (s_invFrequency == 0.0f)
- {
- QueryPerformanceFrequency(&largeInteger);
- s_invFrequency = float64(largeInteger.QuadPart);
- if (s_invFrequency > 0.0f)
- {
- s_invFrequency = 1000.0f / s_invFrequency;
- }
- }
-
- QueryPerformanceCounter(&largeInteger);
- m_start = float64(largeInteger.QuadPart);
-}
-
-void b2Timer::Reset()
-{
- LARGE_INTEGER largeInteger;
- QueryPerformanceCounter(&largeInteger);
- m_start = float64(largeInteger.QuadPart);
-}
-
-float32 b2Timer::GetMilliseconds() const
-{
- LARGE_INTEGER largeInteger;
- QueryPerformanceCounter(&largeInteger);
- float64 count = float64(largeInteger.QuadPart);
- float32 ms = float32(s_invFrequency * (count - m_start));
- return ms;
-}
-
-#elif defined(__linux__) || defined (__APPLE__)
-
-#include <sys/time.h>
-
-b2Timer::b2Timer()
-{
- Reset();
-}
-
-void b2Timer::Reset()
-{
- timeval t;
- gettimeofday(&t, 0);
- m_start_sec = t.tv_sec;
- m_start_msec = t.tv_usec * 0.001f;
-}
-
-float32 b2Timer::GetMilliseconds() const
-{
- timeval t;
- gettimeofday(&t, 0);
- return (t.tv_sec - m_start_sec) * 1000 + t.tv_usec * 0.001f - m_start_msec;
-}
-
-#else
-
-b2Timer::b2Timer()
-{
-}
-
-void b2Timer::Reset()
-{
-}
-
-float32 b2Timer::GetMilliseconds() const
-{
- return 0.0f;
-}
-
-#endif
+/*
+* Copyright (c) 2011 Erin Catto http://box2d.org
+*
+* 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 <Box2D/Common/b2Timer.h>
+
+#if defined(_WIN32)
+
+float64 b2Timer::s_invFrequency = 0.0f;
+
+#include <windows.h>
+
+b2Timer::b2Timer()
+{
+ LARGE_INTEGER largeInteger;
+
+ if (s_invFrequency == 0.0f)
+ {
+ QueryPerformanceFrequency(&largeInteger);
+ s_invFrequency = float64(largeInteger.QuadPart);
+ if (s_invFrequency > 0.0f)
+ {
+ s_invFrequency = 1000.0f / s_invFrequency;
+ }
+ }
+
+ QueryPerformanceCounter(&largeInteger);
+ m_start = float64(largeInteger.QuadPart);
+}
+
+void b2Timer::Reset()
+{
+ LARGE_INTEGER largeInteger;
+ QueryPerformanceCounter(&largeInteger);
+ m_start = float64(largeInteger.QuadPart);
+}
+
+float32 b2Timer::GetMilliseconds() const
+{
+ LARGE_INTEGER largeInteger;
+ QueryPerformanceCounter(&largeInteger);
+ float64 count = float64(largeInteger.QuadPart);
+ float32 ms = float32(s_invFrequency * (count - m_start));
+ return ms;
+}
+
+#elif defined(__linux__) || defined (__APPLE__)
+
+#include <sys/time.h>
+
+b2Timer::b2Timer()
+{
+ Reset();
+}
+
+void b2Timer::Reset()
+{
+ timeval t;
+ gettimeofday(&t, 0);
+ m_start_sec = t.tv_sec;
+ m_start_msec = t.tv_usec * 0.001f;
+}
+
+float32 b2Timer::GetMilliseconds() const
+{
+ timeval t;
+ gettimeofday(&t, 0);
+ return (t.tv_sec - m_start_sec) * 1000 + t.tv_usec * 0.001f - m_start_msec;
+}
+
+#else
+
+b2Timer::b2Timer()
+{
+}
+
+void b2Timer::Reset()
+{
+}
+
+float32 b2Timer::GetMilliseconds() const
+{
+ return 0.0f;
+}
+
+#endif
View
1,026 3rdparty/box2d-2.2.1/Box2D/Dynamics/b2Body.cpp
<
@@ -1,514 +1,514 @@
-/*
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
-*
-* 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 <Box2D/Dynamics/b2Body.h>
-#include <Box2D/Dynamics/b2Fixture.h>
-#include <Box2D/Dynamics/b2World.h>
-#include <Box2D/Dynamics/Contacts/b2Contact.h>
-#include <Box2D/Dynamics/Joints/b2Joint.h>
-
-b2Body::b2Body(const b2BodyDef* bd, b2World* world)
-{
- b2Assert(bd->position.IsValid());
- b2Assert(bd->linearVelocity.IsValid());
- b2Assert(b2IsValid(bd->angle));
- b2Assert(b2IsValid(bd->angularVelocity));
- b2Assert(b2IsValid(bd->angularDamping) && bd->angularDamping >= 0.0f);
- b2Assert(b2IsValid(bd->linearDamping) && bd->linearDamping >= 0.0f);
-
- m_flags = 0;
-
- if (bd->bullet)
- {
- m_flags |= e_bulletFlag;
- }
- if (bd->fixedRotation)
- {
- m_flags |= e_fixedRotationFlag;
- }
- if (bd->allowSleep)
- {
- m_flags |= e_autoSleepFlag;
- }
- if (bd->awake)
- {
- m_flags |= e_awakeFlag;
- }
- if (bd->active)
- {
- m_flags |= e_activeFlag;
- }
-
- m_world = world;
-
- m_xf.p = bd->position;
- m_xf.q.Set(bd->angle);
-
- m_sweep.localCenter.SetZero();
- m_sweep.c0 = m_xf.p;
- m_sweep.c = m_xf.p;
- m_sweep.a0 = bd->angle;
- m_sweep.a = bd->angle;
- m_sweep.alpha0 = 0.0f;
-
- m_jointList = NULL;
- m_contactList = NULL;
- m_prev = NULL;
- m_next = NULL;
-
- m_linearVelocity = bd->linearVelocity;
- m_angularVelocity = bd->angularVelocity;
-
- m_linearDamping = bd->linearDamping;
- m_angularDamping = bd->angularDamping;
- m_gravityScale = bd->gravityScale;
-
- m_force.SetZero();
- m_torque = 0.0f;
-
- m_sleepTime = 0.0f;
-
- m_type = bd->type;
-
- if (m_type == b2_dynamicBody)
- {
- m_mass = 1.0f;
- m_invMass = 1.0f;
- }
- else
- {
- m_mass = 0.0f;
- m_invMass = 0.0f;
- }
-
- m_I = 0.0f;
- m_invI = 0.0f;
-
- m_userData = bd->userData;
-
- m_fixtureList = NULL;
- m_fixtureCount = 0;
-}
-
-b2Body::~b2Body()
-{
- // shapes and joints are destroyed in b2World::Destroy
-}
-
-void b2Body::SetType(b2BodyType type)
-{
- b2Assert(m_world->IsLocked() == false);
- if (m_world->IsLocked() == true)
- {
- return;
- }
-
- if (m_type == type)
- {
- return;
- }
-
- m_type = type;
-
- ResetMassData();
-
- if (m_type == b2_staticBody)
- {
- m_linearVelocity.SetZero();
- m_angularVelocity = 0.0f;
- m_sweep.a0 = m_sweep.a;
- m_sweep.c0 = m_sweep.c;
- SynchronizeFixtures();
- }
-
- SetAwake(true);
-
- m_force.SetZero();
- m_torque = 0.0f;
-
- // Since the body type changed, we need to flag contacts for filtering.
- for (b2Fixture* f = m_fixtureList; f; f = f->m_next)
- {
- f->Refilter();
- }
-}
-
-b2Fixture* b2Body::CreateFixture(const b2FixtureDef* def)
-{
- b2Assert(m_world->IsLocked() == false);
- if (m_world->IsLocked() == true)
- {
- return NULL;
- }
-
- b2BlockAllocator* allocator = &m_world->m_blockAllocator;
-
- void* memory = allocator->Allocate(sizeof(b2Fixture));
- b2Fixture* fixture = new (memory) b2Fixture;
- fixture->Create(allocator, this, def);