#pragma once
#include "container.h"
#include "box2d/constants.h"
#include "box2d/math_functions.h"
#include "box2d/types.h"
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_enableSleep = 0x00000800,
b2_bodyEnableContactRecycling = 0x00001000,
b2_allLocks = b2_lockAngularZ | b2_lockLinearX | b2_lockLinearY,
b2_fixedRotation = b2_lockAngularZ,
b2_bodyTransientFlags = b2_isFast | b2_isSpeedCapped | b2_hadTimeOfImpact,
};
typedef struct b2Body
{
void* userData;
int setIndex;
int localIndex;
int headContactKey;
int contactCount;
int headShapeId;
int shapeCount;
int headChainId;
int headJointKey;
int jointCount;
int islandId;
int islandIndex;
float mass;
float inertia;
float sleepThreshold;
float sleepTime;
int bodyMoveIndex;
int id;
uint32_t flags;
b2BodyType type;
uint16_t generation;
char name[B2_NAME_LENGTH + 1];
} 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
{
b2WorldTransform transform;
b2Pos center;
b2Rot rotation0;
b2Pos 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;
b2DeclareArray( b2Body );
b2DeclareArray( b2BodySim );
b2DeclareArray( b2BodyState );
b2Body* b2GetBodyFullId( b2World* world, b2BodyId bodyId );
b2WorldTransform b2GetBodyTransformQuick( b2World* world, b2Body* body );
b2WorldTransform 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 );
void b2RemoveBodySim( b2Array( b2BodySim ) * bodySims, b2Array( b2Body ) * bodies, int localIndex );
bool b2WakeBody( b2World* world, b2Body* body );
void b2UpdateBodyMassData( b2World* world, b2Body* body );
void b2SyncBodyFlags( b2World* world, b2Body* body );
static inline b2Sweep b2MakeRelativeSweep( const b2BodySim* bodySim, b2Pos base )
{
b2Sweep s;
s.c1 = b2SubPos( bodySim->center0, base );
s.c2 = b2SubPos( bodySim->center, base );
s.q1 = bodySim->rotation0;
s.q2 = bodySim->transform.q;
s.localCenter = bodySim->localCenter;
return s;
}