vkQuake2 doxygen  1.0 dev
r_sprite.c File Reference
#include "r_local.h"

Go to the source code of this file.

Functions

void R_BuildPolygonFromSurface (msurface_t *fa)
 
void R_PolygonCalculateGradients (void)
 
void R_PolyChooseSpanletRoutine (float alpha, qboolean isturbulent)
 
void R_ClipAndDrawPoly (float alpha, qboolean isturbulent, qboolean textured)
 
void R_DrawSprite (void)
 

Variables

polydesc_t r_polydesc
 
vec5_t r_clip_verts [2][MAXWORKINGVERTS+2]
 

Function Documentation

◆ R_BuildPolygonFromSurface()

void R_BuildPolygonFromSurface ( msurface_t fa)

Definition at line 1160 of file r_poly.c.

1161 {
1162  int i, lindex, lnumverts;
1163  medge_t *pedges, *r_pedge;
1164  int vertpage;
1165  float *vec;
1166  vec5_t *pverts;
1167  float tmins[2] = { 0, 0 };
1168 
1169  r_polydesc.nump = 0;
1170 
1171  // reconstruct the polygon
1172  pedges = currentmodel->edges;
1173  lnumverts = fa->numedges;
1174  vertpage = 0;
1175 
1176  pverts = r_clip_verts[0];
1177 
1178  for (i = 0; i<lnumverts; i++)
1179  {
1180  lindex = currentmodel->surfedges[fa->firstedge + i];
1181 
1182  if (lindex > 0)
1183  {
1184  r_pedge = &pedges[lindex];
1185  vec = currentmodel->vertexes[r_pedge->v[0]].position;
1186  }
1187  else
1188  {
1189  r_pedge = &pedges[-lindex];
1190  vec = currentmodel->vertexes[r_pedge->v[1]].position;
1191  }
1192 
1193  VectorCopy(vec, pverts[i]);
1194  }
1195 
1197  VectorCopy(fa->texinfo->vecs[1], r_polydesc.vup);
1200 
1201  if (fa->flags & SURF_PLANEBACK)
1202  {
1204  }
1205 
1206  // PGM 09/16/98
1207  if (fa->texinfo->flags & (SURF_WARP | SURF_FLOWING))
1208  {
1209  r_polydesc.pixels = fa->texinfo->image->pixels[0];
1212  }
1213  // PGM 09/16/98
1214  else
1215  {
1216  surfcache_t *scache;
1217 
1218  scache = D_CacheSurface(fa, 0);
1219 
1220  r_polydesc.pixels = scache->data;
1221  r_polydesc.pixel_width = scache->width;
1222  r_polydesc.pixel_height = scache->height;
1223 
1224  tmins[0] = fa->texturemins[0];
1225  tmins[1] = fa->texturemins[1];
1226  }
1227 
1228  r_polydesc.dist = DotProduct(r_polydesc.vpn, pverts[0]);
1229 
1230  r_polydesc.s_offset = fa->texinfo->vecs[0][3] - tmins[0];
1231  r_polydesc.t_offset = fa->texinfo->vecs[1][3] - tmins[1];
1232 
1233  // scrolling texture addition
1234  if (fa->texinfo->flags & SURF_FLOWING)
1235  {
1236  r_polydesc.s_offset += -128 * ((r_newrefdef.time*0.25) - (int)(r_newrefdef.time*0.25));
1237  }
1238 
1239  r_polydesc.nump = lnumverts;
1240 }

Referenced by R_DrawAlphaSurfaces().

◆ R_ClipAndDrawPoly()

void R_ClipAndDrawPoly ( float  alpha,
qboolean  isturbulent,
qboolean  textured 
)

Referenced by R_DrawSprite().

◆ R_DrawSprite()

void R_DrawSprite ( void  )

Definition at line 40 of file r_sprite.c.

