OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Functions | Variables
Collisions.cpp File Reference
#include "Collisions.h"
#include <algorithm>
#include <limits>
#include <utility>
#include "Engine/Events/Processor.h"
#include "Engine/Objects/DecorationList.h"
#include "Engine/Objects/Decoration.h"
#include "Engine/Graphics/Outdoor.h"
#include "Engine/Graphics/Indoor.h"
#include "Engine/Objects/Actor.h"
#include "Engine/Objects/ObjectList.h"
#include "Engine/Objects/SpriteObject.h"
#include "Engine/TurnEngine/TurnEngine.h"
#include "Engine/OurMath.h"
#include "Engine/Party.h"
#include "Engine/Engine.h"
#include "Engine/Random/Random.h"
#include "Utility/Math/Float.h"
#include "Utility/Math/TrigLut.h"

Functions

static bool CollideWithLine (const Vec3f p1, const Vec3f p2, const float radius, const float currentmovedist, float *newmovedist, float *intersection, bool inside)
 
static bool CollideSphereWithFace (BLVFace *face, const Vec3f &pos, float radius, const Vec3f &dir, float *out_move_distance, Vec3f *out_collision_point, bool ignore_ethereal, int model_idx)
 
static bool CollidePointWithFace (BLVFace *face, const Vec3f &pos, const Vec3f &dir, float *out_move_distance, int model_idx)
 
static void CollideBodyWithFace (BLVFace *face, Pid face_pid, bool ignore_ethereal, int model_idx)
 
static bool CollideWithCylinder (const Vec3f &center_lo, float radius, float height, Pid pid, bool jagged_top)
 
static void CollideWithDecoration (int id)
 
void CollideIndoorWithGeometry (bool ignore_ethereal)
 
void CollideOutdoorWithModels (bool ignore_ethereal)
 
void CollideIndoorWithDecorations ()
 
void CollideOutdoorWithDecorations (Vec2i gridPos)
 
bool CollideIndoorWithPortals ()
 
bool CollideWithActor (int actor_idx, int override_radius)
 
void _46ED8A_collide_against_sprite_objects (Pid pid)
 
void CollideWithParty (bool jagged_top)
 
void ProcessActorCollisionsBLV (Actor &actor, bool isAboveGround, bool isFlying)
 
void ProcessActorCollisionsODM (Actor &actor, bool isFlying)
 
void ProcessPartyCollisionsBLV (int sectorId, int min_party_move_delta_sqr, int *faceId, int *faceEvent)
 
void ProcessPartyCollisionsODM (Vec3f *partyNewPos, Vec3f *partyInputSpeed, int *floorFaceId, bool *partyNotOnModel, bool *partyHasHitModel, int *triggerID)
 
bool hasShorterSolution (const float a, const float b, const float c, const float curSoln, float *outNewSoln, bool inside)
 

Variables

CollisionState collision_state
 
constexpr float COLLISIONS_EPS = 0.01f
 
constexpr float COLLISIONS_MIN_MOVE_DISTANCE = 0.5f
 

Function Documentation

◆ _46ED8A_collide_against_sprite_objects()

void _46ED8A_collide_against_sprite_objects ( Pid  pid)

◆ CollideBodyWithFace()

static void CollideBodyWithFace ( BLVFace face,
Pid  face_pid,
bool  ignore_ethereal,
int  model_idx 
)
static

Helper function that performs several collision checks between both the "feet" and the "head" spheres of the collision state, and the provided face.

Parameters
faceFace to check.
face_pidPid of the provided face.
ignore_etherealWhether ethereal faces should be ignored by this function.
model_idxModel index, or MODEL_INDOOR.

◆ CollideIndoorWithDecorations()

void CollideIndoorWithDecorations ( )
Original binary offset:
0x0046E0B2.

◆ CollideIndoorWithGeometry()

void CollideIndoorWithGeometry ( bool  ignore_ethereal)
Original binary offset:
0x0046E44E.

Performs collisions with level geometry in indoor levels. Updates collision_state.

Parameters
ignore_etherealWhether ethereal faces should be ignored by this function.

◆ CollideIndoorWithPortals()

bool CollideIndoorWithPortals ( )
Original binary offset:
0x0046F04E.

Performs collision checks with portals. Updates collision_state. If the collision did happen, then adjusted_move_distance member is set to 0xFFFFFF (basically a large number).

Returns
True if there were no collisions with portals.

◆ CollideOutdoorWithDecorations()

void CollideOutdoorWithDecorations ( Vec2i  gridPos)
Original binary offset:
0x0046E26D.
Parameters
gridPosGrid coordinates.

◆ CollideOutdoorWithModels()

void CollideOutdoorWithModels ( bool  ignore_ethereal)
Original binary offset:
0x0046E889.

Performs collisions with models in outdoor levels. Updates collision_state.

Parameters
ignore_etherealWhether ethereal faces should be ignored by this function.

◆ CollidePointWithFace()

static bool CollidePointWithFace ( BLVFace face,
const Vec3f pos,
const Vec3f dir,
float *  out_move_distance,
int  model_idx 
)
static
Original binary offset:
0x00475D85, 0x00475F30.
Parameters
facePolygon to check collision against.
posActor position to check.
dirMovement direction as a unit vector.
[in,out]out_move_distanceCurrent movement distance along the dir axis. This parameter is not touched when the function returns false. If the function returns true, then the distance required to hit the polygon is stored here. Note that this effectively means that this function can only decrease move_distance, but never increase it.
model_idxModel index, or MODEL_INDOOR.
Returns
Whether the actor, modeled as a point, hits the provided polygon if moving from pos along the dir axis by at most move_distance.

