#pragma once
#include "array.h"
#include "box2d/math_functions.h"
#include "box2d/types.h"
#define B2_NAME_LENGTH 32
typedef struct b2World b2World;
enum b2BodyFlags
{
b2_lockLinearX = 0x00000001,
b2_lockLinearY = 0x00000002,
b2_lockAngularZ = 0x00000004,
b2_isFast = 0x00000008,
b2_isBullet = 0x00000010,
b2_isSpeedCapped = 0x00000020,
b2_hadTimeOfImpact = 0x00000040,
b2_allowFastRotation = 0x00000080,
b2_enlargeBounds = 0x00000100,
b2_dynamicFlag = 0x00000200,
b2_dirtyMass = 0x00000400,
b2_allLocks = b2_lockAngularZ | b2_lockLinearX | b2_lockLinearY,
};
typedef struct b2Body
{
char name[B2_NAME_LENGTH];
void* userData;
int setIndex;
int localIndex;
int headContactKey;
int contactCount;
int headShapeId;
int shapeCount;
int headChainId;
int headJointKey;
int jointCount;
int islandId;
int islandPrev;
int islandNext;
float mass;
float inertia;
float sleepThreshold;
float sleepTime;
int bodyMoveIndex;
int id;
uint32_t flags;
b2BodyType type;
uint16_t generation;
bool enableSleep;
} b2Body;
typedef struct b2BodyState
{
b2Vec2 linearVelocity; float angularVelocity;
uint32_t flags;
b2Vec2 deltaPosition;
b2Rot deltaRotation; } b2BodyState;
static const b2BodyState b2_identityBodyState = { { 0.0f, 0.0f }, 0.0f, 0, { 0.0f, 0.0f }, { 1.0f, 0.0f } };
typedef struct b2BodySim
{
b2Transform transform;
b2Vec2 center;
b2Rot rotation0;
b2Vec2 center0;
b2Vec2 localCenter;
b2Vec2 force;
float torque;
float invMass;
float invInertia;
float minExtent;
float maxExtent;
float linearDamping;
float angularDamping;
float gravityScale;
int bodyId;
uint32_t flags;
} b2BodySim;
b2Body* b2GetBodyFullId( b2World* world, b2BodyId bodyId );
b2Transform b2GetBodyTransformQuick( b2World* world, b2Body* body );
b2Transform b2GetBodyTransform( b2World* world, int bodyId );
b2BodyId b2MakeBodyId( b2World* world, int bodyId );
bool b2ShouldBodiesCollide( b2World* world, b2Body* bodyA, b2Body* bodyB );
b2BodySim* b2GetBodySim( b2World* world, b2Body* body );
b2BodyState* b2GetBodyState( b2World* world, b2Body* body );
bool b2WakeBody( b2World* world, b2Body* body );
void b2UpdateBodyMassData( b2World* world, b2Body* body );
static inline b2Sweep b2MakeSweep( const b2BodySim* bodySim )
{
b2Sweep s;
s.c1 = bodySim->center0;
s.c2 = bodySim->center;
s.q1 = bodySim->rotation0;
s.q2 = bodySim->transform.q;
s.localCenter = bodySim->localCenter;
return s;
}
B2_ARRAY_INLINE( b2Body, b2Body )
B2_ARRAY_INLINE( b2BodySim, b2BodySim )
B2_ARRAY_INLINE( b2BodyState, b2BodyState )