UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cmodel.cpp File Reference

model loading and grid oriented movement and scanning More...

#include "common.h"
#include "tracing.h"

Go to the source code of this file.

Functions

static void CM_CalculateWidestBoundingBox (const cBspModel_t *model, AABB &box)
 Calculates the worst case bounding box for the given bsp model. More...
 
static bool CM_LineMissesModel (const Line &tLine, const cBspModel_t *model)
 A quick test if the trace might hit the inline model. More...
 
trace_t CM_HintedTransformedBoxTrace (MapTile &tile, const Line &traceLine, const AABB &traceBox, const int headnode, const int contentmask, const int brushrejects, const vec3_t origin, const vec3_t angles, const vec3_t rmaShift, const float fraction)
 Handles offseting and rotation of the end points for moving and rotating entities. More...
 
int32_t CM_HeadnodeForBox (MapTile &tile, const AABB &box)
 To keep everything totally uniform, bounding boxes are turned into small BSP trees instead of being compared directly. More...
 
bool CM_EntTestLine (mapTiles_t *mapTiles, const Line &traceLine, const int levelmask, const char **entlist)
 Checks traces against the world and all inline models. More...
 
bool CM_EntTestLineDM (mapTiles_t *mapTiles, const Line &trLine, vec3_t hit, const int levelmask, const char **entlist)
 Checks traces against the world and all inline models, gives the hit position back. More...
 
trace_t CM_CompleteBoxTrace (mapTiles_t *mapTiles, const Line &trLine, const AABB &box, int levelmask, int brushmask, int brushreject)
 Traces all submodels in all tiles. Used by ufo and ufo_ded. More...
 
trace_t CM_EntCompleteBoxTrace (mapTiles_t *mapTiles, const Line &traceLine, const AABB *traceBox, int levelmask, int brushmask, int brushreject, const char **list)
 Performs box traces against the world and all inline models, gives the hit position back. More...
 

Detailed Description

model loading and grid oriented movement and scanning

Note
collision detection code (server side)

Definition in file cmodel.cpp.

Function Documentation

static void CM_CalculateWidestBoundingBox ( const cBspModel_t model,
AABB box 
)
static

Calculates the worst case bounding box for the given bsp model.

Parameters
[in]modelThe model to calculate the bbox for
[out]boxThe bbox to fill

Definition at line 41 of file cmodel.cpp.

References cBspModel_s::angles, cBspModel_s::cbmBox, AABB::expand(), f, AABB::getWidthX(), AABB::getWidthY(), AABB::getWidthZ(), cBspModel_s::origin, AABB::set(), AABB::shift(), and VectorNotEmpty.

Referenced by CM_EntCompleteBoxTrace(), and CM_LineMissesModel().

trace_t CM_CompleteBoxTrace ( mapTiles_t mapTiles,
const Line trLine,
const AABB box,
int  levelmask,
int  brushmask,
int  brushreject 
)

Traces all submodels in all tiles. Used by ufo and ufo_ded.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]trLineThe line to trace
[in]boxThe box we move through the world
[in]levelmaskSelects which submodels get scanned.
[in]brushmaskbrushes the trace should stop at (see MASK_*)
[in]brushrejectbrushes the trace should ignore (see MASK_*)

Definition at line 283 of file cmodel.cpp.

References AABB::doesIntersect(), trace_s::endpos, trace_s::fraction, MapTile::getTileBox(), trace_s::mapTile, mapTiles_s::mapTiles, mapTiles_s::numTiles, AABB::set(), Line::stop, tr, TR_TileBoxTrace(), and VectorCopy.

Referenced by CL_Trace(), CM_EntCompleteBoxTrace(), R_Trace(), SV_PointContents(), and SV_Trace().

trace_t CM_EntCompleteBoxTrace ( mapTiles_t mapTiles,
const Line traceLine,
const AABB traceBox,
int  levelmask,
int  brushmask,
int  brushreject,
const char **  list 
)

Performs box traces against the world and all inline models, gives the hit position back.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]traceLineThe start/stop position of the trace.
[in]traceBoxThe minimum/maximum extents of the collision box that is projected.
[in]levelmaskA mask of the game levels to trace against. Mask 0x100 filters clips.
[in]brushmaskAny brush detected must at least have one of these contents.
[in]brushrejectAny brush detected with any of these contents will be ignored.
[in]listThe local models list (a local model has a name starting with * followed by the model number)
Returns
a trace_t with the information of the closest brush intersected.
See also
CM_CompleteBoxTrace
CM_HintedTransformedBoxTrace

Definition at line 327 of file cmodel.cpp.

References cBspModel_s::angles, CM_CalculateWidestBoundingBox(), CM_CompleteBoxTrace(), CM_HintedTransformedBoxTrace(), CM_InlineModel(), Com_Error(), AABB::doesIntersect(), ERR_DROP, trace_s::fraction, AABB::getMaxZ(), AABB::getMinZ(), cBspModel_s::headnode, i, mapTiles_s::mapTiles, name, cBspModel_s::origin, PATHFINDING_HEIGHT, AABB::set(), cBspModel_s::shift, cBspModel_s::tile, TL_FLAG_ACTORCLIP, tr, and UNIT_HEIGHT.

