3 // LordHavoc: disabled lerping
7 void R_ClipSpriteImage (vec3_t origin, vec3_t left, vec3_t up)
10 mspriteframe_t *frame;
12 float fleft, fright, fdown, fup;
13 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[0].frame;
16 fright = frame->right;
18 for (i = 1;i < 4 && currentrenderentity->frameblend[i].lerp;i++)
20 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[i].frame;
21 fleft = min(fleft , frame->left );
22 fdown = min(fdown , frame->down );
23 fright = max(fright, frame->right);
24 fup = max(fup , frame->up );
26 // FIXME: reverse these in loader to save time
29 points[0][0] = origin[0] + fdown * up[0] + fleft * left[0];points[0][1] = origin[1] + fdown * up[1] + fleft * left[1];points[0][2] = origin[2] + fdown * up[2] + fleft * left[2];
30 points[1][0] = origin[0] + fup * up[0] + fleft * left[0];points[1][1] = origin[1] + fup * up[1] + fleft * left[1];points[1][2] = origin[2] + fup * up[2] + fleft * left[2];
31 points[2][0] = origin[0] + fup * up[0] + fright * left[0];points[2][1] = origin[1] + fup * up[1] + fright * left[1];points[2][2] = origin[2] + fup * up[2] + fright * left[2];
32 points[3][0] = origin[0] + fdown * up[0] + fright * left[0];points[3][1] = origin[1] + fdown * up[1] + fright * left[1];points[3][2] = origin[2] + fdown * up[2] + fright * left[2];
33 R_Clip_AddPolygon(&points[0][0], 4, sizeof(float[3]), false, R_Entity_Callback, currentrenderentity, NULL, NULL);
36 void R_ClipSpriteImage (vec3_t origin, vec3_t left, vec3_t up)
39 mspriteframe_t *frame;
41 float fleft, fright, fdown, fup;
43 for (i = 0;i < 4 && currentrenderentity->frameblend[i].lerp;i++)
44 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[i].frame;
47 fright = frame->right;
49 // FIXME: reverse these in loader to save time
52 points[0][0] = origin[0] + fdown * up[0] + fleft * left[0];points[0][1] = origin[1] + fdown * up[1] + fleft * left[1];points[0][2] = origin[2] + fdown * up[2] + fleft * left[2];
53 points[1][0] = origin[0] + fup * up[0] + fleft * left[0];points[1][1] = origin[1] + fup * up[1] + fleft * left[1];points[1][2] = origin[2] + fup * up[2] + fleft * left[2];
54 points[2][0] = origin[0] + fup * up[0] + fright * left[0];points[2][1] = origin[1] + fup * up[1] + fright * left[1];points[2][2] = origin[2] + fup * up[2] + fright * left[2];
55 points[3][0] = origin[0] + fdown * up[0] + fright * left[0];points[3][1] = origin[1] + fdown * up[1] + fright * left[1];points[3][2] = origin[2] + fdown * up[2] + fright * left[2];
56 R_Clip_AddPolygon(&points[0][0], 4, sizeof(float[3]), false, R_Entity_Callback, currentrenderentity, NULL, NULL);
60 int R_SpriteSetup (int type, float org[3], float left[3], float up[3])
62 float matrix1[3][3], matrix2[3][3], matrix3[3][3];
64 VectorCopy(currentrenderentity->origin, org);
67 case SPR_VP_PARALLEL_UPRIGHT:
69 // vertical beam sprite, faces view plane
70 VectorNegate(vpn, matrix3[0]);
72 VectorNormalizeFast(matrix3[0]);
73 //VectorVectors(matrix3[0], matrix3[1], matrix3[2]);
74 //VectorNegate(matrix3[1], matrix3[1]);
75 matrix3[1][0] = matrix3[0][1];
76 matrix3[1][1] = -matrix3[0][0];
82 case SPR_FACING_UPRIGHT:
84 // vertical beam sprite, faces viewer's origin (not the view plane)
85 VectorSubtract(currentrenderentity->origin, r_origin, matrix3[0]);
87 VectorNormalizeFast(matrix3[0]);
88 //VectorVectors(matrix3[0], matrix3[1], matrix3[2]);
89 matrix3[1][0] = matrix3[0][1];
90 matrix3[1][1] = -matrix3[0][0];
97 Con_Printf("R_SpriteSetup: unknown sprite type %i\n", type);
98 // fall through to normal sprite
102 VectorCopy(vpn, matrix3[0]);
103 VectorNegate(vright, matrix3[1]);
104 VectorCopy(vup, matrix3[2]);
107 // bullet marks on walls
108 // ignores viewer entirely
109 AngleVectorsFLU (currentrenderentity->angles, matrix3[0], matrix3[1], matrix3[2]);
110 // nudge it toward the view, so it will be infront of the wall
111 VectorSubtract(org, vpn, org);
113 case SPR_VP_PARALLEL_ORIENTED:
114 // I have no idea what people would use this for
115 // oriented relative to view space
116 // FIXME: test this and make sure it mimicks software
117 AngleVectorsFLU (currentrenderentity->angles, matrix1[0], matrix1[1], matrix1[2]);
118 VectorCopy(vpn, matrix2[0]);
119 VectorNegate(vright, matrix2[1]);
120 VectorCopy(vup, matrix2[2]);
121 R_ConcatRotations (matrix1[0], matrix2[0], matrix3[0]);
125 // don't draw if view origin is behind it
126 //if (DotProduct(org, matrix3[0]) < (DotProduct(r_origin, matrix3[0]) - 1.0f))
129 if (currentrenderentity->scale != 1)
131 VectorScale(matrix3[1], currentrenderentity->scale, left);
132 VectorScale(matrix3[2], currentrenderentity->scale, up);
136 VectorCopy(matrix3[1], left);
137 VectorCopy(matrix3[2], up);
142 void R_ClipSprite (void)
144 vec3_t org, left, up;
146 if (currentrenderentity->frameblend[0].frame < 0)
149 if (R_SpriteSetup(currentrenderentity->model->sprnum_type, org, left, up))
152 // LordHavoc: interpolated sprite rendering
153 R_ClipSpriteImage(org, left, up);
156 int spritepolyindex[6] = {0, 1, 2, 0, 2, 3};
158 void GL_DrawSpriteImage (int fog, mspriteframe_t *frame, int texture, vec3_t origin, vec3_t up, vec3_t left, float red, float green, float blue, float alpha)
161 float v[4][4], st[4][2];
162 memset(&m, 0, sizeof(m));
163 m.transparent = true;
164 m.blendfunc1 = GL_SRC_ALPHA;
165 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
166 if ((currentrenderentity->effects & EF_ADDITIVE)
167 || (currentrenderentity->model->flags & EF_ADDITIVE)
169 m.blendfunc2 = GL_ONE;
171 m.index = spritepolyindex;
174 m.vertexstep = sizeof(float[4]);
180 m.texcoords[0] = &st[0][0];
181 m.texcoordstep[0] = sizeof(float[2]);
183 // FIXME: negate left and right in loader
184 v[0][0] = origin[0] + frame->down * up[0] - frame->left * left[0];
185 v[0][1] = origin[1] + frame->down * up[1] - frame->left * left[1];
186 v[0][2] = origin[2] + frame->down * up[2] - frame->left * left[2];
187 v[1][0] = origin[0] + frame->up * up[0] - frame->left * left[0];
188 v[1][1] = origin[1] + frame->up * up[1] - frame->left * left[1];
189 v[1][2] = origin[2] + frame->up * up[2] - frame->left * left[2];
190 v[2][0] = origin[0] + frame->up * up[0] - frame->right * left[0];
191 v[2][1] = origin[1] + frame->up * up[1] - frame->right * left[1];
192 v[2][2] = origin[2] + frame->up * up[2] - frame->right * left[2];
193 v[3][0] = origin[0] + frame->down * up[0] - frame->right * left[0];
194 v[3][1] = origin[1] + frame->down * up[1] - frame->right * left[1];
195 v[3][2] = origin[2] + frame->down * up[2] - frame->right * left[2];
213 void R_DrawSpriteModel ()
216 vec3_t left, up, org, color;
217 mspriteframe_t *frame;
221 if (currentrenderentity->frameblend[0].frame < 0)
224 if (R_SpriteSetup(currentrenderentity->model->sprnum_type, org, left, up))
229 if ((currentrenderentity->model->flags & EF_FULLBRIGHT) || (currentrenderentity->effects & EF_FULLBRIGHT))
230 color[0] = color[1] = color[2] = 1;
232 R_CompleteLightPoint(color, currentrenderentity->origin, true, NULL);
236 VectorSubtract(currentrenderentity->origin, r_origin, diff);
237 fog = exp(fogdensity/DotProduct(diff,diff));
246 // LordHavoc: interpolated sprite rendering
247 for (i = 0;i < 4;i++)
249 if (currentrenderentity->frameblend[i].lerp >= 0.01f)
251 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[i].frame;
252 GL_DrawSpriteImage(false, frame, R_GetTexture(frame->texture), org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, currentrenderentity->alpha * currentrenderentity->frameblend[i].lerp);
253 if (fog * currentrenderentity->frameblend[i].lerp >= 0.01f)
254 GL_DrawSpriteImage(true, frame, R_GetTexture(frame->fogtexture), org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * currentrenderentity->alpha * currentrenderentity->frameblend[i].lerp);
258 // LordHavoc: no interpolation
260 for (i = 0;i < 4 && currentrenderentity->frameblend[i].lerp;i++)
261 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[i].frame;
263 GL_DrawSpriteImage(false, frame, R_GetTexture(frame->texture), org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, currentrenderentity->alpha);
264 if (fog * currentrenderentity->frameblend[i].lerp >= 0.01f)
265 GL_DrawSpriteImage(true, frame, R_GetTexture(frame->fogtexture), org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * currentrenderentity->alpha);