Skip to content
Browse files

more work on box2D

  • Loading branch information...
1 parent 075282e commit 025b50ac59bc6f70e0d928b2bf94d985508ae02e @totallyevil totallyevil committed Oct 9, 2012
View
2 external/Box2D/box2d/Collision/Shapes/b2Shape.cs
@@ -6,7 +6,7 @@
namespace Box2D.Collision.Shapes
{
- enum b2ShapeType
+ public enum b2ShapeType
{
e_circle = 0,
e_edge = 1,
View
27 external/Box2D/box2d/Collision/b2Collision.cs
@@ -35,32 +35,21 @@ public struct b2RayCastInput
/// come from b2RayCastInput.
public struct b2RayCastOutput
{
- public b2Vec2 normal = new b2Vec2();
- public float fraction = 0f;
+ public b2Vec2 normal;
+ public float fraction;
- public static b2RayCastOutput Zero = new b2RayCastOutput();
+ public b2RayCastOutput(b2Vec2 b, float f)
+ {
+ normal = b;
+ fraction = f;
+ }
+ public static b2RayCastOutput Zero = new b2RayCastOutput(new b2Vec2(), 0f);
}
public abstract class b2Collision
{
public static byte b2_nullFeature = byte.MaxValue;
- public static bool b2TestOverlap(b2AABB a, b2AABB b)
- {
- b2Vec2 d1, d2;
- d1 = b.lowerBound - a.upperBound;
- d2 = a.lowerBound - b.upperBound;
-
- if (d1.x > 0.0f || d1.y > 0.0f)
- return false;
-
- if (d2.x > 0.0f || d2.y > 0.0f)
- return false;
-
- return true;
- }
-
-
/// 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.
public static void b2GetPointStates(b2PointState[] state1, b2PointState[] state2,
View
198 external/Box2D/box2d/Dynamics/b2Body.cs
@@ -0,0 +1,198 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Box2D.Common;
+
+namespace Box2D.Dynamics
+{
+ public enum b2BodyType
+ {
+ b2_staticBody = 0,
+ b2_kinematicBody,
+ b2_dynamicBody
+
+ //b2_bulletBody,
+ }
+
+ [Flags]
+ public enum b2BodyFlags
+ {
+ e_islandFlag = 0x0001,
+ e_awakeFlag = 0x0002,
+ e_autoSleepFlag = 0x0004,
+ e_bulletFlag = 0x0008,
+ e_fixedRotationFlag = 0x0010,
+ e_activeFlag = 0x0020,
+ e_toiFlag = 0x0040
+ }
+
+
+ public class b2Body
+ {
+ protected b2BodyType m_type;
+ public b2BodyType BodyType
+ {
+ get { return (m_type); }
+ set { m_type = value; }
+ }
+
+ protected b2BodyFlags m_flags;
+ public b2BodyFlags BodyFlags
+ {
+ get { return (m_flags); }
+ set { m_flags = value; }
+ }
+
+ protected int m_islandIndex;
+ public int IslandIndex
+ {
+ get { return (m_islandIndex); }
+ set { m_islandIndex = value; }
+ }
+
+ protected b2Transform m_xf; // the body origin transform
+ public b2Transform XF
+ {
+ get { return (m_xf); }
+ set { m_xf = value; }
+ }
+
+ protected b2Sweep m_sweep; // the swept motion for CCD
+ public b2Sweep Sweep
+ {
+ get { return (m_sweep); }
+ set { m_sweep = value; }
+ }
+ protected b2Vec2 m_linearVelocity;
+ public b2Vec2 LinearVelocity
+ {
+ get { return (m_linearVelocity); }
+ set { m_linearVelocity = value; }
+ }
+ protected float m_angularVelocity;
+ public float AngularVelocity
+ {
+ get { return (m_angularVelocity); }
+ set { m_angularVelocity = value; }
+ }
+
+ protected b2Vec2 m_force;
+ public b2Vec2 Force
+ {
+ get { return (m_force); }
+ set { m_force = value; }
+ }
+ protected float m_torque;
+ public float Torque
+ {
+ get { return (m_torque); }
+ set { m_torque = value; }
+ }
+
+ protected b2World m_world;
+ public b2World World
+ {
+ get { return (m_world); }
+ set { m_world = value; }
+ }
+ protected b2Body m_prev;
+ public b2Body Prev
+ {
+ get { return (m_prev); }
+ set { m_prev = value; }
+ }
+ protected b2Body m_next;
+ public b2Body Next
+ {
+ get { return (m_next); }
+ set { m_next = value; }
+ }
+
+ protected b2Fixture m_fixtureList;
+ public b2Fixture FixtureList
+ {
+ get { return (m_fixtureList); }
+ set { m_fixtureList = value; }
+ }
+ protected int m_fixtureCount;
+ public int FixtureCount
+ {
+ get { return (m_fixtureCount); }
+ set { m_fixtureCount = value; }
+ }
+
+ protected b2JointEdge m_jointList;
+ public b2JointEdge JointList
+ {
+ get { return (m_jointList); }
+ set { m_jointList = value; }
+ }
+ protected b2ContactEdge m_contactList;
+ public b2ContactEdge ContactList
+ {
+ get { return (m_contactList); }
+ set { m_contactList = value; }
+ }
+
+ protected float m_mass, m_invMass;
+ public float Mass
+ {
+ get { return (m_mass); }
+ set { m_mass = value; }
+ }
+ public float InvertedMass
+ {
+ get { return (m_invMass); }
+ set { m_invMass = value; }
+ }
+
+ // Rotational inertia about the center of mass.
+ protected float m_I, m_invI;
+ public float I
+ {
+ get { return (m_I); }
+ set { m_I = value; }
+ }
+ public float InvertedI
+ {
+ get { return (m_invI); }
+ set { m_invI = value; }
+ }
+
+
+ protected float m_linearDamping;
+ public float LinearDamping
+ {
+ get { return (m_linearDamping); }
+ set { m_linearDamping = value; }
+ }
+ protected float m_angularDamping;
+ public float AngularDamping
+ {
+ get { return (m_angularDamping); }
+ set { m_angularDamping = value; }
+ }
+ protected float m_gravityScale;
+ public float GravityScale
+ {
+ get { return (m_gravityScale); }
+ set { m_gravityScale = value; }
+ }
+
+ protected float m_sleepTime;
+ public float SleepTime
+ {
+ get { return (m_sleepTime); }
+ set { m_sleepTime = value; }
+ }
+
+ protected object m_userData;
+ public object UserData
+ {
+ get { return (m_userData); }
+ set { m_userData = value; }
+ }
+
+ }
+}
View
86 external/Box2D/box2d/Dynamics/b2BodyDef.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Box2D.Common;
+
+namespace Box2D.Dynamics
+{
+ /// A body definition holds all the data needed to construct a rigid body.
+ /// You can safely re-use body definitions. Shapes are added to a body after construction.
+ public struct b2BodyDef
+ {
+ /// This constructor sets the body definition default values.
+ public b2BodyDef()
+ {
+ userData = null;
+ position = new b2Vec2();
+ position.Set(0.0f, 0.0f);
+ angle = 0.0f;
+ linearVelocity = new b2Vec2();
+ linearVelocity.Set(0.0f, 0.0f);
+ angularVelocity = 0.0f;
+ linearDamping = 0.0f;
+ angularDamping = 0.0f;
+ allowSleep = true;
+ awake = true;
+ fixedRotation = false;
+ bullet = false;
+ type = b2BodyType.b2_staticBody;
+ active = true;
+ gravityScale = 1.0f;
+ }
+
+ /// The body type: static, kinematic, or dynamic.
+ /// Note: if a dynamic body would have zero mass, the mass is set to one.
+ public b2BodyType type;
+
+ /// The world position of the body. Avoid creating bodies at the origin
+ /// since this can lead to many overlapping shapes.
+ public b2Vec2 position;
+
+ /// The world angle of the body in radians.
+ public float angle;
+
+ /// The linear velocity of the body's origin in world co-ordinates.
+ public b2Vec2 linearVelocity;
+
+ /// The angular velocity of the body.
+ public float angularVelocity;
+
+ /// Linear damping is use to reduce the linear velocity. The damping parameter
+ /// can be larger than 1.0f but the damping effect becomes sensitive to the
+ /// time step when the damping parameter is large.
+ public float linearDamping;
+
+ /// Angular damping is use to reduce the angular velocity. The damping parameter
+ /// can be larger than 1.0f but the damping effect becomes sensitive to the
+ /// time step when the damping parameter is large.
+ public float angularDamping;
+
+ /// Set this flag to false if this body should never fall asleep. Note that
+ /// this increases CPU usage.
+ public bool allowSleep;
+
+ /// Is this body initially awake or sleeping?
+ public bool awake;
+
+ /// Should this body be prevented from rotating? Useful for characters.
+ public bool fixedRotation;
+
+ /// Is this a fast moving body that should be prevented from tunneling through
+ /// other moving bodies? Note that all bodies are prevented from tunneling through
+ /// kinematic and static bodies. This setting is only considered on dynamic bodies.
+ /// @warning You should use this flag sparingly since it increases processing time.
+ public bool bullet;
+
+ /// Does this body start out active?
+ public bool active;
+
+ /// Use this to store application specific body data.
+ public object userData;
+
+ /// Scale the gravity applied to this body.
+ public float gravityScale;
+ }
+}
View
18 external/Box2D/box2d/Dynamics/b2World.cs
@@ -93,7 +93,6 @@ public b2World(b2Vec2 gravity)
}
/// Enable/disable sleep.
- public void SetAllowSleeping(bool flag);
public bool GetAllowSleeping() { return m_allowSleep; }
/// Enable/disable warm starting. For testing.
@@ -226,13 +225,12 @@ public void DestroyBody(b2Body b)
public b2Joint CreateJoint(b2JointDef def)
{
- b2Assert(IsLocked() == false);
if (IsLocked())
{
return null;
}
- b2Joint j = b2Joint.Create(def, &m_blockAllocator);
+ b2Joint j = b2Joint.Create(def);
// Connect to the world list.
j.m_prev = null;
@@ -265,8 +263,8 @@ public b2Joint CreateJoint(b2JointDef def)
// If the joint prevents collisions, then flag any contacts for filtering.
if (def.collideConnected == false)
{
- b2ContactEdge* edge = bodyB.GetContactList();
- while (edge)
+ b2ContactEdge edge = bodyB.GetContactList();
+ while (edge != null)
{
if (edge.other == bodyA)
{
@@ -286,7 +284,6 @@ public b2Joint CreateJoint(b2JointDef def)
public void DestroyJoint(b2Joint j)
{
- b2Assert(IsLocked() == false);
if (IsLocked())
{
return;
@@ -356,16 +353,15 @@ public void DestroyJoint(b2Joint j)
j.m_edgeB.prev = null;
j.m_edgeB.next = null;
- b2Joint.Destroy(j, &m_blockAllocator);
+ b2Joint.Destroy(j);
- b2Assert(m_jointCount > 0);
--m_jointCount;
// If the joint prevents collisions, then flag any contacts for filtering.
if (collideConnected == false)
{
- b2ContactEdge* edge = bodyB.GetContactList();
- while (edge)
+ b2ContactEdge edge = bodyB.GetContactList();
+ while (edge != null)
{
if (edge.other == bodyA)
{
@@ -390,7 +386,7 @@ public void SetAllowSleeping(bool flag)
m_allowSleep = flag;
if (m_allowSleep == false)
{
- for (b2Body b = m_bodyList; b; b = b.m_next)
+ for (b2Body b = m_bodyList; b != null; b = b.m_next)
{
b.SetAwake(true);
}
View
2 external/Box2D/box2d/box2d.csproj
@@ -80,6 +80,8 @@
<Compile Include="Common\b2Transform.cs" />
<Compile Include="Common\bVec2.cs" />
<Compile Include="Common\bVec3.cs" />
+ <Compile Include="Dynamics\b2Body.cs" />
+ <Compile Include="Dynamics\b2BodyDef.cs" />
<Compile Include="Dynamics\b2ContactFilter.cs" />
<Compile Include="Dynamics\b2ContactListener.cs" />
<Compile Include="Dynamics\b2ContactManager.cs" />

0 comments on commit 025b50a

Please sign in to comment.
Something went wrong with that request. Please try again.