Skip to content

Instantly share code, notes, and snippets.

@erincatto
Last active March 25, 2024 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erincatto/4974e5bb815179f25a049760c04f5a0f to your computer and use it in GitHub Desktop.
Save erincatto/4974e5bb815179f25a049760c04f5a0f to your computer and use it in GitHub Desktop.
Static Shapes

Option 1: static bodies

typedef struct b2StaticBodyDef
{
	/// The world position of the body. Avoid creating bodies at the origin
	/// since this can lead to many overlapping shapes.
	b2Vec2 position;

	/// The world angle of the body in radians.
	float angle;

	/// Use this to store application specific body data.
	void* userData;
} b2StaticBodyDef;

/// Create a static rigid body given a definition. No reference to the definition is retained.
/// @warning This function is locked during callbacks.
B2_API b2StaticBodyId b2CreateStaticBody(b2WorldId worldId, const b2StaticBodyDef* def);

/// Destroy a static rigid body given an id. This destroys all shapes and joints attached to the body.
/// @warning This function is locked during callbacks.
B2_API void b2DestroyStaticBody(b2StaticBodyId staticBodyId);

/// Body identifier validation. Provides validation for up to 64K allocations.
B2_API bool b2StaticBody_IsValid(b2StaticBodyId staticBodyId);

/// Set the user data for a body
B2_API void b2StaticBody_SetUserData(b2StaticBodyId staticBodyId, void* userData);

/// Get the user data stored in a body
B2_API void* b2StaticBody_GetUserData(b2StaticBodyId staticBodyId);

/// Get the world transform of a static body.
B2_API b2Transform b2StaticBody_GetTransform(b2StaticBodyId staticBodyId);

/// Get the number of shapes on this body
B2_API int b2StaticBody_GetShapeCount(b2StaticBodyId staticBodyId);

/// Get the shape ids for all shapes on this body, up to the provided capacity
B2_API void b2StaticBody_GetShapes(b2StaticBodyId staticBodyId, b2ShapeId* shapeArray, int capacity);

B2_API b2ShapeId b2CreateStaticCircleShape(b2StaticBodyId staticBodyId, const b2ShapeDef* def, const b2Circle* circle);
B2_API b2ShapeId b2CreateStaticSegmentShape(b2StaticBodyId staticBodyId, const b2ShapeDef* def, const b2Segment* segment);
B2_API b2ShapeId b2CreateStaticCapsuleShape(b2StaticBodyId staticBodyId, const b2ShapeDef* def, const b2Capsule* capsule);
B2_API b2ShapeId b2CreateStaticPolygonShape(b2StaticBodyId staticBodyId, const b2ShapeDef* def, const b2Polygon* polygon);

Option 2: world shapes

B2_API b2ShapeId b2CreateStaticCircleShape(b2WorldId worldId, const b2ShapeDef* def, const b2Circle* circle, b2Transform transform);
B2_API b2ShapeId b2CreateStaticSegmentShape(b2WorldId worldId, const b2ShapeDef* def, const b2Segment* segment, b2Transform transform);
B2_API b2ShapeId b2CreateStaticCapsuleShape(b2WorldId worldId, const b2ShapeDef* def, const b2Capsule* capsule, b2Transform transform);
B2_API b2ShapeId b2CreateStaticPolygonShape(b2WorldId worldId, const b2ShapeDef* def, const b2Polygon* polygon, b2Transform transform);

Option 3: hide this all behind b2BodyId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment