CRM64Pro GDK v0.15.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches
CRM64Pro::Physics

Physics interface class. More...

Detailed Description

Physics interface class.

Classes

struct  AABB
 Axis-aligned bounding box using half-open bounds [min, max). More...

Public Types

typedef bool(* TileSolidCallback) (const SceneLayerTile *pTileLayer, Sint32 iCellX, Sint32 iCellY, Uint32 iCellValue, void *pUserData)
 Callback used by tile-layer sweep/ground checks to decide if one tile is solid.

Public Member Functions

bool overlapsSprite (Sprite *pS1, float fX1, float fY1, Sprite *pS2, float fX2, float fY2, const SDL_FRect *pOverlap=nullptr, ePhysicsCollisionMode eMode=PCM_PIXEL)
 Check overlap between two sprites.
bool overlapsSprite (Sprite *pS1, float fX1, float fY1, const SDL_FRect &rect, const SDL_FRect *pOverlap=nullptr, ePhysicsCollisionMode eMode=PCM_PIXEL)
 Check overlap between a sprite and a rectangle.
bool overlapsSprite (Sprite *pS1, float fX1, float fY1, float fPX, float fPY, ePhysicsCollisionMode eMode=PCM_PIXEL)
 Check overlap between a sprite and a point.
bool resolve (SDL_FRect &subject, const SDL_FRect &obstacle)
 Resolve overlap between two rectangular areas.
bool sweepAABBOnLayerTile (const SDL_FRect &rectStart, float fDX, float fDY, SceneLayerTile *pSceneLayer, SDL_FRect *pRectResolved, bool *pHitX=nullptr, bool *pHitY=nullptr, bool *pGrounded=nullptr, TileSolidCallback fnSolid=nullptr, void *pUserData=nullptr)
 Sweep an AABB on a tile layer and resolve collisions (axis separated: X then Y).
bool isGroundedOnLayerTile (const SDL_FRect &rect, SceneLayerTile *pSceneLayer, float fProbeDistance=1.0f, TileSolidCallback fnSolid=nullptr, void *pUserData=nullptr)
 Ground probe helper against a tile layer.
bool info (Sint32 iMode=0) override
 Request Physics Interface information.

Static Public Member Functions

static bool integrateVelocity (float &fV, float fA, float fDT)
 Integrate velocity using explicit Euler: v = v + a * dt.
static bool applyLinearDamping (float &fV, float fDamping, float fDT)
 Apply linear damping to velocity: v *= max(0, 1 - damping * dt).
static bool clampVelocity (float &fV, float fMaxV)
 Clamp a velocity value within a maximum magnitude.
static bool isValidAABB (const AABB &aabb)
 Validate if an AABB contains finite values and non-inverted bounds.
static bool containsPoint (const AABB &aabb, float px, float py)
 Test if a point is inside an AABB using half-open bounds [min, max).
static bool overlapsAABB (const AABB &aabb1, const AABB &aabb2, SDL_FRect *pOverlap=nullptr)
 Test if two AABBs overlap using half-open bounds [min, max).
static bool overlapsObjectAABB (const SceneObject *pObjA, const SceneObject *pObjB, SDL_FRect *pOverlap=nullptr)
 Fast object-object broad phase using cached object AABBs.
static bool containsObjectPoint (const SceneObject *pObj, float fPX, float fPY)
 Precise point-in-object check using object shape geometry.
static bool overlapsObject (const SceneObject *pObjA, const SceneObject *pObjB, ePhysicsCollisionMode eMode=PCM_SHAPE, SDL_FRect *pOverlap=nullptr)
 Object-object overlap with selectable narrow phase.
static bool overlapsObjectTrigger (const SceneObject *pOwnerObj, const SceneShapeData &triggerLocalShape, const SceneObject *pOther, ePhysicsCollisionMode eMode=PCM_SHAPE, SDL_FRect *pOverlap=nullptr)
 Trigger-local-shape versus object overlap.
static bool matchTypeHash (Uint32 iObjectTypeHash, const vector< Uint32 > &vIncludeHashes, const vector< Uint32 > &vExcludeHashes)
 Fast hash filter helper for trigger/object-type matching.

Member Typedef Documentation

◆ TileSolidCallback

typedef bool(* CRM64Pro::Physics::TileSolidCallback) (const SceneLayerTile *pTileLayer, Sint32 iCellX, Sint32 iCellY, Uint32 iCellValue, void *pUserData)

Callback used by tile-layer sweep/ground checks to decide if one tile is solid.

Parameters
pTileLayerTile layer being queried.
iCellXTile cell X.
iCellYTile cell Y.
iCellValueTile GID/value at the queried cell (0 for out-of-bounds).
pUserDataUser payload passed through helper call.
Returns
true if the tile should be treated as solid.

Member Function Documentation

◆ integrateVelocity()

bool CRM64Pro::Physics::integrateVelocity ( float & fV,
float fA,
float fDT )
static

Integrate velocity using explicit Euler: v = v + a * dt.

Parameters
fVReference to velocity.
fAAcceleration.
fDTDelta time in seconds (must be >= 0).
Returns
true if velocity changed.

◆ applyLinearDamping()

bool CRM64Pro::Physics::applyLinearDamping ( float & fV,
float fDamping,
float fDT )
static

Apply linear damping to velocity: v *= max(0, 1 - damping * dt).

Parameters
fVReference to velocity.
fDampingDamping factor in 1/seconds (must be >= 0).
fDTDelta time in seconds (must be >= 0).
Returns
true if velocity changed.

◆ clampVelocity()

bool CRM64Pro::Physics::clampVelocity ( float & fV,
float fMaxV )
static

Clamp a velocity value within a maximum magnitude.

Parameters
fVReference to the velocity value to be clamped.
fMaxVThe maximum allowed velocity.
Returns
true if the value was clamped.

◆ isValidAABB()

bool CRM64Pro::Physics::isValidAABB ( const AABB & aabb)
static

Validate if an AABB contains finite values and non-inverted bounds.

Parameters
aabbAABB to validate.
Returns
true if bounds are finite and min<=max on both axes, otherwise false.

◆ containsPoint()

bool CRM64Pro::Physics::containsPoint ( const AABB & aabb,
float px,
float py )
static

Test if a point is inside an AABB using half-open bounds [min, max).

Parameters
aabbAABB to test against.
pxPoint X coordinate in world space.
pyPoint Y coordinate in world space.
Returns
true if point lies inside the half-open AABB, otherwise false.

◆ overlapsAABB()

bool CRM64Pro::Physics::overlapsAABB ( const AABB & aabb1,
const AABB & aabb2,
SDL_FRect * pOverlap = nullptr )
static

Test if two AABBs overlap using half-open bounds [min, max).

Parameters
aabb1First AABB.
aabb2Second AABB.
pOverlapOptional output pointer. When overlap exists, receives intersection rectangle in world space.
Returns
true if AABBs overlap, otherwise false.
Note
Uses half-open bounds semantics [min, max).

◆ overlapsObjectAABB()

bool CRM64Pro::Physics::overlapsObjectAABB ( const SceneObject * pObjA,
const SceneObject * pObjB,
SDL_FRect * pOverlap = nullptr )
static

Fast object-object broad phase using cached object AABBs.

Parameters
pObjAFirst object.
pObjBSecond object.
pOverlapOptional output pointer. When overlap exists, receives intersection rectangle in world space.
Returns
true if both objects are valid and their AABBs overlap, otherwise false.

◆ containsObjectPoint()

bool CRM64Pro::Physics::containsObjectPoint ( const SceneObject * pObj,
float fPX,
float fPY )
static

Precise point-in-object check using object shape geometry.

Parameters
pObjObject to test.
fPXPoint X coordinate in world space.
fPYPoint Y coordinate in world space.
Returns
true if point is inside object shape, otherwise false.

◆ overlapsObject()

bool CRM64Pro::Physics::overlapsObject ( const SceneObject * pObjA,
const SceneObject * pObjB,
ePhysicsCollisionMode eMode = PCM_SHAPE,
SDL_FRect * pOverlap = nullptr )
static

Object-object overlap with selectable narrow phase.

PCM_AABB uses only cached AABB overlap. PCM_SHAPE uses precise per-point shape checks inside the overlap region. PCM_PIXEL currently falls back to PCM_SHAPE when no sprite alpha source is available.

Parameters
pObjAFirst object.
pObjBSecond object.
eModeOverlap mode.
pOverlapOptional output pointer. Receives AABB intersection when broad-phase overlap exists.
Returns
true if overlap is detected according to selected mode, otherwise false.

◆ overlapsObjectTrigger()

bool CRM64Pro::Physics::overlapsObjectTrigger ( const SceneObject * pOwnerObj,
const SceneShapeData & triggerLocalShape,
const SceneObject * pOther,
ePhysicsCollisionMode eMode = PCM_SHAPE,
SDL_FRect * pOverlap = nullptr )
static

Trigger-local-shape versus object overlap.

The trigger shape is defined in owner-local coordinates and transformed to world space using owner transform.

Parameters
pOwnerObjOwner object that defines trigger transform space.
triggerLocalShapeTrigger shape in owner-local coordinates.
pOtherObject tested against trigger shape.
eModeOverlap mode.
pOverlapOptional output pointer. Receives trigger/object AABB overlap rectangle when broad-phase overlap exists.
Returns
true if overlap is detected according to selected mode, otherwise false.

◆ matchTypeHash()

bool CRM64Pro::Physics::matchTypeHash ( Uint32 iObjectTypeHash,
const vector< Uint32 > & vIncludeHashes,
const vector< Uint32 > & vExcludeHashes )
static

Fast hash filter helper for trigger/object-type matching.

Parameters
iObjectTypeHash32-bit type hash for tested object.
vIncludeHashesInclude filter hashes. Empty means include all.
vExcludeHashesExclude filter hashes. Matching any excludes the object.
Returns
true if hash passes include/exclude filters, otherwise false.

◆ overlapsSprite() [1/3]

