SwPhys

From SWWorkshop

Jump to: navigation, search

Rigid body simulation on Box2D. This api support Body, Joints and Contact.

World

void swPhysWorldSetMeterOfPixelRatio(float ratio);
void swPhysWorldCreate(swRect *AABB, swVec2 *gravity,bool doSleep);
void swPhysWorldDestroy();
void swPhysWorldUpdate();
void swPhysWorldSetGravity(swVec2 *gravity);

Renderer

typedef enum _swPhysRenderedItemEnum{
  SW_PHYS_RENDERED_SHAPE,
  SW_PHYS_RENDERED_JOINTS,
  SW_PHYS_RENDERED_CORESHAPES,
  SW_PHYS_RENDERED_AABBs,
  SW_PHYS_RENDERED_OBBs,
  SW_PHYS_RENDERED_PAIRS,
  SW_PHYS_RENDERED_CONTACTPOINTS,
  SW_PHYS_RENDERED_CONTACTNORMALS,
  SW_PHYS_RENDERED_CONTACTFORCES,
  SW_PHYS_RENDERED_FRICTIONFORCES,
  SW_PHYS_RENDERED_CENTEROFMASSES,
  SW_PHYS_RENDERED_STATISTICS,
}swPhysRenderedItemEnum;
 
 
void swPhysRendererSetEnabled(swPhysRenderedItemEnum type, boolean bVisible);
void swPhysRendererExecute();


BodyDef

void  swPhysBodyDefSetPos(float x,float y);
void  swPhysBodyDefSetAngle(float angle);
void  swPhysBodyDefSetRectShapeType(float w,float h);
void  swPhysBodyDefSetCircleShapeType(float radious);
void  swPhysBodyDefSetLinearDamping(float damping);
void  swPhysBodyDefSetDensity(float density);
void  swPhysBodyDefSetFriction(float friction);
void  swPhysBodyDefSetRestitution(float restitution);
void  swPhysBodyDefSetFixedRotation(bool bfixedRot);
void  swPhysBodyDefSetBullet(bool isBullet);
void  swPhysBodyDefSetFilterGroupIndex(int index);
void  swPhysBodyDefSetPosListener(float *xListener,float *yListener);
void  swPhysBodyDefSetAngleListener(float *angleListener);

Manage Body

int   swPhysBodyCreate();
void  swPhysBodyDestroy(int bodyID);
void  swPhysBodySetUserData(int bodyID, void *userData);
void  swPhysBodyApplyForce(int bodyID, swVec2 force,swPoint pos);
void  swPhysBodyApplyForce1(int bodyID, float fx, float fy,float x,float y);
void  swPhysBodySetLinearVelocity(int bodyID, swVec2 vel);
void  swPhysBodySetLinearVelocity1(int bodyID, float x, float y);
void  swPhysBodySetLinearVelocityY(int bodyID, float y);
void  swPhysBodySetLinearVelocityX(int bodyID, float x);
void  swPhysBodySetXForm(int bodyID, swVec2 pos,float rot);
void  swPhysBodySetXForm1(int bodyID, float x, float y,float rot);
void  swPhysBodySetBullet(int bodyID,bool isBullet);
void  swPhysBodyWakeUp(int bodyID);
void  swPhysBodyPutToSleep(int bodyID);

Query Body

float swPhysBodyGetMass(int bodyID);
bool  swPhysBodyIsBullet(int bodyID);
bool  swPhysBodyIsStatic(int bodyID);
bool  swPhysBodyIsDynamic(int bodyID);
bool  swPhysBodyIsFrozen(int bodyID);
bool  swPhysBodyIsSleeping(int bodyID);


Joints

int  swPhysDistJointCreate(int bodyID1,swPoint anchor1,float bodyID2,swPoint anchor2,bool collideConneted);
int  swPhysRevoJointCreate(int bodyID1,float bodyID2,swPoint anchor,
                           float lowerAngle, float upperAngle, bool enableLimit, 
                           float maxMotorTorque, float motorSpeed, bool enableMotor);
 
int  swPhysPrisJointCreate(int bodyID1,float bodyID2,swPoint anchor,
                           swPoint axis,float lowerTrans, float upperTrans, 
                           bool enableLimit, float maxMotorForce, float motorSpeed, bool enableMotor);
 
int  swPhysPullJointCreate(int bodyID1,float bodyID2,swPoint gAnchor1,swPoint gAnchor2,
                           swPoint anchor1,swPoint anchor2, 
                           float ratio,float maxLength1, float maxLength2);
 
int  swPhysGearJointCreate(int bodyID1,float bodyID2,int joint1,int joint2,float ratio);
void swPhysJointDestroy(int jointID);
Personal tools