middle[2] = (worldmins[2] + worldmaxs[2]) * 0.5f;
VectorAdd(start, middle, start2);
VectorAdd(end, middle, end2);
- frac = CL_TraceLine((float *)start2, (float *)end2, impactpos, impactnormal, 0, true);
+ frac = CL_TraceLine((float *)start2, (float *)end2, impactpos, impactnormal, 0, true, NULL);
VectorSubtract(impactpos, middle, impactpos);
*impactentnum = -1;
return frac;
chase_dest[1] = r_refdef.vieworg[1] + forward[1] * dist;
chase_dest[2] = r_refdef.vieworg[2] + forward[2] * dist + chase_up.value;
- CL_TraceLine (r_refdef.vieworg, chase_dest, stop, normal, 0, true);
+ CL_TraceLine (r_refdef.vieworg, chase_dest, stop, normal, 0, true, NULL);
chase_dest[0] = stop[0] + forward[0] * 8 + normal[0] * 4;
chase_dest[1] = stop[1] + forward[1] * 8 + normal[1] * 4;
chase_dest[2] = stop[2] + forward[2] * 8 + normal[2] * 4;
int cl_traceline_endcontents;
-float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels)
+float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels, entity_render_t **hitent)
{
double maxfrac;
trace_t trace;
+ if (hitent)
+ *hitent = NULL;
Mod_CheckLoaded(cl.worldmodel);
Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end);
VectorCopy (trace.plane.normal, normal);
cl_traceline_endcontents = trace.endcontents;
maxfrac = trace.fraction;
+ if (hitent && trace.fraction < 1)
+ *hitent = &cl_entities[0].render;
if (hitbmodels && cl_num_brushmodel_entities)
{
if (normal)
VectorCopy(trace.plane.normal, normal);
cl_traceline_endcontents = trace.endcontents;
+ if (hitent)
+ *hitent = ent;
}
}
}
// (leafs matching contents are considered empty, others are solid)
extern int cl_traceline_endcontents; // set by TraceLine
-float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels);
+float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels, entity_render_t **hitent);
#endif
v2[0] = v[0] * 18 + neworg[0];
v2[1] = v[1] * 18 + neworg[1];
v2[2] = v[2] * 18 + neworg[2] + 16;
- CL_TraceLine(neworg, v2, v, NULL, 0, true);
+ CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
ent->persistent.muzzleflash -= cl.frametime * 1000;
VectorCopy(p->org, org);
if (p->bounce)
{
- if (CL_TraceLine(p->oldorg, p->org, v, normal, 0, true) < 1)
+ if (CL_TraceLine(p->oldorg, p->org, v, normal, 0, true, NULL) < 1)
{
VectorCopy(v, p->org);
if (p->bounce < 0)
#include "quakedef.h"
+#include "cl_collision.h"
cvar_t r_quickmodels = {0, "r_quickmodels", "1"};
}
*/
-void R_AliasLerpVerts(int vertcount,
+void R_AliasLerpVerts(int vertcount, float *vertices, float *normals,
float lerp1, const trivertx_t *verts1, const vec3_t fscale1, const vec3_t translate1,
float lerp2, const trivertx_t *verts2, const vec3_t fscale2, const vec3_t translate2,
float lerp3, const trivertx_t *verts3, const vec3_t fscale3, const vec3_t translate3,
vec3_t scale1, scale2, scale3, scale4, translate;
const float *n1, *n2, *n3, *n4;
float *av, *avn;
- av = aliasvert;
- avn = aliasvertnorm;
+ av = vertices;
+ avn = normals;
VectorScale(fscale1, lerp1, scale1);
if (lerp2)
{
return &model->skinframes[model->skinscenes[s].firstframe];
}
-void R_SetupMDLMD2Frames(const entity_render_t *ent, float colorr, float colorg, float colorb)
+void R_LerpMDLMD2Vertices(const entity_render_t *ent, float *vertices, float *normals)
{
const md2frame_t *frame1, *frame2, *frame3, *frame4;
const trivertx_t *frame1verts, *frame2verts, *frame3verts, *frame4verts;
frame2verts = &model->mdlmd2data_pose[ent->frameblend[1].frame * model->numverts];
frame3verts = &model->mdlmd2data_pose[ent->frameblend[2].frame * model->numverts];
frame4verts = &model->mdlmd2data_pose[ent->frameblend[3].frame * model->numverts];
- R_AliasLerpVerts(model->numverts,
+ R_AliasLerpVerts(model->numverts, vertices, normals,
ent->frameblend[0].lerp, frame1verts, frame1->scale, frame1->translate,
ent->frameblend[1].lerp, frame2verts, frame2->scale, frame2->translate,
ent->frameblend[2].lerp, frame3verts, frame3->scale, frame3->translate,
ent->frameblend[3].lerp, frame4verts, frame4->scale, frame4->translate);
-
- R_LightModel(ent, model->numverts, colorr, colorg, colorb, false);
-
- //R_AliasTransformVerts(model->numverts);
}
void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
varray_texcoord[0][i] = model->mdlmd2data_texcoords[i] * 8.0f;
aliasvert = varray_vertex;
aliasvertcolor = varray_color;
- R_SetupMDLMD2Frames(ent, colorscale, colorscale, colorscale);
+ R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
+ R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
aliasvert = aliasvertbuf;
aliasvertcolor = aliasvertcolorbuf;
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
aliasvert = varray_vertex;
aliasvertcolor = varray_color;
- R_SetupMDLMD2Frames(ent, colorscale, colorscale, colorscale);
+ R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
+ R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
aliasvert = aliasvertbuf;
aliasvertcolor = aliasvertcolorbuf;
R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
return;
}
- R_SetupMDLMD2Frames(ent, 1 - fog, 1 - fog, 1 - fog);
+ R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
+ R_LightModel(ent, model->numverts, colorscale * (1 - fog), colorscale * (1 - fog), colorscale * (1 - fog), false);
if (colormapped)
{
}
}
+void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent)
+{
+ int i;
+ rmeshstate_t m;
+ model_t *model;
+ float *v, lightdirection[3], surfnormal[3], planenormal[3], planedist, floororigin[3], v2[3], offset[3], dist1, dist2, frac;
+
+ VectorCopy(ent->origin, v2);
+ v2[2] -= 65536.0f;
+ if (CL_TraceLine(ent->origin, v2, floororigin, surfnormal, 0, false, NULL) == 1)
+ return;
+
+ R_Mesh_Matrix(&ent->matrix);
+
+ model = ent->model;
+ R_Mesh_ResizeCheck(model->numverts);
+
+ memset(&m, 0, sizeof(m));
+ m.blendfunc1 = GL_SRC_ALPHA;
+ m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
+ R_Mesh_State(&m);
+
+ c_alias_polys += model->numtris;
+ R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+ R_FillColors(varray_color, model->numverts, 0, 0, 0, 0.5);
+
+ // put a light direction in the entity's coordinate space
+ lightdirection[0] = 0.3;
+ lightdirection[1] = 0.1;
+ lightdirection[2] = -1;
+ Matrix4x4_Transform3x3(&ent->inversematrix, lightdirection, offset);
+ VectorNormalizeFast(offset);
+ VectorScale(offset, 65536.0f, offset);
+
+ // put the plane's normal in the entity's coordinate space
+ Matrix4x4_Transform3x3(&ent->inversematrix, surfnormal, planenormal);
+ VectorNormalizeFast(planenormal);
+
+ // put the plane's distance in the entity's coordinate space
+ VectorSubtract(floororigin, ent->origin, floororigin);
+ planedist = DotProduct(floororigin, surfnormal) + 1;
+
+ //Con_Printf("sn: %f %f %f pn: %f %f %f pd: %f\n", surfnormal[0], surfnormal[1], surfnormal[2], planenormal[0], planenormal[1], planenormal[2], planedist);
+ {
+ //int count1 = 0, count2 = 0, count3 = 0;
+ for (i = 0, v = varray_vertex;i < model->numverts;i++, v += 4)
+ {
+ v2[0] = v[0] + offset[0];
+ v2[1] = v[1] + offset[1];
+ v2[2] = v[2] + offset[2];
+ dist1 = DotProduct(v, planenormal) - planedist;
+ dist2 = DotProduct(v2, planenormal) - planedist;
+ //if (dist1 > 0)
+ // count1++;
+ //if (dist2 > 0)
+ // count2++;
+ //if (dist1 > 0 != dist2 > 0)
+ // count3++;
+ if (dist1 > 0 && dist2 < 0)
+ //if (i & 1)
+ {
+ // clipped
+ frac = dist1 / (dist1 - dist2);
+ VectorMA(v, frac, offset, v);
+ }
+ }
+ //Con_Printf("counts %d %d %d\n", count1, count2, count3);
+ }
+ R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
+}
+
int ZymoticLerpBones(int count, const zymbonematrix *bonebase, const frameblend_t *blend, const zymbone_t *bone)
{
int i;
else
R_DrawQ1Q2AliasModelCallback(ent, 0);
}
-
cvar_t r_drawentities = {0, "r_drawentities","1"};
cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
+cvar_t r_shadows = {CVAR_SAVE, "r_shadows", "1"};
cvar_t r_speeds = {0, "r_speeds","0"};
cvar_t r_fullbright = {0, "r_fullbright","0"};
cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
Cvar_RegisterVariable (&r_drawentities);
Cvar_RegisterVariable (&r_drawviewmodel);
+ Cvar_RegisterVariable (&r_shadows);
Cvar_RegisterVariable (&r_speeds);
Cvar_RegisterVariable (&r_fullbrights);
Cvar_RegisterVariable (&r_wateralpha);
VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
}
- if (R_CullBox(ent->mins, ent->maxs))
- continue;
-
ent->visframe = r_framecount;
VectorCopy(ent->angles, v);
if (!ent->model || ent->model->type != mod_brush)
Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
R_LerpAnimation(ent);
R_UpdateEntLights(ent);
+ if (R_CullBox(ent->mins, ent->maxs))
+ continue;
R_FarClip_Box(ent->mins, ent->maxs);
}
}
}
}
+void R_DrawModelFakeShadows (void)
+{
+ int i;
+ entity_render_t *ent;
+
+ if (!r_drawentities.integer)
+ return;
+
+ for (i = 0;i < r_refdef.numentities;i++)
+ {
+ ent = r_refdef.entities[i];
+ if (ent->model && ent->model->DrawFakeShadow)
+ ent->model->DrawFakeShadow(ent);
+ }
+}
+
static void R_SetFrustum (void)
{
int i;
if (!intimerefresh && !r_speeds.integer)
S_ExtraUpdate ();
+ if (r_shadows.integer)
+ {
+ R_DrawModelFakeShadows();
+ R_TimeReport("fakeshadows");
+ }
+
R_DrawModels();
R_TimeReport("models");
out[3] = v[0] * in->m[3][0] + v[1] * in->m[3][1] + v[2] * in->m[3][2] + v[3] * in->m[3][3];
}
+void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[3])
+{
+ out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2];
+ out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2];
+ out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2];
+}
+
/*
void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3])
{
out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
}
+/*
void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3])
{
float t[3];
out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
}
+*/
+
+void Matrix3x4_Transform3x3 (const matrix3x4_t *in, const float v[3], float out[3])
+{
+ out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
+ out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
+ out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
+}
+
// FIXME: optimize
void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
// cases (rotation and translation *ONLY*), this attempts to undo the results
// of Transform
//void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3]);
+// transforms a direction vector through the rotation part of a matrix
+void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[3]);
// ease of use functions
// immediately applies a Translate to the matrix
// reverse transforms a 3D vector through a matrix3x4, at least for *simple*
// cases (rotation and translation *ONLY*), this attempts to undo the results
// of Transform
-void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3]);
+//void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3]);
+// transforms a direction vector through the rotation part of a matrix
+void Matrix3x4_Transform3x3 (const matrix3x4_t *in, const float v[3], float out[3]);
// ease of use functions
// immediately applies a Translate to the matrix
loadmodel->Draw = R_DrawQ1Q2AliasModel;
loadmodel->DrawSky = NULL;
- loadmodel->DrawShadow = NULL;
+ loadmodel->DrawFakeShadow = R_DrawQ1Q2AliasModelFakeShadow;
loadmodel->mdlmd2data_triangleneighbors = Mem_Alloc(loadmodel->mempool, loadmodel->numtris * sizeof(int[3]));
Mod_BuildTriangleNeighbors(loadmodel->mdlmd2data_triangleneighbors, loadmodel->mdlmd2data_indices, loadmodel->numtris);
loadmodel->aliastype = ALIASTYPE_MDLMD2;
loadmodel->Draw = R_DrawQ1Q2AliasModel;
loadmodel->DrawSky = NULL;
- loadmodel->DrawShadow = NULL;
+ loadmodel->DrawFakeShadow = NULL;
if (LittleLong(pinmodel->num_tris < 1) || LittleLong(pinmodel->num_tris) > MD2MAX_TRIANGLES)
Host_Error ("%s has invalid number of triangles: %i", loadmodel->name, LittleLong(pinmodel->num_tris));
loadmodel->Draw = R_DrawZymoticModel;
loadmodel->DrawSky = NULL;
- loadmodel->DrawShadow = NULL;
+ loadmodel->DrawFakeShadow = NULL;
}
mod->numleafs = bm->visleafs;
mod->Draw = R_DrawBrushModelNormal;
- mod->DrawShadow = NULL;
+ mod->DrawFakeShadow = NULL;
// LordHavoc: only register submodels if it is the world
// (prevents bsp models from replacing world submodels)
void(*Draw)(struct entity_render_s *ent);
// draw the model's sky polygons (only used by brush models)
void(*DrawSky)(struct entity_render_s *ent);
- // draw the model's shadows
- void(*DrawShadow)(struct entity_render_s *ent);
+ // draw a fake shadow for the model
+ void(*DrawFakeShadow)(struct entity_render_s *ent);
// memory pool for allocations
mempool_t *mempool;
loadmodel->Draw = R_DrawSpriteModel;
loadmodel->DrawSky = NULL;
- loadmodel->DrawShadow = NULL;
+ loadmodel->DrawFakeShadow = NULL;
version = LittleLong(((dsprite_t *)buffer)->version);
if (version == SPRITE_VERSION || SPRITE32_VERSION)
AngleVectors(cl.viewangles, v2, NULL, NULL);
//VectorCopy(r_origin, v1);
VectorMA(v1, 8192, v2, v2);
- spritescale = CL_TraceLine(v1, v2, spriteorigin, NULL, 0, true) * (8192.0f / 40.0f) * crosshair_size.value;
+ spritescale = CL_TraceLine(v1, v2, spriteorigin, NULL, 0, true, NULL) * (8192.0f / 40.0f) * crosshair_size.value;
// draw the sprite
R_DrawCrosshairSprite(pic->tex, spriteorigin, spritescale, color[0], color[1], color[2], color[3]);
VectorMA(e->vert[i], frametime, e->vertvel[i], end);
if (r_explosionclip.integer)
{
- if (CL_TraceLine(e->vert[i], end, impact, normal, 0, true) < 1)
+ if (CL_TraceLine(e->vert[i], end, impact, normal, 0, true, NULL) < 1)
{
// clip velocity against the wall
dot = DotProduct(e->vertvel[i], normal) * -1.125f;
{
rd = r_dlight + i;
dist = (DotProduct(rd->origin, vpn) - viewdist);
- if (dist >= 24.0f && CL_TraceLine(rd->origin, r_origin, NULL, NULL, 0, true) == 1)
+ if (dist >= 24.0f && CL_TraceLine(rd->origin, r_origin, NULL, NULL, 0, true, NULL) == 1)
{
scale = r_colorscale * (1.0f / 131072.0f);
if (gl_flashblend.integer)
{
VectorSubtract (p, sl->origin, v);
f = ((1.0f / (DotProduct(v, v) * sl->falloff + sl->distbias)) - sl->subtract);
- if (f > 0 && CL_TraceLine(p, sl->origin, NULL, NULL, 0, false) == 1)
+ if (f > 0 && CL_TraceLine(p, sl->origin, NULL, NULL, 0, false, NULL) == 1)
{
f *= d_lightstylevalue[sl->style] * (1.0f / 65536.0f);
VectorMA(color, f, sl->light, color);
rd = r_dlight + i;
VectorSubtract (p, rd->origin, v);
f = DotProduct(v, v);
- if (f < rd->cullradius2 && CL_TraceLine(p, rd->origin, NULL, NULL, 0, false) == 1)
+ if (f < rd->cullradius2 && CL_TraceLine(p, rd->origin, NULL, NULL, 0, false, NULL) == 1)
{
f = (1.0f / (f + LIGHTOFFSET)) - rd->subtract;
VectorMA(color, f, rd->light, color);
VectorSubtract (v, rd->origin, v);
if (DotProduct(v, v) < rd->cullradius2)
{
- if (CL_TraceLine(ent->origin, rd->origin, NULL, NULL, 0, false) != 1)
+ if (CL_TraceLine(ent->origin, rd->origin, NULL, NULL, 0, false, NULL) != 1)
continue;
VectorSubtract (ent->origin, rd->origin, v);
f = ((1.0f / (DotProduct(v, v) + LIGHTOFFSET)) - rd->subtract);
ent->numentlights = 0;
if (cl.worldmodel)
for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights && ent->numentlights < MAXENTLIGHTS;i++, sl++)
- if (CL_TraceLine(ent->origin, sl->origin, NULL, NULL, 0, false) == 1)
+ if (CL_TraceLine(ent->origin, sl->origin, NULL, NULL, 0, false, NULL) == 1)
ent->entlights[ent->numentlights++] = i;
}
ent->entlightsframe = r_framecount;
void R_DrawWorld(entity_render_t *ent);
void R_DrawParticles(void);
void R_DrawExplosions(void);
-void R_DrawBrushModelSky (entity_render_t *ent);
-void R_DrawBrushModelNormal (entity_render_t *ent);
-void R_DrawZymoticModel (entity_render_t *ent);
+void R_DrawBrushModelSky(entity_render_t *ent);
+void R_DrawBrushModelNormal(entity_render_t *ent);
+void R_DrawZymoticModel(entity_render_t *ent);
void R_DrawQ1Q2AliasModel(entity_render_t *ent);
-void R_DrawSpriteModel (entity_render_t *ent);
+void R_DrawQ1Q2AliasModelFakeShadow(entity_render_t *ent);
+void R_DrawSpriteModel(entity_render_t *ent);
// LordHavoc: vertex transform
#include "transform.h"