Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
PhysicsQueries.cpp File Reference
#include "./PhysicsBindings.hpp"
#include "./PhysicsContext.hpp"
#include <cfloat>
#include <cstring>
Include dependency graph for PhysicsQueries.cpp:

Go to the source code of this file.

Functions

static float raycastCallback (b2ShapeId shapeId, b2Vec2 point, b2Vec2 normal, float fraction, void *context)
static bool overlapCallback (b2ShapeId shapeId, void *context)
static float shapeCastCallback (b2ShapeId shapeId, b2Vec2 point, b2Vec2 normal, float fraction, void *context)
static bool oneWayAdmits (b2ShapeId shapeId, uint32_t entity, b2Vec2 normal, float depth)
static bool normalIsSurface (b2ShapeId shapeId, const b2PlaneResult *pr)
static bool moverPlaneCallback (b2ShapeId shapeId, const b2PlaneResult *pr, void *context)
static float snapCastCallback (b2ShapeId shapeId, b2Vec2 point, b2Vec2 normal, float fraction, void *context)
static float headroomCastCallback (b2ShapeId shapeId, b2Vec2 point, b2Vec2 normal, float fraction, void *context)
int physics_raycast (float originX, float originY, float dirX, float dirY, float maxDistance, uint32_t maskBits)
uintptr_t physics_getRaycastBuffer ()
int physics_overlapCircle (float centerX, float centerY, float radius, uint32_t maskBits)
uintptr_t physics_getOverlapBuffer ()
int physics_shapeCastCircle (float centerX, float centerY, float radius, float translationX, float translationY, uint32_t maskBits)
int physics_shapeCastBox (float centerX, float centerY, float halfW, float halfH, float angle, float translationX, float translationY, uint32_t maskBits)
int physics_shapeCastCapsule (float center1X, float center1Y, float center2X, float center2Y, float radius, float translationX, float translationY, uint32_t maskBits)
uintptr_t physics_getShapeCastBuffer ()
int physics_overlapAABB (float minX, float minY, float maxX, float maxY, uint32_t maskBits)
int physics_moveCharacter (float px, float py, float c1x, float c1y, float c2x, float c2y, float radius, float velX, float velY, float dt, float upX, float upY, float floorCos, uint32_t maskBits, uint32_t selfEntity, float skinWidth, int maxSlides, float snapLength, int slideOnCeiling, float carryX, float carryY, uint32_t flags, float stepHeight)
uintptr_t physics_getMoveCharacterBuffer ()

Variables

static constexpr int MAX_MOVER_PLANES = 32
static constexpr int MAX_MOVER_HITS = 4
static constexpr float MOVER_ONE_WAY_ALIGN = 0.5f
static constexpr float MOVER_ONE_WAY_SLOP = 0.02f
static constexpr uint32_t MOVER_DROP_THROUGH = 1u
static constexpr uint32_t MOVER_IGNORE_DYNAMIC = 2u
static constexpr uint32_t MOVER_BLOCK_STEEP = 4u
static constexpr uint32_t MOVER_WAS_ON_FLOOR = 8u
static b2CollisionPlane g_moverPlanes [MAX_MOVER_PLANES]
static uint32_t g_moverPlaneEntity [MAX_MOVER_PLANES]
static bool g_moverPlaneSurface [MAX_MOVER_PLANES]
static int g_moverPlaneCount = 0
static uint32_t g_moverSelfEntity = 0xFFFFFFFF
static uint32_t g_moverFlags = 0
static b2Vec2 g_moverVelocity = {0.0f, 0.0f}
static float g_moverDt = 0.0f
static float g_moverBuffer [11+MAX_MOVER_HITS *3] = {}
static uint32_t g_moverHitEntity [MAX_MOVER_HITS]
static b2Vec2 g_moverHitNormal [MAX_MOVER_HITS]
static int g_moverHitCount = 0
static float g_snapClosest = 1.0f
static b2Vec2 g_snapNormal = {0.0f, 0.0f}
static uint32_t g_snapEntity = 0xFFFFFFFF
static bool g_snapHit = false
static b2Vec2 g_snapUp = {0.0f, 1.0f}
static float g_snapFloorCos = 0.0f
static float g_headroom = 1.0f

Function Documentation

◆ headroomCastCallback()

float headroomCastCallback ( b2ShapeId shapeId,
b2Vec2 point,
b2Vec2 normal,
float fraction,
void * context )
static

◆ moverPlaneCallback()

◆ normalIsSurface()

bool normalIsSurface ( b2ShapeId shapeId,
const b2PlaneResult * pr )
static

Whether a contact's normal is the surface's own. A rounded foot on the corner of a ledge gets a leaning normal off no slope at all, and a ray along it tells them apart: it lands on a face, and only a real slope's face leans.

