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

Mesh Model drawing code. More...

#include "r_local.h"
#include "r_lightmap.h"
#include "r_light.h"
#include "r_mesh.h"
#include "r_mesh_anim.h"
#include "r_error.h"
#include "r_draw.h"
#include "../battlescape/cl_particle.h"

Go to the source code of this file.

Macros

#define R_GetTagOrientByFrame(mod, tagIndex, frame)   &(((mod)->alias.tags)[tagIndex].orient[frame])
 

Functions

static void R_TransformModelDirect (modelInfo_t *mi)
 
static void R_DrawMeshModelShell (const mAliasMesh_t *mesh, const vec4_t color)
 Draws an animated, colored shell for the specified entity. Rather than re-lerping or re-scaling the entity, the currently bound vertex arrays are simply re-drawn using a small depth offset and varying texcoord delta. More...
 
static void R_DrawAliasFrameLerp (mAliasModel_t *mod, mAliasMesh_t *mesh, float backlerp, int framenum, int oldframenum, const vec4_t shellColor)
 Animated model render function. More...
 
static void R_DrawAliasStatic (const mAliasMesh_t *mesh, const vec4_t shellColor)
 Static model render function. More...
 
static void R_ResetArraysAfterStaticMeshRender (void)
 
static void R_DrawAliasStaticWithReset (const mAliasMesh_t *mesh, const vec4_t shellColor)
 
static void R_ComputeGLMatrixFromTag (float *glMatrix, const mAliasTagOrientation_t *orient)
 
void R_GetTags (const model_t *mod, const char *tagName, int currentFrame, int oldFrame, const mAliasTagOrientation_t **current, const mAliasTagOrientation_t **old)
 
bool R_GetTagMatrix (const model_t *mod, const char *tagName, int frame, float matrix[16])
 
void R_InterpolateTransform (float backLerp, int numframes, const mAliasTagOrientation_t *current, const mAliasTagOrientation_t *old, float *interpolated)
 Interpolate the transform for a model places on a tag of another model. More...
 
int R_GetTagIndexByName (const model_t *mod, const char *tagName)
 Searches the tag data for the given name. More...
 
void R_ModelAutoScale (const vec2_t boxSize, modelInfo_t *mi, vec3_t scale, vec3_t center)
 Compute scale and center for a model info data structure. More...
 
void R_DrawModelDirect (modelInfo_t *mi, modelInfo_t *pmi, const char *tagname)
 Draws a model in 2d mode (for rendering model data from the ui) More...
 
void R_DrawModelParticle (modelInfo_t *mi)
 Renders a particle model for the battlescape. More...
 
bool R_CullMeshModel (const entity_t *e)
 Checks whether a model is visible in the current scene. More...
 
static mAliasMesh_tR_GetLevelOfDetailForModel (const vec3_t origin, const mAliasModel_t *mod)
 Searches an appropriate level-of-detail mesh for the given model. More...
 
static void R_DrawAliasTags (const mAliasModel_t *mod)
 
static mAliasMesh_tR_DrawAliasModelBuffer (entity_t *e)
 
static bool R_UpdateShadowOrigin (entity_t *e)
 
static void R_RotateForMeshShadow (const entity_t *e)
 Applies translation, rotation and scale for the shadow of the specified entity. In order to reuse the vertex arrays from the primary rendering pass, the shadow origin must transformed into model-view space. More...
 
static void R_DrawMeshShadow (entity_t *e, const mAliasMesh_t *mesh)
 Re-draws the mesh using the stencil test. Meshes with stale lighting information, or with a lighting point above our view, are not drawn. More...
 
void R_DrawAliasModel (entity_t *e)
 Draw a model from the battlescape entity list. More...
 

Variables

static const float MESH_SHADOW_MAX_DISTANCE = 512.0
 
static const float MESH_SHADOW_ALPHA = 0.3
 

Detailed Description

Mesh Model drawing code.

Definition in file r_mesh.cpp.

Macro Definition Documentation

#define R_GetTagOrientByFrame (   mod,
  tagIndex,
  frame 
)    &(((mod)->alias.tags)[tagIndex].orient[frame])

Definition at line 166 of file r_mesh.cpp.

Referenced by R_GetTagMatrix(), and R_GetTags().

Function Documentation

static void R_ComputeGLMatrixFromTag ( float *  glMatrix,
const mAliasTagOrientation_t orient 
)
static
Note
Matrix format:
  • 0-11: rotation (forward, right, up)
  • 12-14: translation
  • 15:

Definition at line 143 of file r_mesh.cpp.

References mAliasTagOrientation_s::axis, and mAliasTagOrientation_s::origin.

Referenced by R_GetTagMatrix(), and R_InterpolateTransform().

bool R_CullMeshModel ( const entity_t e)

Checks whether a model is visible in the current scene.

Parameters
[in]eThe entity to check
Returns
false if visible, true if the entity is outside the current view

Definition at line 446 of file r_mesh.cpp.

References AngleVectors(), cBspPlane_s::dist, DotProduct, f, rlocals_s::frustum, i, lengthof, cBspPlane_s::normal, entity_t::origin, r_locals, VectorAdd, VectorCopy, and YAW.

Referenced by R_CullEntity().

static void R_DrawAliasFrameLerp ( mAliasModel_t mod,
mAliasMesh_t mesh,
float  backlerp,
int  framenum,
int  oldframenum,
const vec4_t  shellColor 
)
static
static void R_DrawAliasStaticWithReset ( const mAliasMesh_t mesh,
const vec4_t  shellColor 
)
static

Definition at line 131 of file r_mesh.cpp.

References R_DrawAliasStatic(), and R_ResetArraysAfterStaticMeshRender().

Referenced by R_DrawModelDirect(), and R_DrawModelParticle().

static void R_DrawMeshModelShell ( const mAliasMesh_t mesh,
const vec4_t  color 
)
static

Draws an animated, colored shell for the specified entity. Rather than re-lerping or re-scaling the entity, the currently bound vertex arrays are simply re-drawn using a small depth offset and varying texcoord delta.

Definition at line 61 of file r_mesh.cpp.

References rendererData_t::batchCount, mAliasMesh_s::num_tris, R_BindTexture, R_Color(), R_EnableShell(), r_envmaptextures, refdef, and VectorNotEmpty.

Referenced by R_DrawAliasFrameLerp(), and R_DrawAliasStatic().

static void R_DrawMeshShadow ( entity_t e,
const mAliasMesh_t mesh 
)
static
void R_DrawModelDirect ( modelInfo_t mi,
modelInfo_t pmi,
const char *  tagname 
)

Draws a model in 2d mode (for rendering model data from the ui)

Parameters
[in,out]miAll the needed model information to render the model
[in,out]pmiThe model information of the parent model. This is used in those cases, where the model that should get rendered here is placed relativly to an already existing model in the world.
[in]tagnameIf a parent model is given, a tagname is given in most cases, too. It's used to transform the model location relative to the parent model location again. E.g. a tagname of tag_rweapon will transform the location to the right hand of an actor.
See also
R_DrawAliasModel

Definition at line 306 of file r_mesh.cpp.

References model_s::alias, rendererData_t::aliasCount, modelInfo_t::backlerp, modelInfo_t::color, Com_Printf(), mAliasFrame_s::fBox, modelInfo_t::frame, mAliasModel_s::frames, cvar_s::integer, model_s::loaded, modelInfo_t::mesh, mAliasModel_s::meshes, modelInfo_t::model, modelInfo_t::name, mAliasModel_s::num_frames, mAliasMesh_s::num_tris, modelInfo_t::oldframe, Q_strnull(), R_AliasModelState(), R_BindTexture, R_CheckError, R_Color(), R_DrawAliasFrameLerp(), R_DrawAliasStaticWithReset(), R_DrawBoundingBox(), R_FindModel(), R_GetTags(), R_InterpolateTransform(), r_showbox, R_TransformModelDirect(), refdef, viddef_t::rx, viddef_t::ry, modelInfo_t::skin, image_s::texnum, vec4_origin, and viddef.

Referenced by R_Draw2DMapMarkers(), R_Draw3DMapMarkers(), UI_DrawItem(), UI_DrawModelNode(), and UI_DrawModelNodeWithUIModel().

static mAliasMesh_t* R_GetLevelOfDetailForModel ( const vec3_t  origin,
const mAliasModel_t mod 
)
static

Searches an appropriate level-of-detail mesh for the given model.

Parameters
originThe origin the model should be placed to in the world
modThe model where we are searching an appropriate level-of-detail mesh for
Returns
The mesh to render

Definition at line 526 of file r_mesh.cpp.