bool CRM64Pro::Physics::overlapsSprite ( Sprite * pS1,
float fX1,
float fY1,
Sprite * pS2,
float fX2,
float fY2,
const SDL_FRect * pOverlap = nullptr,
ePhysicsCollisionMode eMode = PCM_PIXEL )

Check overlap between two sprites.

Parameters
pS1Pointer to the first Sprite.
fX1X position of the first sprite.
fY1Y position of the first sprite.
pS2Pointer to the second Sprite.
fX2X position of the second sprite.
fY2Y position of the second sprite.
pOverlapOptional pointer to a precomputed intersection rectangle to speed up math.
eModeOverlap mode. PCM_AABB performs rectangle overlap only, PCM_PIXEL performs pixel-perfect overlap, PCM_SHAPE is not supported for sprites in this version.
Returns
true if an overlap is detected according to selected mode.

◆ overlapsSprite() [2/3]

bool CRM64Pro::Physics::overlapsSprite ( Sprite * pS1,
float fX1,
float fY1,
const SDL_FRect & rect,
const SDL_FRect * pOverlap = nullptr,
ePhysicsCollisionMode eMode = PCM_PIXEL )

Check overlap between a sprite and a rectangle.

Parameters
pS1Pointer to the Sprite.
fX1X position of the sprite.
fY1Y position of the sprite.
rectReference to the SDL_FRect defining the overlap area.
pOverlapOptional pointer to a precomputed intersection rectangle to speed up math.
eModeOverlap mode. PCM_AABB performs rectangle overlap only, PCM_PIXEL performs pixel-perfect overlap, PCM_SHAPE is not supported for sprites in this version.
Returns
true if an overlap is detected according to selected mode.

◆ overlapsSprite() [3/3]

bool CRM64Pro::Physics::overlapsSprite ( Sprite * pS1,
float fX1,
float fY1,
float fPX,
float fPY,
ePhysicsCollisionMode eMode = PCM_PIXEL )

Check overlap between a sprite and a point.

Parameters
pS1Pointer to the Sprite.
fX1X position of the sprite.
fY1Y position of the sprite.
fPXX coordinate of the point.
fPYY coordinate of the point.
eModeOverlap mode. PCM_AABB performs sprite bounds test only, PCM_PIXEL performs pixel test, PCM_SHAPE is not supported for sprites in this version.
Returns
true if an overlap is detected according to selected mode.

◆ resolve()

bool CRM64Pro::Physics::resolve ( SDL_FRect & subject,
const SDL_FRect & obstacle )

Resolve overlap between two rectangular areas.

Note
Not implemented in this version.
Parameters
subjectReference to the subject rectangle (to be moved).
obstacleReference to the static obstacle rectangle.
Returns
true if overlap was resolved.

◆ sweepAABBOnLayerTile()

bool CRM64Pro::Physics::sweepAABBOnLayerTile ( const SDL_FRect & rectStart,
float fDX,
float fDY,
SceneLayerTile * pSceneLayer,
SDL_FRect * pRectResolved,
bool * pHitX = nullptr,
bool * pHitY = nullptr,
bool * pGrounded = nullptr,
TileSolidCallback fnSolid = nullptr,
void * pUserData = nullptr )

Sweep an AABB on a tile layer and resolve collisions (axis separated: X then Y).

Parameters
rectStartInitial world-space rectangle.
fDXDesired movement on X axis in world units.
fDYDesired movement on Y axis in world units.
pSceneLayerTile layer used as collision map.
pRectResolvedOutput resolved rectangle after collision response.
pHitXOptional output flag set to true when X movement is blocked.
pHitYOptional output flag set to true when Y movement is blocked.
pGroundedOptional output flag set when downward movement collides with ground.
fnSolidOptional solidity callback (default: any non-zero tile is solid, out-of-bounds sides/bottom are solid, above top is non-solid).
pUserDataUser payload passed to fnSolid.
Returns
true on valid execution, false on invalid inputs.
Note
Uses edge-sweep traversal across crossed tile columns/rows to avoid tunneling on large deltas.
Designed for platform/top-down kinematic movement and deterministic fixed-step updates.

◆ isGroundedOnLayerTile()

bool CRM64Pro::Physics::isGroundedOnLayerTile ( const SDL_FRect & rect,
SceneLayerTile * pSceneLayer,
float fProbeDistance = 1.0f,
TileSolidCallback fnSolid = nullptr,
void * pUserData = nullptr )

Ground probe helper against a tile layer.

Parameters
rectObject/world rectangle.
pSceneLayerTile layer used as collision map.
fProbeDistanceThickness of the feet probe strip in world units below rect bottom. Typical values: 0.5 to 4.0.
fnSolidOptional solidity callback (same semantics as sweepAABBOnTileLayer()).
pUserDataUser payload passed to fnSolid.
Returns
true if a solid tile overlaps the feet probe strip.

◆ info()

bool CRM64Pro::Physics::info ( Sint32 iMode = 0)
override

Request Physics Interface information.

Logs Physics information using the default log.

Parameters
iModeunused for the time being.
Returns
true on success or false on failure.