| CRM64Pro GDK v0.18.0 A free cross-platform game development kit built on top of SDL 3.0

Loading...
Searching...
No Matches
CRM64Pro::Physicsfinal
Graphics modules » Physics

Physics module class. More...

## Detailed Description

Physics module class.

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

## Public Types
using | TileSolidCallback = bool (*)(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 &rRect, 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 &rSubject, const SDL_FRect &rObstacle)
| Resolve overlap between two rectangular areas.
bool | sweepAABBOnLayerTile (const SDL_FRect &rRectStart, float fDX, float fDY, const 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 &rRect, const 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 module 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 fX, float fY)
| 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

using CRM64Pro::Physics::TileSolidCallback = bool (*)(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

  pTileLayer | Tile layer being queried.
  iCellX | Tile cell X.
  iCellY | Tile cell Y.
  iCellValue | Tile GID/value at the queried cell (0 for out-of-bounds).
  pUserData | User 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

  fV | Reference to velocity.
  fA | Acceleration.
  fDT | Delta 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

  fV | Reference to velocity.
  fDamping | Damping factor in 1/seconds (must be >= 0).
  fDT | Delta 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

  fV | Reference to the velocity value to be clamped.
  fMaxV | The maximum allowed velocity magnitude. Must be >= 0.

Returns
  true if the value was clamped, false if unchanged or if fMaxV is invalid.

## ◆ isValidAABB()

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

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

Parameters

  aabb | AABB 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 | fX,
|  | float | fY )
| static

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

Parameters

  aabb | AABB to test against.
  fX | Point X coordinate in world space.
  fY | Point 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

  aabb1 | First AABB.
  aabb2 | Second AABB.
  pOverlap | Optional 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

  pObjA | First object.
  pObjB | Second object.
  pOverlap | Optional 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

  pObj | Object to test.
  fPX | Point X coordinate in world space.
  fPY | Point 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

  pObjA | First object.
  pObjB | Second object.
  eMode | Overlap mode.
  pOverlap | Optional 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

  pOwnerObj | Owner object that defines trigger transform space.
  triggerLocalShape | Trigger shape in owner-local coordinates.
  pOther | Object tested against trigger shape.
  eMode | Overlap mode.
  pOverlap | Optional 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

  iObjectTypeHash | 32-bit type hash for tested object.
  vIncludeHashes | Include filter hashes. Empty means include all.
  vExcludeHashes | Exclude 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

  pS1 | Pointer to the first Sprite.
  fX1 | X position of the first sprite.
  fY1 | Y position of the first sprite.
  pS2 | Pointer to the second Sprite.
  fX2 | X position of the second sprite.
  fY2 | Y position of the second sprite.
  pOverlap | Optional input pointer to a precomputed intersection rectangle used as a cache to speed up math. It is not modified.
  eMode | Overlap 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 & | rRect,
|  | const SDL_FRect * | pOverlap = nullptr,
|  | ePhysicsCollisionMode | eMode = PCM_PIXEL )

Check overlap between a sprite and a rectangle.

Parameters

  pS1 | Pointer to the Sprite.
  fX1 | X position of the sprite.
  fY1 | Y position of the sprite.
  rRect | Reference to the SDL_FRect defining the overlap area.
  pOverlap | Optional input pointer to a precomputed intersection rectangle used as a cache to speed up math. It is not modified.
  eMode | Overlap 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

  pS1 | Pointer to the Sprite.
  fX1 | X position of the sprite.
  fY1 | Y position of the sprite.
  fPX | X coordinate of the point.
  fPY | Y coordinate of the point.
  eMode | Overlap 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 & | rSubject,
|  | const SDL_FRect & | rObstacle )

Resolve overlap between two rectangular areas.

Note
  Not implemented in this version.

Parameters

  rSubject | Reference to the subject rectangle (to be moved).
  rObstacle | Reference to the static obstacle rectangle.

Returns
  true if overlap was resolved.

## ◆ sweepAABBOnLayerTile()

bool CRM64Pro::Physics::sweepAABBOnLayerTile | ( | const SDL_FRect & | rRectStart,
|  | float | fDX,
|  | float | fDY,
|  | const 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

  rRectStart | Initial world-space rectangle.
  fDX | Desired movement on X axis in world units.
  fDY | Desired movement on Y axis in world units.
  pSceneLayer | Tile layer used as collision map.
  pRectResolved | Output resolved rectangle after collision response.
  pHitX | Optional output flag set to true when X movement is blocked.
  pHitY | Optional output flag set to true when Y movement is blocked.
  pGrounded | Optional output flag set when downward movement collides with ground.
  fnSolid | Optional solidity callback (default: any non-zero tile is solid, out-of-bounds sides/bottom are solid, above top is non-solid).
  pUserData | User 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 & | rRect,
|  | const SceneLayerTile * | pSceneLayer,
|  | float | fProbeDistance = 1.0f,
|  | TileSolidCallback | fnSolid = nullptr,
|  | void * | pUserData = nullptr )

Ground probe helper against a tile layer.

Parameters

  rRect | Object/world rectangle.
  pSceneLayer | Tile layer used as collision map.
  fProbeDistance | Thickness of the feet probe strip in world units below rect bottom. Typical values: 0.5 to 4.0.
  fnSolid | Optional solidity callback (same semantics as sweepAABBOnLayerTile()).
  pUserData | User 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 module information.

Logs Physics information using the default log.

Parameters

  iMode | Reserved for future use. Pass 0.

Returns
  true on success, or false on failure.