entity_t *ent = &cl_entities[0];
cl_brushmodel_entities[cl_num_brushmodel_entities++] = 0;
// FIXME: this should be done at load
- Matrix4x4_CreateIdentity(&ent->render.matrix);
- Matrix4x4_CreateIdentity(&ent->render.inversematrix);
+ ent->render.matrix = identitymatrix;
+ ent->render.inversematrix = identitymatrix;
R_LerpAnimation(&ent->render);
CL_BoundingBoxForEntity(&ent->render);
ent->render.flags = RENDER_SHADOW;
return;
// cl_brushmodel_entities[cl_num_brushmodel_entities++] = 0;
// FIXME: this should be done at load
- Matrix4x4_CreateIdentity(&ent->render.matrix);
- Matrix4x4_CreateIdentity(&ent->render.inversematrix);
+ ent->render.matrix = identitymatrix;
+ ent->render.inversematrix = identitymatrix;
R_LerpAnimation(&ent->render);
CL_BoundingBoxForEntity(&ent->render);
ent->render.flags = RENDER_SHADOW;
r_refdef.time = cl.time;
r_refdef.extraupdate = !r_speeds.integer;
r_refdef.numentities = 0;
- Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
+ r_refdef.viewentitymatrix = identitymatrix;
cl_num_brushmodel_entities = 0;
if (cls.state == ca_connected && cls.signon == SIGNONS)
}
}
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
memset(&m, 0, sizeof(m));
m.tex[0] = R_GetTexture(tex->texture);
static void CSQC_R_RecalcView (void)
{
extern matrix4x4_t viewmodelmatrix;
- Matrix4x4_CreateIdentity(&viewmodelmatrix);
- Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
+ viewmodelmatrix = identitymatrix;
+ r_refdef.viewentitymatrix = identitymatrix;
Matrix4x4_CreateFromQuakeEntity(&r_refdef.viewentitymatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 1);
Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 0.3);
}
prvm_edict_t *attachent;
model_t *model;
- Matrix4x4_CreateIdentity(out); // warnings and errors return identical matrix
+ out = identitymatrix; // warnings and errors return identical matrix
if (ent == prog->edicts)
return 1;
return ret;
}
else
- Matrix4x4_CreateIdentity(&tagmatrix);
+ tagmatrix = identitymatrix;
if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict)
{ // DP_GFX_QUAKE3MODELTAGS, scan all chain and stop on unattached entity
if (model && val->_float >= 1 && model->animscenes && attachent->fields.client->frame >= 0 && attachent->fields.client->frame < model->numframes)
Mod_Alias_GetTagMatrix(model, model->animscenes[(int)attachent->fields.client->frame].firstframe, val->_float - 1, &attachmatrix);
else
- Matrix4x4_CreateIdentity(&attachmatrix);
+ attachmatrix = identitymatrix;
// apply transformation by child entity matrix
val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
void Collision_ClipTrace_BrushBox(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask)
{
colbrushf_t *boxbrush, *thisbrush_start, *thisbrush_end;
- matrix4x4_t identitymatrix;
vec3_t startmins, startmaxs, endmins, endmaxs;
// create brushes for the collision
VectorAdd(start, maxs, startmaxs);
VectorAdd(end, mins, endmins);
VectorAdd(end, maxs, endmaxs);
- Matrix4x4_CreateIdentity(&identitymatrix);
boxbrush = Collision_BrushForBox(&identitymatrix, cmins, cmaxs);
thisbrush_start = Collision_BrushForBox(&identitymatrix, startmins, startmaxs);
thisbrush_end = Collision_BrushForBox(&identitymatrix, endmins, endmaxs);
void GL_SetupView_Orientation_Identity (void)
{
- Matrix4x4_CreateIdentity(&backend_viewmatrix);
+ backend_viewmatrix = identitymatrix;
memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
}
unit->combinergb = GL_MODULATE;
unit->combinealpha = GL_MODULATE;
unit->texmatrixenabled = false;
- unit->matrix = r_identitymatrix;
+ unit->matrix = identitymatrix;
}
for (i = 0;i < backendimageunits;i++)
R_Textures_Frame();
GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
R_Mesh_Start();
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
// draw the loading plaque
pic = Draw_CachePic("gfx/loading", false);
x = (vid_conwidth.integer - pic->width)/2;
qglViewport(r_view_x, vid.height - (r_view_y + r_view_height), r_view_width, r_view_height);
GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
qglDepthFunc(GL_LEQUAL);
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
chartexnum = R_GetTexture(char_texture);
mplane_t frustum[5];
-matrix4x4_t r_identitymatrix;
+matrix4x4_t identitymatrix;
renderstats_t renderstats;
void GL_Main_Init(void)
{
- Matrix4x4_CreateIdentity(&r_identitymatrix);
// FIXME: move this to client?
FOG_registercvars();
Cvar_RegisterVariable(&r_showtris);
GL_SetupView_Mode_Ortho(0, 0, 1, 1, -10, 100);
GL_DepthMask(true);
GL_DepthTest(false);
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
// vertex coordinates for a quad that covers the screen exactly
varray_vertex3f[0] = 0;varray_vertex3f[1] = 0;varray_vertex3f[2] = 0;
varray_vertex3f[3] = 1;varray_vertex3f[4] = 0;varray_vertex3f[5] = 0;
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL_DepthMask(false);
GL_DepthTest(true);
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
vertex3f[ 0] = mins[0];vertex3f[ 1] = mins[1];vertex3f[ 2] = mins[2];
vertex3f[ 3] = maxs[0];vertex3f[ 4] = mins[1];vertex3f[ 5] = mins[2];
fog = VERTEXFOGTABLE(VectorDistance(origin, r_vieworigin));
ifog = 1 - fog;
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
GL_BlendFunc(blendfunc1, blendfunc2);
GL_DepthMask(false);
GL_DepthTest(!depthdisable);
if (t->currentmaterialflags & MATERIALFLAG_WATER && r_waterscroll.value != 0)
t->currenttexmatrix = r_waterscrollmatrix;
else
- t->currenttexmatrix = r_identitymatrix;
+ t->currenttexmatrix = identitymatrix;
t->currentnumlayers = 0;
if (!(t->currentmaterialflags & MATERIALFLAG_NODRAW))
{
if (gl_lightmaps.integer)
- R_Texture_AddLayer(t, true, GL_ONE, GL_ZERO, TEXTURELAYERTYPE_LITTEXTURE_MULTIPASS, r_texture_white, &r_identitymatrix, 1, 1, 1, 1);
+ R_Texture_AddLayer(t, true, GL_ONE, GL_ZERO, TEXTURELAYERTYPE_LITTEXTURE_MULTIPASS, r_texture_white, &identitymatrix, 1, 1, 1, 1);
else if (t->currentmaterialflags & MATERIALFLAG_SKY)
{
// transparent sky would be ridiculous
if (!(t->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
- R_Texture_AddLayer(t, true, GL_ONE, GL_ZERO, TEXTURELAYERTYPE_SKY, r_texture_white, &r_identitymatrix, fogcolor[0], fogcolor[1], fogcolor[2], 1);
+ R_Texture_AddLayer(t, true, GL_ONE, GL_ZERO, TEXTURELAYERTYPE_SKY, r_texture_white, &identitymatrix, fogcolor[0], fogcolor[1], fogcolor[2], 1);
}
else
{
// were darkened by fog already, and we should not add fog color
// (because the background was not darkened, there is no fog color
// that was lost behind it).
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, (t->currentmaterialflags & MATERIALFLAG_TRANSPARENT) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA, TEXTURELAYERTYPE_FOG, t->skin.fog, &r_identitymatrix, fogcolor[0], fogcolor[1], fogcolor[2], t->currentalpha);
+ R_Texture_AddLayer(t, false, GL_SRC_ALPHA, (t->currentmaterialflags & MATERIALFLAG_TRANSPARENT) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA, TEXTURELAYERTYPE_FOG, t->skin.fog, &identitymatrix, fogcolor[0], fogcolor[1], fogcolor[2], t->currentalpha);
}
}
}
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL_DepthMask(false);
GL_DepthTest(true);
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
memset(&m, 0, sizeof(m));
m.pointer_vertex = varray_vertex3f;
{
const float *boneframe;
float tempbonematrix[12], bonematrix[12];
- Matrix4x4_CreateIdentity(outmatrix);
+ *outmatrix = identitymatrix;
if (model->num_bones)
{
if (tagindex < 0 || tagindex >= model->num_bones)
if (!linetrace)
{
// box trace, performed as brush trace
- Matrix4x4_CreateIdentity(&startmatrix);
- Matrix4x4_CreateIdentity(&endmatrix);
+ startmatrix = identitymatrix;
+ endmatrix = identitymatrix;
thisbrush_start = Collision_BrushForBox(&startmatrix, boxstartmins, boxstartmaxs);
thisbrush_end = Collision_BrushForBox(&endmatrix, boxendmins, boxendmaxs);
}
for (i = 0, pintag = (md3tag_t *)((unsigned char *)pinmodel + LittleLong(pinmodel->lump_tags));i < loadmodel->num_tagframes * loadmodel->num_tags;i++, pintag++)
{
strcpy(loadmodel->data_tags[i].name, pintag->name);
- Matrix4x4_CreateIdentity(&loadmodel->data_tags[i].matrix);
+ loadmodel->data_tags[i].matrix = identitymatrix;
for (j = 0;j < 3;j++)
{
for (k = 0;k < 3;k++)
mesh->data_vertexboneweights[mesh->num_vertexboneweights].vertexindex = index;
mesh->data_vertexboneweights[mesh->num_vertexboneweights].boneindex = rawweights[j].boneindex;
mesh->data_vertexboneweights[mesh->num_vertexboneweights].weight = rawweights[j].weight;
- Matrix4x4_CreateIdentity(&matrix);
+ matrix = identitymatrix;
for (i = rawweights[j].boneindex;i >= 0;i = loadmodel->data_bones[i].parent)
{
matrix4x4_t childmatrix, tempmatrix;
trace->fraction = 1;
trace->realfraction = 1;
trace->hitsupercontentsmask = hitsupercontentsmask;
- Matrix4x4_CreateIdentity(&startmatrix);
- Matrix4x4_CreateIdentity(&endmatrix);
+ startmatrix = identitymatrix;
+ endmatrix = identitymatrix;
segmentmins[0] = min(boxstartmins[0], boxendmins[0]);
segmentmins[1] = min(boxstartmins[1], boxendmins[1]);
segmentmins[2] = min(boxstartmins[2], boxendmins[2]);
{
int i, tnum;
float sdir[3], tdir[3], normal[3], *v;
+ const float *v0, *v1, *v2, *tc0, *tc1, *tc2;
+ float f, tangentcross[3], v10[3], v20[3], tc10[2], tc20[2];
const int *e;
// clear the vectors
if (svector3f)
// process each vertex of each triangle and accumulate the results
for (tnum = 0, e = elements;tnum < numtriangles;tnum++, e += 3)
{
- Mod_BuildBumpVectors(vertex3f + e[0] * 3, vertex3f + e[1] * 3, vertex3f + e[2] * 3, texcoord2f + e[0] * 2, texcoord2f + e[1] * 2, texcoord2f + e[2] * 2, sdir, tdir, normal);
+ v0 = vertex3f + e[0] * 3;
+ v1 = vertex3f + e[1] * 3;
+ v2 = vertex3f + e[2] * 3;
+ tc0 = texcoord2f + e[0] * 2;
+ tc1 = texcoord2f + e[1] * 2;
+ tc2 = texcoord2f + e[2] * 2;
+
+ // 79 add/sub/negate/multiply (1 cycle), 1 compare (3 cycle?), total cycles not counting load/store/exchange roughly 82 cycles
+ // 6 add, 28 subtract, 39 multiply, 1 compare, 50% chance of 6 negates
+
+ // calculate the edge directions and surface normal
+ // 6 multiply, 9 subtract
+ VectorSubtract(v1, v0, v10);
+ VectorSubtract(v2, v0, v20);
+ normal[0] = v20[1] * v10[2] - v20[2] * v10[1];
+ normal[1] = v20[2] * v10[0] - v20[0] * v10[2];
+ normal[2] = v20[0] * v10[1] - v20[1] * v10[0];
+
+ // calculate the tangents
+ // 12 multiply, 10 subtract
+ tc10[1] = tc1[1] - tc0[1];
+ tc20[1] = tc2[1] - tc0[1];
+ sdir[0] = tc10[1] * v20[0] - tc20[1] * v10[0];
+ sdir[1] = tc10[1] * v20[1] - tc20[1] * v10[1];
+ sdir[2] = tc10[1] * v20[2] - tc20[1] * v10[2];
+ tc10[0] = tc1[0] - tc0[0];
+ tc20[0] = tc2[0] - tc0[0];
+ tdir[0] = tc10[0] * v20[0] - tc20[0] * v10[0];
+ tdir[1] = tc10[0] * v20[1] - tc20[0] * v10[1];
+ tdir[2] = tc10[0] * v20[2] - tc20[0] * v10[2];
+
+ // make the tangents completely perpendicular to the surface normal
+ // 12 multiply, 4 add, 6 subtract
+ f = DotProduct(sdir, normal);
+ sdir[0] -= f * normal[0];
+ sdir[1] -= f * normal[1];
+ sdir[2] -= f * normal[2];
+ f = DotProduct(tdir, normal);
+ tdir[0] -= f * normal[0];
+ tdir[1] -= f * normal[1];
+ tdir[2] -= f * normal[2];
+
+ // if texture is mapped the wrong way (counterclockwise), the tangents
+ // have to be flipped, this is detected by calculating a normal from the
+ // two tangents, and seeing if it is opposite the surface normal
+ // 9 multiply, 2 add, 3 subtract, 1 compare, 50% chance of: 6 negates
+ CrossProduct(tdir, sdir, tangentcross);
+ if (DotProduct(tangentcross, normal) < 0)
+ {
+ VectorNegate(sdir, sdir);
+ VectorNegate(tdir, tdir);
+ }
+
if (!areaweighting)
{
VectorNormalize(sdir);
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
GL_DepthMask(false);
GL_DepthTest(true);
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
numtriangles = EXPLOSIONTRIS;
numverts = EXPLOSIONVERTS;
dlight_t *light;
if (r_coronas.value < 0.01)
return;
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
viewdist = DotProduct(r_vieworigin, r_viewforward);
flag = r_rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
for (lnum = 0, light = r_shadow_worldlightchain;light;light = light->next, lnum++)
vec3_t beamdir, right, up, offset;
float length, t1, t2;
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
// calculate beam direction (beamdir) vector and beam length
// get difference vector
break;
}
- R_Mesh_Matrix(&r_identitymatrix);
+ R_Mesh_Matrix(&identitymatrix);
if (!(ent->flags & RENDER_LIGHT))
color[0] = color[1] = color[2] = 1;
// TODO: dynamic resize according to r_refdef.worldmodel->num_surfaces
extern unsigned char r_worldsurfacevisible[262144];
-extern matrix4x4_t r_identitymatrix;
-
// 1.0f / N table
extern float ixtable[4096];
frame = 0;
return Mod_Alias_GetTagMatrix(model, model->animscenes[frame].firstframe, tagindex, out);
}
- Matrix4x4_CreateIdentity(out);
+ *out = identitymatrix;
return 0;
}
matrix4x4_t entitymatrix, tagmatrix, attachmatrix;
model_t *model;
- Matrix4x4_CreateIdentity(out); // warnings and errors return identical matrix
+ *out = identitymatrix; // warnings and errors return identical matrix
if (ent == prog->edicts)
return 1;
model = sv.models[modelindex];
- Matrix4x4_CreateIdentity(&tagmatrix);
+ tagmatrix = identitymatrix;
// DP_GFX_QUAKE3MODELTAGS, scan all chain and stop on unattached entity
attachloop = 0;
for (;;)
if(csqc_loaded)
return;
VectorClear(gunorg);
- Matrix4x4_CreateIdentity(&viewmodelmatrix);
- Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
+ viewmodelmatrix = identitymatrix;
+ r_refdef.viewentitymatrix = identitymatrix;
if (cls.state == ca_connected && cls.signon == SIGNONS)
{
// ent is the view entity (visible when out of body)