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 matrix3[1][0] = matrix3[0][1];
74 matrix3[1][1] = -matrix3[0][0];
80 case SPR_FACING_UPRIGHT:
82 // vertical beam sprite, faces viewer's origin (not the view plane)
83 VectorSubtract(currentrenderentity->origin, r_origin, matrix3[0]);
85 VectorNormalizeFast(matrix3[0]);
86 matrix3[1][0] = matrix3[0][1];
87 matrix3[1][1] = -matrix3[0][0];
94 Con_Printf("R_SpriteSetup: unknown sprite type %i\n", type);
95 // fall through to normal sprite
99 VectorCopy(vpn, matrix3[0]);
100 VectorNegate(vright, matrix3[1]);
101 VectorCopy(vup, matrix3[2]);
104 // bullet marks on walls
105 // ignores viewer entirely
106 AngleVectorsFLU (currentrenderentity->angles, matrix3[0], matrix3[1], matrix3[2]);
107 // nudge it toward the view, so it will be infront of the wall
108 VectorSubtract(org, vpn, org);
110 case SPR_VP_PARALLEL_ORIENTED:
111 // I have no idea what people would use this for
112 // oriented relative to view space
113 // FIXME: test this and make sure it mimicks software
114 AngleVectorsFLU (currentrenderentity->angles, matrix1[0], matrix1[1], matrix1[2]);
115 VectorCopy(vpn, matrix2[0]);
116 VectorNegate(vright, matrix2[1]);
117 VectorCopy(vup, matrix2[2]);
118 R_ConcatRotations (matrix1[0], matrix2[0], matrix3[0]);
122 if (currentrenderentity->scale != 1)
124 VectorScale(matrix3[1], currentrenderentity->scale, left);
125 VectorScale(matrix3[2], currentrenderentity->scale, up);
129 VectorCopy(matrix3[1], left);
130 VectorCopy(matrix3[2], up);
135 void R_ClipSprite (void)
137 vec3_t org, left, up;
139 if (currentrenderentity->frameblend[0].frame < 0)
142 if (R_SpriteSetup(currentrenderentity->model->sprnum_type, org, left, up))
145 // LordHavoc: interpolated sprite rendering
146 R_ClipSpriteImage(org, left, up);
149 int spritepolyindex[6] = {0, 1, 2, 0, 2, 3};
151 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)
154 float v[4][4], st[4][2];
155 memset(&m, 0, sizeof(m));
156 m.transparent = true;
157 m.blendfunc1 = GL_SRC_ALPHA;
158 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
159 if ((currentrenderentity->effects & EF_ADDITIVE)
160 || (currentrenderentity->model->flags & EF_ADDITIVE)
162 m.blendfunc2 = GL_ONE;
164 m.index = spritepolyindex;
167 m.vertexstep = sizeof(float[4]);
173 m.texcoords[0] = &st[0][0];
174 m.texcoordstep[0] = sizeof(float[2]);
176 // FIXME: negate left and right in loader
177 v[0][0] = origin[0] + frame->down * up[0] - frame->left * left[0];
178 v[0][1] = origin[1] + frame->down * up[1] - frame->left * left[1];
179 v[0][2] = origin[2] + frame->down * up[2] - frame->left * left[2];
180 v[1][0] = origin[0] + frame->up * up[0] - frame->left * left[0];
181 v[1][1] = origin[1] + frame->up * up[1] - frame->left * left[1];
182 v[1][2] = origin[2] + frame->up * up[2] - frame->left * left[2];
183 v[2][0] = origin[0] + frame->up * up[0] - frame->right * left[0];
184 v[2][1] = origin[1] + frame->up * up[1] - frame->right * left[1];
185 v[2][2] = origin[2] + frame->up * up[2] - frame->right * left[2];
186 v[3][0] = origin[0] + frame->down * up[0] - frame->right * left[0];
187 v[3][1] = origin[1] + frame->down * up[1] - frame->right * left[1];
188 v[3][2] = origin[2] + frame->down * up[2] - frame->right * left[2];
206 void R_DrawSpriteModel ()
209 vec3_t left, up, org, color;
210 mspriteframe_t *frame;
214 if (currentrenderentity->frameblend[0].frame < 0)
217 if (R_SpriteSetup(currentrenderentity->model->sprnum_type, org, left, up))
222 if ((currentrenderentity->model->flags & EF_FULLBRIGHT) || (currentrenderentity->effects & EF_FULLBRIGHT))
223 color[0] = color[1] = color[2] = 1;
225 R_CompleteLightPoint(color, currentrenderentity->origin, true, NULL);
229 VectorSubtract(currentrenderentity->origin, r_origin, diff);
230 fog = exp(fogdensity/DotProduct(diff,diff));
239 // LordHavoc: interpolated sprite rendering
240 for (i = 0;i < 4;i++)
242 if (currentrenderentity->frameblend[i].lerp >= 0.01f)
244 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[i].frame;
245 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);
246 if (fog * currentrenderentity->frameblend[i].lerp >= 0.01f)
247 GL_DrawSpriteImage(true, frame, R_GetTexture(frame->fogtexture), org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * currentrenderentity->alpha * currentrenderentity->frameblend[i].lerp);
251 // LordHavoc: no interpolation
253 for (i = 0;i < 4 && currentrenderentity->frameblend[i].lerp;i++)
254 frame = currentrenderentity->model->sprdata_frames + currentrenderentity->frameblend[i].frame;
256 GL_DrawSpriteImage(false, frame, R_GetTexture(frame->texture), org, up, left, color[0] * ifog, color[1] * ifog, color[2] * ifog, currentrenderentity->alpha);
257 if (fog * currentrenderentity->frameblend[i].lerp >= 0.01f)
258 GL_DrawSpriteImage(true, frame, R_GetTexture(frame->fogtexture), org, up, left, fogcolor[0],fogcolor[1],fogcolor[2], fog * currentrenderentity->alpha);