bool CM_EntTestLine ( mapTiles_t mapTiles,
const Line traceLine,
const int  levelmask,
const char **  entlist 
)

Checks traces against the world and all inline models.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]traceLineThe start/stop positions of the trace.
[in]levelmask
[in]entlistThe local models list
See also
TR_TestLine
CM_InlineModel
CM_TransformedBoxTrace
Returns
true - hit something
false - hit nothing

Definition at line 184 of file cmodel.cpp.

References cBspModel_s::angles, CM_HintedTransformedBoxTrace(), CM_InlineModel(), CM_LineMissesModel(), Com_Error(), ERR_DROP, trace_s::fraction, cBspModel_s::headnode, mapTiles_s::mapTiles, MASK_VISIBILILITY, name, cBspModel_s::origin, cBspModel_s::shift, Line::start, trace_s::startsolid, Line::stop, cBspModel_s::tile, and TR_TestLine().

Referenced by SV_TestLineWithEnt().

bool CM_EntTestLineDM ( mapTiles_t mapTiles,
const Line trLine,
vec3_t  hit,
const int  levelmask,
const char **  entlist 
)

Checks traces against the world and all inline models, gives the hit position back.

Parameters
[in]mapTilesList of tiles the current (RMA-)map is composed of
[in]trLineThe start/stop positions of the trace.
[out]hitThe position where the line hits a object or the stop position if nothing is in the line
[in]levelmask
[in]entlistThe local models list
See also
TR_TestLineDM
CM_TransformedBoxTrace

Definition at line 230 of file cmodel.cpp.

References cBspModel_s::angles, CM_HintedTransformedBoxTrace(), CM_InlineModel(), CM_LineMissesModel(), Com_Error(), trace_s::endpos, ERR_DROP, trace_s::fraction, cBspModel_s::headnode, mapTiles_s::mapTiles, MASK_ALL, name, cBspModel_s::origin, Line::start, trace_s::startsolid, Line::stop, cBspModel_s::tile, TR_TestLineDM(), vec3_origin, and VectorCopy.

Referenced by CL_ActorMouseTrace(), and CL_GetWorldCoordsUnderMouse().

int32_t CM_HeadnodeForBox ( MapTile tile,
const AABB box 
)

To keep everything totally uniform, bounding boxes are turned into small BSP trees instead of being compared directly.

creates a clipping hull for an arbitrary box

Definition at line 151 of file cmodel.cpp.

References MapTile::box_headnode, MapTile::box_planes, cBspPlane_s::dist, MAX_MAP_NODES, AABB::maxs, and AABB::mins.

Referenced by CL_HullForEntity(), and SV_HullForEntity().

trace_t CM_HintedTransformedBoxTrace ( MapTile tile,
const Line traceLine,
const AABB traceBox,
const int  headnode,
const int  contentmask,
const int  brushrejects,
const vec3_t  origin,
const vec3_t  angles,
const vec3_t  rmaShift,
const float  fraction 
)

Handles offseting and rotation of the end points for moving and rotating entities.

Parameters
[in]tileTile to check (normally 0 - except in assembled maps)
[in]traceLineThe start and stop vectors of the trace
[in]traceBoxThe box we shove through the world
[in]headnodeif < 0 we are in a leaf node
[in]contentmaskcontent flags the trace should stop at (see MASK_*)
[in]brushrejectsbrushes the trace should ignore (see MASK_*)
[in]origincenter for rotating objects
[in]anglescurrent rotation status (in degrees) for rotating objects
[in]rmaShifthow much the object was shifted by the RMA process (needed for doors)
[in]fractionThe furthest distance needed to trace before we stop.
See also
CM_BoxTrace
Todo:
figure out how to do this with existing angles

Definition at line 84 of file cmodel.cpp.

References AngleVectors(), MapTile::box_headnode, DotProduct, trace_s::endpos, trace_s::fraction, MapTile::idx, boxtrace_s::init(), trace_s::mapTile, trace_s::plane, boxtrace_s::setLineAndBox(), Line::start, Line::stop, TR_BoxTrace(), VectorAdd, VectorCopy, VectorInterpolation, VectorNegate, VectorNotEmpty, and VectorSubtract.

Referenced by CL_ClipMoveToLEs(), CM_EntCompleteBoxTrace(), CM_EntTestLine(), CM_EntTestLineDM(), and SV_ClipMoveToEntities().

static bool CM_LineMissesModel ( const Line tLine,
const cBspModel_t model 
)
static

A quick test if the trace might hit the inline model.

Parameters
[in]tLineThe traceline
[in]modelThe entity to check
Returns
true - the line isn't anywhere near the model; false - we can't be sure

Definition at line 58 of file cmodel.cpp.

References AABB::canBeHitBy(), and CM_CalculateWidestBoundingBox().

Referenced by CM_EntTestLine(), and CM_EntTestLineDM().