Definition at line 102 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback().

◆ oneWayAdmits()

bool oneWayAdmits ( b2ShapeId shapeId,
uint32_t entity,
b2Vec2 normal,
float depth )
static

A one-way surface answers only from its solid side, while what meets it is not rising, and not once it is already inside it.

Definition at line 85 of file PhysicsQueries.cpp.

References g_ctx, g_moverDt, g_moverFlags, g_moverVelocity, MOVER_DROP_THROUGH, MOVER_ONE_WAY_ALIGN, and MOVER_ONE_WAY_SLOP.

Referenced by moverPlaneCallback(), and snapCastCallback().

◆ overlapCallback()

bool overlapCallback ( b2ShapeId shapeId,
void * context )
static

◆ physics_getMoveCharacterBuffer()

uintptr_t physics_getMoveCharacterBuffer ( )

Definition at line 524 of file PhysicsQueries.cpp.

References g_moverBuffer.

◆ physics_getOverlapBuffer()

uintptr_t physics_getOverlapBuffer ( )

Definition at line 316 of file PhysicsQueries.cpp.

References g_overlapBuffer.

◆ physics_getRaycastBuffer()

uintptr_t physics_getRaycastBuffer ( )

Definition at line 294 of file PhysicsQueries.cpp.

References g_raycastBuffer.

◆ physics_getShapeCastBuffer()

uintptr_t physics_getShapeCastBuffer ( )

Definition at line 378 of file PhysicsQueries.cpp.

References g_shapeCastBuffer.

◆ physics_moveCharacter()

int physics_moveCharacter ( float px,
float py,
float c1x,
float c1y,
float c2x,
float c2y,
float radius,
float velX,
float velY,
float dt,
float upX,
float upY,
float floorCos,
uint32_t maskBits,
uint32_t selfEntity,
float skinWidth,
int maxSlides,
float snapLength,
int slideOnCeiling,
float carryX,
float carryY,
uint32_t flags,
float stepHeight )

◆ physics_overlapAABB()

int physics_overlapAABB ( float minX,
float minY,
float maxX,
float maxY,
uint32_t maskBits )

Definition at line 383 of file PhysicsQueries.cpp.

References g_ctx, g_overlapBuffer, and overlapCallback().

◆ physics_overlapCircle()

int physics_overlapCircle ( float centerX,
float centerY,
float radius,
uint32_t maskBits )

Definition at line 299 of file PhysicsQueries.cpp.

References g_ctx, g_overlapBuffer, and overlapCallback().

◆ physics_raycast()

int physics_raycast ( float originX,
float originY,
float dirX,
float dirY,
float maxDistance,
uint32_t maskBits )

Definition at line 276 of file PhysicsQueries.cpp.

References g_ctx, g_raycastBuffer, RAYCAST_STRIDE, and raycastCallback().

◆ physics_shapeCastBox()

int physics_shapeCastBox ( float centerX,
float centerY,
float halfW,
float halfH,
float angle,
float translationX,
float translationY,
uint32_t maskBits )

Definition at line 340 of file PhysicsQueries.cpp.

References g_ctx, g_shapeCastBuffer, SHAPECAST_STRIDE, and shapeCastCallback().

◆ physics_shapeCastCapsule()

int physics_shapeCastCapsule ( float center1X,
float center1Y,
float center2X,
float center2Y,
float radius,
float translationX,
float translationY,
uint32_t maskBits )

Definition at line 359 of file PhysicsQueries.cpp.

References g_ctx, g_shapeCastBuffer, SHAPECAST_STRIDE, and shapeCastCallback().

◆ physics_shapeCastCircle()

int physics_shapeCastCircle ( float centerX,
float centerY,
float radius,
float translationX,
float translationY,
uint32_t maskBits )

Definition at line 321 of file PhysicsQueries.cpp.

References g_ctx, g_shapeCastBuffer, SHAPECAST_STRIDE, and shapeCastCallback().

◆ raycastCallback()

float raycastCallback ( b2ShapeId shapeId,
b2Vec2 point,
b2Vec2 normal,
float fraction,
void * context )
static

◆ shapeCastCallback()

float shapeCastCallback ( b2ShapeId shapeId,
b2Vec2 point,
b2Vec2 normal,
float fraction,
void * context )
static

◆ snapCastCallback()

float snapCastCallback ( b2ShapeId shapeId,
b2Vec2 point,
b2Vec2 normal,
float fraction,
void * context )
static

Variable Documentation

◆ g_headroom

float g_headroom = 1.0f
static

Definition at line 171 of file PhysicsQueries.cpp.