41 {
42  vec5_t *pverts;
43  vec3_t left, up, right, down;
44  dsprite_t *s_psprite;
45  dsprframe_t *s_psprframe;
46 
47 
48  s_psprite = (dsprite_t *)currentmodel->extradata;
49 #if 0
50  if (currententity->frame >= s_psprite->numframes
51  || currententity->frame < 0)
52  {
53  ri.Con_Printf (PRINT_ALL, "No such sprite frame %i\n",
55  currententity->frame = 0;
56  }
57 #endif
58  currententity->frame %= s_psprite->numframes;
59 
60  s_psprframe = &s_psprite->frames[currententity->frame];
61 
63  r_polydesc.pixel_width = s_psprframe->width;
64  r_polydesc.pixel_height = s_psprframe->height;
65  r_polydesc.dist = 0;
66 
67  // generate the sprite's axes, completely parallel to the viewplane.
71 
72 // build the sprite poster in worldspace
74  s_psprframe->width - s_psprframe->origin_x, right);
76  s_psprframe->height - s_psprframe->origin_y, up);
78  -s_psprframe->origin_x, left);
80  -s_psprframe->origin_y, down);
81 
82  // invert UP vector for sprites
84 
85  pverts = r_clip_verts[0];
86 
87  pverts[0][0] = r_entorigin[0] + up[0] + left[0];
88  pverts[0][1] = r_entorigin[1] + up[1] + left[1];
89  pverts[0][2] = r_entorigin[2] + up[2] + left[2];
90  pverts[0][3] = 0;
91  pverts[0][4] = 0;
92 
93  pverts[1][0] = r_entorigin[0] + up[0] + right[0];
94  pverts[1][1] = r_entorigin[1] + up[1] + right[1];
95  pverts[1][2] = r_entorigin[2] + up[2] + right[2];
96  pverts[1][3] = s_psprframe->width;
97  pverts[1][4] = 0;
98 
99  pverts[2][0] = r_entorigin[0] + down[0] + right[0];
100  pverts[2][1] = r_entorigin[1] + down[1] + right[1];
101  pverts[2][2] = r_entorigin[2] + down[2] + right[2];
102  pverts[2][3] = s_psprframe->width;
103  pverts[2][4] = s_psprframe->height;
104 
105  pverts[3][0] = r_entorigin[0] + down[0] + left[0];
106  pverts[3][1] = r_entorigin[1] + down[1] + left[1];
107  pverts[3][2] = r_entorigin[2] + down[2] + left[2];
108  pverts[3][3] = 0;
109  pverts[3][4] = s_psprframe->height;
110 
111  r_polydesc.nump = 4;
115 
118  R_ClipAndDrawPoly ( currententity->alpha, false, true );
119  else
120  R_ClipAndDrawPoly ( 1.0F, false, true );
122 }

Referenced by R_DrawEntitiesOnList().

◆ R_PolyChooseSpanletRoutine()

void R_PolyChooseSpanletRoutine ( float  alpha,
qboolean  isturbulent 
)

◆ R_PolygonCalculateGradients()

void R_PolygonCalculateGradients ( void  )

Definition at line 1245 of file r_poly.c.

1246 {
1247  vec3_t p_normal, p_saxis, p_taxis;
1248  float distinv;
1249 
1250  TransformVector(r_polydesc.vpn, p_normal);
1251  TransformVector(r_polydesc.vright, p_saxis);
1252  TransformVector(r_polydesc.vup, p_taxis);
1253 
1255 
1256  d_sdivzstepu = p_saxis[0] * xscaleinv;
1257  d_sdivzstepv = -p_saxis[1] * yscaleinv;
1258  d_sdivzorigin = p_saxis[2] - xcenter * d_sdivzstepu - ycenter * d_sdivzstepv;
1259 
1260  d_tdivzstepu = p_taxis[0] * xscaleinv;
1261  d_tdivzstepv = -p_taxis[1] * yscaleinv;
1262  d_tdivzorigin = p_taxis[2] - xcenter * d_tdivzstepu - ycenter * d_tdivzstepv;
1263 
1264  d_zistepu = p_normal[0] * xscaleinv * distinv;
1265  d_zistepv = -p_normal[1] * yscaleinv * distinv;
1266  d_ziorigin = p_normal[2] * distinv - xcenter * d_zistepu - ycenter * d_zistepv;
1267 
1270 
1271  // -1 (-epsilon) so we never wander off the edge of the texture
1272  bbextents = (r_polydesc.pixel_width << 16) - 1;
1273  bbextentt = (r_polydesc.pixel_height << 16) - 1;
1274 }

