OpenEnroth 73e68f7
|
#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 ¢er_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 |
void _46ED8A_collide_against_sprite_objects | ( | Pid | pid | ) |
|
static |
Helper function that performs several collision checks between both the "feet" and the "head" spheres of the collision state, and the provided face.
face | Face to check. |
face_pid | Pid of the provided face. |
ignore_ethereal | Whether ethereal faces should be ignored by this function. |
model_idx | Model index, or MODEL_INDOOR . |
void CollideIndoorWithDecorations | ( | ) |
void CollideIndoorWithGeometry | ( | bool | ignore_ethereal | ) |
Performs collisions with level geometry in indoor levels. Updates collision_state
.
ignore_ethereal | Whether ethereal faces should be ignored by this function. |
bool CollideIndoorWithPortals | ( | ) |
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).
void CollideOutdoorWithDecorations | ( | Vec2i | gridPos | ) |
gridPos | Grid coordinates. |
void CollideOutdoorWithModels | ( | bool | ignore_ethereal | ) |
Performs collisions with models in outdoor levels. Updates collision_state
.
ignore_ethereal | Whether ethereal faces should be ignored by this function. |
|
static |
face | Polygon to check collision against. | |
pos | Actor position to check. | |
dir | Movement direction as a unit vector. | |
[in,out] | out_move_distance | Current 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_idx | Model index, or MODEL_INDOOR . |
pos
along the dir
axis by at most move_distance
.
|
static |
face | Polygon to check collision against. | |
pos | Actor position to check. | |
radius | Actor radius. | |
dir | Movement direction as a unit vector. | |
[out] | out_move_distance | Move 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_point | Point at which collision between sphere and face occurs. |
ignore_ethereal | Whether ethereal faces should be ignored by this function. | |
model_idx | Model index, or MODEL_INDOOR . |
dir
axis. bool CollideWithActor | ( | int | actor_idx, |
int | override_radius | ||
) |
actor_idx | Actor index. |
override_radius | Override actor's radius. Pass zero to use original radius. |
|
static |
Performs a collision check with a cylinder.
center_lo | Center of the cylinder's base. |
radius | Cylinder radius. |
height | Cylinder height. |
pid | Pid of the object represented by the cylinder. |
jagged_top | See CollideWithParty . |
|
static |
|
static |
p1 | Starting point of line. | |
p2 | End point of line. | |
radius | Radius to use. | |
currentmovedist | Current largest movement distance before a collision. | |
[out] | newmovedist | Move 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] | intersection | How far along the line p1->p2 the collision will occur in the range [0 - 1]. Not set if the function returns false. |
inside | Whether collisions should happen when inside radius |
dir
axis AND the distance required to move for that collision is less than the current distance. void CollideWithParty | ( | bool | jagged_top | ) |
jagged_top | Makes 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. |
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.
a | A component of quadratic. | |
b | B component of quadratic. | |
c | C component of quadratic. | |
curSoln | Current input smallest solution to test against. | |
[out] | outNewSoln | New smallest non negative solution. This value is not set if the function returns false. |
inside | If you want collision with any point inside radius - for cylinder decorations/party |
void ProcessActorCollisionsBLV | ( | Actor & | actor, |
bool | isAboveGround, | ||
bool | isFlying | ||
) |
Handles actor movement - performs collision detection, updates actor's position, handles sliding on slopes, deceleration, etc.
actor | Actor to move. |
isAboveGround | Whether the actor is currently above ground (stands on air, basically). |
isFlying | Whether the actor is a flying creature that can fly (e.g. not paralyzed). |
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 | ||
) |
CollisionState collision_state |
|
constexpr |
|
constexpr |