References length, mAliasModel_s::meshes, mAliasModel_s::num_meshes, RDF_NOWORLDMODEL, refdef, rendererData_t::rendererFlags, VectorLength(), VectorSubtract, and rendererData_t::viewOrigin.

Referenced by R_DrawAliasModelBuffer().

int R_GetTagIndexByName ( const model_t mod,
const char *  tagName 
)

Searches the tag data for the given name.

Parameters
[in]modThe model to search the tag data. Can be nullptr
[in]tagNameThe name of the tag to get the matrix for. Might not be nullptr
Returns
-1 if no tag with the given name was found

Definition at line 247 of file r_mesh.cpp.

References model_s::alias, i, mAliasTag_s::name, mAliasModel_s::num_tags, Q_streq, and mAliasModel_s::tags.

Referenced by CL_ActorGetMuzzle(), CL_AddActor(), R_GetTagMatrix(), and R_GetTags().

bool R_GetTagMatrix ( const model_t mod,
const char *  tagName,
int  frame,
float  matrix[16] 
)
Parameters
[in]modThe model to get the tag transformation matrix for
[in]tagNameThe name of the tag to get the transformation matrix for
[in]frameThe frame of the tag to get the transformation matrix for
[out]matrixThe transformation matrix
Returns
false if the tag name for the given model wasn't found, true if the matrix was filled.

Definition at line 189 of file r_mesh.cpp.

References Com_Printf(), index, model_s::name, R_ComputeGLMatrixFromTag(), R_GetTagIndexByName(), and R_GetTagOrientByFrame.

Referenced by CL_ActorGetMuzzle().

void R_GetTags ( const model_t mod,
const char *  tagName,
int  currentFrame,
int  oldFrame,
const mAliasTagOrientation_t **  current,
const mAliasTagOrientation_t **  old 
)
void R_InterpolateTransform ( float  backLerp,
int  numframes,
const mAliasTagOrientation_t current,
const mAliasTagOrientation_t old,
float *  interpolated 
)

Interpolate the transform for a model places on a tag of another model.

Parameters
[out]interpolatedThis is an array of 16 floats
[in]currentThe current frame tag data
[in]oldThe old frame tag data
[in]backLerpthe linear interpolation value [0.0,1.0]
[in]numframesThe max frames of the tag data

Definition at line 212 of file r_mesh.cpp.

References mAliasTagOrientation_s::axis, i, mAliasTagOrientation_s::origin, R_ComputeGLMatrixFromTag(), and VectorNormalizeFast().

Referenced by R_CalcTransform(), and R_DrawModelDirect().

void R_ModelAutoScale ( const vec2_t  boxSize,
modelInfo_t mi,
vec3_t  scale,
vec3_t  center 
)

Compute scale and center for a model info data structure.

Parameters
[in]boxSizeThe size the model should fit into
[in,out]miThe model info that contains the model that should be scaled
[out]scaleThe scale vector
[out]centerThe center of the model (center of the model's bounding box)
Note
The scale and center vectors are parameters here because the modelInfo_t struct only holds pointers to the vectors.
Todo:
Take the rotation info from modelInfo_t into account

Definition at line 278 of file r_mesh.cpp.

References modelInfo_t::center, AABB::getCenter(), AABB::getWidthX(), AABB::getWidthZ(), model_s::modBox, modelInfo_t::model, modelInfo_t::scale, scale, VectorNegate, and VectorSet.

Referenced by R_Draw2DMapMarkers(), R_Draw3DMapMarkers(), UI_DrawModelNode(), and UI_DrawModelNodeWithUIModel().

static void R_ResetArraysAfterStaticMeshRender ( void  )
static
static void R_RotateForMeshShadow ( const entity_t e)
static

Applies translation, rotation and scale for the shadow of the specified entity. In order to reuse the vertex arrays from the primary rendering pass, the shadow origin must transformed into model-view space.

Definition at line 641 of file r_mesh.cpp.

References PITCH, and R_TransformForEntity().

Referenced by R_DrawMeshShadow().

static void R_TransformModelDirect ( modelInfo_t mi)
static
static bool R_UpdateShadowOrigin ( entity_t e)
static

Variable Documentation

const float MESH_SHADOW_ALPHA = 0.3
static

Definition at line 38 of file r_mesh.cpp.

Referenced by R_DrawMeshShadow().

const float MESH_SHADOW_MAX_DISTANCE = 512.0
static

Definition at line 37 of file r_mesh.cpp.

Referenced by R_UpdateShadowOrigin().