◆ CollideSphereWithFace()

static bool CollideSphereWithFace ( BLVFace face,
const Vec3f pos,
float  radius,
const Vec3f dir,
float *  out_move_distance,
Vec3f out_collision_point,
bool  ignore_ethereal,
int  model_idx 
)
static
Original binary offset:
0x0047531C, 0x004754BF.
Parameters
facePolygon to check collision against.
posActor position to check.
radiusActor radius.
dirMovement direction as a unit vector.
[out]out_move_distanceMove distance along the dir axis required to touch the provided polygon. Always non-negative. This parameter is not set if the function returns false. Note that "touching" in this context means that the distance from the actor's center to the polygon equals actor's radius.
[out]out_collision_pointPoint at which collision between sphere and face occurs.
ignore_etherealWhether ethereal faces should be ignored by this function.
model_idxModel index, or MODEL_INDOOR.
Returns
Whether the actor, basically modeled as a sphere, can actually collide with the polygon if moving along the dir axis.

◆ CollideWithActor()

bool CollideWithActor ( int  actor_idx,
int  override_radius 
)
Original binary offset:
0x0046DF1A.
Parameters
actor_idxActor index.
override_radiusOverride actor's radius. Pass zero to use original radius.
Returns
Whether the collision is possible.

◆ CollideWithCylinder()

static bool CollideWithCylinder ( const Vec3f center_lo,
float  radius,
float  height,
Pid  pid,
bool  jagged_top 
)
static

Performs a collision check with a cylinder.

Parameters
center_loCenter of the cylinder's base.
radiusCylinder radius.
heightCylinder height.
pidPid of the object represented by the cylinder.
jagged_topSee CollideWithParty.
Returns
Whether there is a collision.

◆ CollideWithDecoration()

static void CollideWithDecoration ( int  id)
static

◆ CollideWithLine()

static bool CollideWithLine ( const Vec3f  p1,
const Vec3f  p2,
const float  radius,
const float  currentmovedist,
float *  newmovedist,
float *  intersection,
bool  inside 
)
static
Parameters
p1Starting point of line.
p2End point of line.
radiusRadius to use.
currentmovedistCurrent largest movement distance before a collision.
[out]newmovedistMove distance along the dir axis required to touch the provided line with provided radius. Always non-negative. This parameter is not set if the function returns false.
[out]intersectionHow far along the line p1->p2 the collision will occur in the range [0 - 1]. Not set if the function returns false.
insideWhether collisions should happen when inside radius
Returns
Whether the sphere of radius at position of collision state 'lo', can collide with the line p1 to p2 if moving along the dir axis AND the distance required to move for that collision is less than the current distance.

◆ CollideWithParty()

void CollideWithParty ( bool  jagged_top)
Original binary offset:
0x0046EF01.
Parameters
jagged_topMakes collision happen even if the monster would end up above the party. However, for the collision to happen, corresponding bounding boxes still need to intersect.

◆ hasShorterSolution()

bool hasShorterSolution ( const float  a,
const float  b,
const float  c,
const float  curSoln,
float *  outNewSoln,
bool  inside = false 
)

Finds whether this quadratic (of the form AX^2 + BX + C = 0) can be solved and if the solution is smaller than out current solution. Returns true if a smaller non negative solution is found.

Parameters
aA component of quadratic.
bB component of quadratic.
cC component of quadratic.
curSolnCurrent input smallest solution to test against.
[out]outNewSolnNew smallest non negative solution. This value is not set if the function returns false.
insideIf you want collision with any point inside radius - for cylinder decorations/party
Returns
True if the quadratic has a valid solution that is smaller than the input curSoln.

◆ ProcessActorCollisionsBLV()

void ProcessActorCollisionsBLV ( Actor actor,
bool  isAboveGround,
bool  isFlying 
)

Handles actor movement - performs collision detection, updates actor's position, handles sliding on slopes, deceleration, etc.

Parameters
actorActor to move.
isAboveGroundWhether the actor is currently above ground (stands on air, basically).
isFlyingWhether the actor is a flying creature that can fly (e.g. not paralyzed).

◆ ProcessActorCollisionsODM()

void ProcessActorCollisionsODM ( Actor actor,
bool  isFlying 
)

◆ ProcessPartyCollisionsBLV()

void ProcessPartyCollisionsBLV ( int  sectorId,
int  min_party_move_delta_sqr,
int *  faceId,
int *  faceEvent 
)

◆ ProcessPartyCollisionsODM()

void ProcessPartyCollisionsODM ( Vec3f partyNewPos,
Vec3f partyInputSpeed,
int *  floorFaceId,
bool *  partyNotOnModel,
bool *  partyHasHitModel,
int *  triggerID 
)

Variable Documentation

◆ collision_state

CollisionState collision_state

◆ COLLISIONS_EPS

constexpr float COLLISIONS_EPS = 0.01f
constexpr

◆ COLLISIONS_MIN_MOVE_DISTANCE

constexpr float COLLISIONS_MIN_MOVE_DISTANCE = 0.5f
constexpr