Referenced by headroomCastCallback().

◆ g_moverBuffer

float g_moverBuffer[11+MAX_MOVER_HITS *3] = {}
static

Definition at line 79 of file PhysicsQueries.cpp.

Referenced by physics_getMoveCharacterBuffer(), and physics_moveCharacter().

◆ g_moverDt

float g_moverDt = 0.0f
static

Definition at line 77 of file PhysicsQueries.cpp.

Referenced by oneWayAdmits(), and physics_moveCharacter().

◆ g_moverFlags

uint32_t g_moverFlags = 0
static

◆ g_moverHitCount

int g_moverHitCount = 0
static

Definition at line 82 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ g_moverHitEntity

uint32_t g_moverHitEntity[MAX_MOVER_HITS]
static

Definition at line 80 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ g_moverHitNormal

b2Vec2 g_moverHitNormal[MAX_MOVER_HITS]
static

Definition at line 81 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ g_moverPlaneCount

int g_moverPlaneCount = 0
static

Definition at line 72 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ g_moverPlaneEntity

uint32_t g_moverPlaneEntity[MAX_MOVER_PLANES]
static

Definition at line 70 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ g_moverPlanes

b2CollisionPlane g_moverPlanes[MAX_MOVER_PLANES]
static

Definition at line 69 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ g_moverPlaneSurface

bool g_moverPlaneSurface[MAX_MOVER_PLANES]
static

Definition at line 71 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback().

◆ g_moverSelfEntity

uint32_t g_moverSelfEntity = 0xFFFFFFFF
static

◆ g_moverVelocity

b2Vec2 g_moverVelocity = {0.0f, 0.0f}
static

Definition at line 76 of file PhysicsQueries.cpp.

Referenced by oneWayAdmits(), and physics_moveCharacter().

◆ g_snapClosest

float g_snapClosest = 1.0f
static

Definition at line 146 of file PhysicsQueries.cpp.

Referenced by physics_moveCharacter(), and snapCastCallback().

◆ g_snapEntity

uint32_t g_snapEntity = 0xFFFFFFFF
static

Definition at line 148 of file PhysicsQueries.cpp.

Referenced by physics_moveCharacter(), and snapCastCallback().

◆ g_snapFloorCos

float g_snapFloorCos = 0.0f
static

Definition at line 151 of file PhysicsQueries.cpp.

Referenced by physics_moveCharacter(), and snapCastCallback().

◆ g_snapHit

bool g_snapHit = false
static

Definition at line 149 of file PhysicsQueries.cpp.

Referenced by physics_moveCharacter(), and snapCastCallback().

◆ g_snapNormal

b2Vec2 g_snapNormal = {0.0f, 0.0f}
static

Definition at line 147 of file PhysicsQueries.cpp.

Referenced by physics_moveCharacter(), and snapCastCallback().

◆ g_snapUp

b2Vec2 g_snapUp = {0.0f, 1.0f}
static

◆ MAX_MOVER_HITS

int MAX_MOVER_HITS = 4
staticconstexpr

Definition at line 57 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback().

◆ MAX_MOVER_PLANES

int MAX_MOVER_PLANES = 32
staticconstexpr

Definition at line 56 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback().

◆ MOVER_BLOCK_STEEP

uint32_t MOVER_BLOCK_STEEP = 4u
staticconstexpr

Definition at line 66 of file PhysicsQueries.cpp.

Referenced by moverPlaneCallback(), and physics_moveCharacter().

◆ MOVER_DROP_THROUGH

uint32_t MOVER_DROP_THROUGH = 1u
staticconstexpr

Definition at line 64 of file PhysicsQueries.cpp.

Referenced by oneWayAdmits().

◆ MOVER_IGNORE_DYNAMIC

uint32_t MOVER_IGNORE_DYNAMIC = 2u
staticconstexpr

Definition at line 65 of file PhysicsQueries.cpp.

Referenced by headroomCastCallback(), moverPlaneCallback(), and snapCastCallback().

◆ MOVER_ONE_WAY_ALIGN

float MOVER_ONE_WAY_ALIGN = 0.5f
staticconstexpr

Definition at line 60 of file PhysicsQueries.cpp.

Referenced by oneWayAdmits().

◆ MOVER_ONE_WAY_SLOP

float MOVER_ONE_WAY_SLOP = 0.02f
staticconstexpr

Definition at line 62 of file PhysicsQueries.cpp.

Referenced by oneWayAdmits().

◆ MOVER_WAS_ON_FLOOR

uint32_t MOVER_WAS_ON_FLOOR = 8u
staticconstexpr

Definition at line 67 of file PhysicsQueries.cpp.

Referenced by physics_moveCharacter().