Referenced by R_DrawPoly().

Variable Documentation

◆ r_clip_verts

◆ r_polydesc

RF_TRANSLUCENT
#define RF_TRANSLUCENT
Definition: q_shared.h:604
currentmodel
model_t * currentmodel
Definition: r_main.c:39
msurface_s::plane
mplane_t * plane
Definition: r_model.h:100
d_sdivzorigin
float d_sdivzorigin
Definition: r_main.c:190
r_clip_verts
vec5_t r_clip_verts[2][MAXWORKINGVERTS+2]
Definition: r_poly.c:52
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
VectorSubtract
#define VectorSubtract(a, b, c)
Definition: q_shared.h:163
surfcache_s
Definition: r_local.h:389
ri
refimport_t ri
Definition: r_main.c:25
surfcache_s::height
unsigned height
Definition: r_local.h:397
yscaleinv
float yscaleinv
Definition: r_local.h:576
d_tdivzstepv
float d_tdivzstepv
Definition: r_local.h:518
D_CacheSurface
surfcache_t * D_CacheSurface(msurface_t *surface, int miplevel)
Definition: r_surf.c:638
dsprframe_t::height
int height
Definition: qfiles.h:176
vright
vec3_t vright
Definition: r_main.c:74
model_s::edges
medge_t * edges
Definition: r_model.h:211
VectorScale
void VectorScale(vec3_t in, vec_t scale, vec3_t out)
Definition: q_shared.c:782
i
int i
Definition: q_shared.c:305
msurface_s::numedges
int numedges
Definition: r_model.h:104
modelorg
vec3_t modelorg
Definition: r_bsp.c:29
d_tdivzorigin
float d_tdivzorigin
Definition: r_local.h:519
polydesc_t::pixel_width
int pixel_width
Definition: r_local.h:416
polydesc_t::stipple_parity
int stipple_parity
Definition: r_local.h:423
r_origin
vec3_t r_origin
Definition: r_main.c:75
xscaleinv
float xscaleinv
Definition: r_main.c:83
entity_s::flags
int flags
Definition: ref.h:76
currententity
entity_t * currententity
Definition: r_bsp.c:28
SURF_WARP
#define SURF_WARP
Definition: qfiles.h:372
mplane_s::normal
vec3_t normal
Definition: r_model.h:59
polydesc_t::vpn
vec3_t vpn
Definition: r_local.h:418
polydesc_t::viewer_position
float viewer_position[3]
Definition: r_local.h:421
model_s::extradata
void * extradata
Definition: r_model.h:235
vup
vec3_t vup
Definition: r_main.c:72
r_clip_verts
vec5_t r_clip_verts[2][MAXWORKINGVERTS+2]
Definition: r_poly.c:52
mvertex_t::position
vec3_t position
Definition: r_model.h:47
dsprite_t
Definition: qfiles.h:181
polydesc_t::pixels
byte * pixels
Definition: r_local.h:415
SURF_PLANEBACK
#define SURF_PLANEBACK
Definition: r_model.h:68
polydesc_t::t_offset
float t_offset
Definition: r_local.h:420
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
mtexinfo_s::image
image_t * image
Definition: r_model.h:87
polydesc_t::s_offset
float s_offset
Definition: r_local.h:420
d_ziorigin
float d_ziorigin
Definition: r_local.h:519
entity_s::alpha
float alpha
Definition: ref.h:73
medge_t
Definition: r_model.h:77
image_s::height
int height
Definition: r_local.h:75
bbextentt
fixed16_t bbextentt
Definition: r_local.h:522
polydesc_t::nump
int nump
Definition: r_local.h:413
msurface_s::texinfo
mtexinfo_t * texinfo
Definition: r_model.h:112
polydesc_t::dist
float dist
Definition: r_local.h:419
SURF_FLOWING
#define SURF_FLOWING
Definition: qfiles.h:375
sadjust
fixed16_t sadjust
Definition: r_local.h:732
d_tdivzstepu
float d_tdivzstepu
Definition: r_local.h:517
r_newrefdef
refdef_t r_newrefdef
Definition: r_main.c:38
DotProduct
#define DotProduct(x, y)
Definition: q_shared.h:162
r_polydesc
polydesc_t r_polydesc
Definition: r_poly.c:45
F
#define F(X, Y, Z)
Definition: md4.c:13
bbextents
fixed16_t bbextents
Definition: r_local.h:733
refdef_t::time
float time
Definition: ref.h:109
d_zistepv
float d_zistepv
Definition: r_local.h:518
model_s::surfedges
int * surfedges
Definition: r_model.h:224
image_s::pixels
byte * pixels[4]
Definition: r_local.h:78
image_s::width
int width
Definition: r_local.h:75
VectorInverse
void VectorInverse(vec3_t v)
Definition: q_shared.c:775
d_zistepu
float d_zistepu
Definition: r_local.h:517
ycenter
float ycenter
Definition: r_local.h:574
dsprite_t::frames
dsprframe_t frames[1]
Definition: qfiles.h:185
dsprframe_t::width
int width
Definition: qfiles.h:176
msurface_s::flags
int flags
Definition: r_model.h:101
r_pedge
medge_t * r_pedge
Definition: r_rast.c:41
r_polydesc
polydesc_t r_polydesc
Definition: r_poly.c:45
entity_s::frame
int frame
Definition: ref.h:58
VectorCopy
#define VectorCopy(a, b)
Definition: q_shared.h:165
model_s::skins
image_t * skins[MAX_MD2SKINS]
Definition: r_model.h:234
mtexinfo_s::vecs
float vecs[2][4]
Definition: r_model.h:85
fixed16_t
int fixed16_t
Definition: q_shared.h:139
vec3_origin
vec3_t vec3_origin
Definition: q_shared.c:24
up
static vec3_t up
Definition: p_view.c:29
dsprite_t::numframes
int numframes
Definition: qfiles.h:184
dsprframe_t::origin_y
int origin_y
Definition: qfiles.h:177
polydesc_t::vup
vec3_t vup
Definition: r_local.h:418
surfcache_s::data
byte data[4]
Definition: r_local.h:400
medge_t::v
unsigned short v[2]
Definition: r_model.h:79
vec5_t
vec_t vec5_t[5]
Definition: q_shared.h:135
d_sdivzstepu
float d_sdivzstepu
Definition: r_main.c:188
dsprframe_t
Definition: qfiles.h:174
mtexinfo_s::flags
int flags
Definition: r_model.h:88
msurface_s::texturemins
short texturemins[2]
Definition: r_model.h:109
surfcache_s::width
unsigned width
Definition: r_local.h:396
R_ClipAndDrawPoly
void R_ClipAndDrawPoly(float alpha, qboolean isturbulent, qboolean textured)
dsprframe_t::origin_x
int origin_x
Definition: qfiles.h:177
right
GLdouble right
Definition: qgl_win.c:159
d_sdivzstepv
float d_sdivzstepv
Definition: r_main.c:189
r_entorigin
vec3_t r_entorigin
Definition: r_bsp.c:31
model_s::vertexes
mvertex_t * vertexes
Definition: r_model.h:208
tadjust
fixed16_t tadjust
Definition: r_local.h:521
polydesc_t::pixel_height
int pixel_height
Definition: r_local.h:417
xcenter
float xcenter
Definition: r_main.c:81
vpn
vec3_t vpn
Definition: r_main.c:73
TransformVector
void TransformVector(vec3_t in, vec3_t out)
Definition: r_misc.c:216
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:134
polydesc_t::vright
vec3_t vright
Definition: r_local.h:418
msurface_s::firstedge
int firstedge
Definition: r_model.h:103