122 lines
3 KiB
C
122 lines
3 KiB
C
// SPDX-FileCopyrightText: 2026 Erin Catto
|
|
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
|
|
#include "box3d/collision.h"
|
|
#include "box3d/id.h"
|
|
#include "box3d/math_functions.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
// Ghost collision scenes, shared by the Mesh / Ghost Collisions sample and the headless ghost scan.
|
|
// Each ground is a profile in the xy-plane extruded along z and finely tessellated, so a sliding
|
|
// body crosses many internal edges. A manifold that pushes on the body is a ghost when its normal
|
|
// points outside the span of face normals under the body. Those are the ones that block or launch
|
|
// a body.
|
|
|
|
typedef enum GhostScene
|
|
{
|
|
e_ghostFlat,
|
|
e_ghostConcaveRamp,
|
|
e_ghostCliff,
|
|
e_ghostCrest,
|
|
e_ghostBumps,
|
|
e_ghostTJunction,
|
|
e_ghostShapeSeam,
|
|
e_ghostInternalEdges,
|
|
e_ghostSceneCount
|
|
} GhostScene;
|
|
|
|
typedef enum GhostBody
|
|
{
|
|
e_ghostBox,
|
|
e_ghostCapsule,
|
|
e_ghostUprightCapsule,
|
|
e_ghostSphere,
|
|
e_ghostCylinder,
|
|
e_ghostBodyCount
|
|
} GhostBody;
|
|
|
|
// Mesh variants of the PEEL InternalEdges presets
|
|
#define GHOST_PEEL_PRESET_COUNT 4
|
|
|
|
// Bumps has the longest profile
|
|
#define GHOST_MAX_PROFILE_POINTS 96
|
|
|
|
extern const char* g_ghostSceneNames[e_ghostSceneCount];
|
|
extern const char* g_ghostBodyNames[e_ghostBodyCount];
|
|
extern const char* g_ghostPeelPresetNames[GHOST_PEEL_PRESET_COUNT];
|
|
|
|
typedef struct GhostSettings
|
|
{
|
|
GhostScene scene;
|
|
GhostBody body;
|
|
int peelPreset;
|
|
bool mirror;
|
|
float cellSize;
|
|
float speed;
|
|
|
|
// Degrees
|
|
float yaw;
|
|
|
|
float friction;
|
|
bool fixedRotation;
|
|
bool speculative;
|
|
} GhostSettings;
|
|
|
|
GhostSettings GetDefaultGhostSettings( void );
|
|
|
|
typedef struct GhostReport
|
|
{
|
|
b3Pos point;
|
|
b3Vec3 normal;
|
|
float separation;
|
|
float impulse;
|
|
} GhostReport;
|
|
|
|
typedef struct GhostCollisionsData
|
|
{
|
|
GhostSettings settings;
|
|
b3Vec2 profile[GHOST_MAX_PROFILE_POINTS];
|
|
int profileCount;
|
|
b3MeshData* meshes[2];
|
|
int meshCount;
|
|
b3HullData* cylinder;
|
|
b3HullData* peelCylinder;
|
|
b3BodyId groundId;
|
|
b3BodyId bodyId;
|
|
b3ShapeId shapeId;
|
|
|
|
// Steps in the current run
|
|
int runSteps;
|
|
|
|
// Completed runs, each ending when the body reaches the end or falls off
|
|
int runCount;
|
|
|
|
int runGhostCount;
|
|
int ghostCount;
|
|
} GhostCollisionsData;
|
|
|
|
// Creates the ground and launches the body
|
|
GhostCollisionsData CreateGhostCollisions( b3WorldId worldId, GhostSettings settings );
|
|
|
|
// Rebuild the ground after a scene, preset, mirror or cell size change. Relaunch after this.
|
|
void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data );
|
|
|
|
// Launch a new body from the start, after a body, speed, yaw, friction or rotation change
|
|
void LaunchGhostBody( b3WorldId worldId, GhostCollisionsData* data );
|
|
|
|
// Call after each world step. Relaunches a body that finished its run, then counts the ghost
|
|
// manifolds on the body. Returns the ghost count for this step and writes up to capacity reports.
|
|
int UpdateGhostCollisions( b3WorldId worldId, GhostCollisionsData* data, GhostReport* reports, int capacity );
|
|
|
|
void DestroyGhostCollisions( GhostCollisionsData* data );
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|