icculus quake2 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 1010 of file r_poly.c.

1011 {
1012  int i, lindex, lnumverts;
1013  medge_t *pedges, *r_pedge;
1014  int vertpage;
1015  float *vec;
1016  vec5_t *pverts;
1017  float tmins[2] = { 0, 0 };
1018 
1019  r_polydesc.nump = 0;
1020 
1021  // reconstruct the polygon
1022  pedges = currentmodel->edges;
1023  lnumverts = fa->numedges;
1024  vertpage = 0;
1025 
1026  pverts = r_clip_verts[0];
1027 
1028  for (i=0 ; i<lnumverts ; i++)
1029  {
1030  lindex = currentmodel->surfedges[fa->firstedge + i];
1031 
1032  if (lindex > 0)
1033  {
1034  r_pedge = &pedges[lindex];
1035  vec = currentmodel->vertexes[r_pedge->v[0]].position;
1036  }
1037  else
1038  {
1039  r_pedge = &pedges[-lindex];
1040  vec = currentmodel->vertexes[r_pedge->v[1]].position;
1041  }
1042 
1043  VectorCopy (vec, pverts[i] );
1044  }
1045 
1046  VectorCopy( fa->texinfo->vecs[0], r_polydesc.vright );
1047  VectorCopy( fa->texinfo->vecs[1], r_polydesc.vup );
1050 
1051  if ( fa->flags & SURF_PLANEBACK )
1052  {
1054  }
1055 
1056 // PGM 09/16/98
1057  if ( fa->texinfo->flags & (SURF_WARP|SURF_FLOWING) )
1058  {
1059  r_polydesc.pixels = fa->texinfo->image->pixels[0];
1062  }
1063 // PGM 09/16/98
1064  else
1065  {
1066  surfcache_t *scache;
1067 
1068  scache = D_CacheSurface( fa, 0 );
1069 
1070  r_polydesc.pixels = scache->data;
1071  r_polydesc.pixel_width = scache->width;
1072  r_polydesc.pixel_height = scache->height;
1073 
1074  tmins[0] = fa->texturemins[0];
1075  tmins[1] = fa->texturemins[1];
1076  }
1077 
1078  r_polydesc.dist = DotProduct( r_polydesc.vpn, pverts[0] );
1079 
1080  r_polydesc.s_offset = fa->texinfo->vecs[0][3] - tmins[0];
1081  r_polydesc.t_offset = fa->texinfo->vecs[1][3] - tmins[1];
1082 
1083  // scrolling texture addition
1084  if (fa->texinfo->flags & SURF_FLOWING)
1085  {
1086  r_polydesc.s_offset += -128 * ( (r_newrefdef.time*0.25) - (int)(r_newrefdef.time*0.25) );
1087  }
1088 
1089  r_polydesc.nump = lnumverts;
1090 }

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 1095 of file r_poly.c.

1096 {
1097  vec3_t p_normal, p_saxis, p_taxis;
1098  float distinv;
1099 
1100  TransformVector (r_polydesc.vpn, p_normal);
1101  TransformVector (r_polydesc.vright, p_saxis);
1102  TransformVector (r_polydesc.vup, p_taxis);
1103 
1104  distinv = 1.0 / (-(DotProduct (r_polydesc.viewer_position, r_polydesc.vpn)) + r_polydesc.dist );
1105 
1106  d_sdivzstepu = p_saxis[0] * xscaleinv;
1107  d_sdivzstepv = -p_saxis[1] * yscaleinv;
1108  d_sdivzorigin = p_saxis[2] - xcenter * d_sdivzstepu - ycenter * d_sdivzstepv;
1109 
1110  d_tdivzstepu = p_taxis[0] * xscaleinv;
1111  d_tdivzstepv = -p_taxis[1] * yscaleinv;
1112  d_tdivzorigin = p_taxis[2] - xcenter * d_tdivzstepu - ycenter * d_tdivzstepv;
1113 
1114  d_zistepu = p_normal[0] * xscaleinv * distinv;
1115  d_zistepv = -p_normal[1] * yscaleinv * distinv;
1116  d_ziorigin = p_normal[2] * distinv - xcenter * d_zistepu - ycenter * d_zistepv;
1117 
1120 
1121 // -1 (-epsilon) so we never wander off the edge of the texture
1122  bbextents = (r_polydesc.pixel_width << 16) - 1;
1123  bbextentt = (r_polydesc.pixel_height << 16) - 1;
1124 }

Referenced by R_DrawPoly().

Variable Documentation

◆ r_clip_verts

◆ r_polydesc

RF_TRANSLUCENT
#define RF_TRANSLUCENT
Definition: q_shared.h:618
currentmodel
model_t * currentmodel
Definition: r_main.c:37
d_sdivzorigin
float d_sdivzorigin
Definition: r_main.c:175
r_clip_verts
vec5_t r_clip_verts[2][MAXWORKINGVERTS+2]
Definition: r_poly.c:50
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
VectorSubtract
#define VectorSubtract(a, b, c)
Definition: q_shared.h:156
surfcache_s
Definition: r_local.h:360
ri
refimport_t ri
Definition: r_main.c:25
surfcache_s::height
unsigned height
Definition: r_local.h:368
yscaleinv
float yscaleinv
Definition: r_local.h:540
d_tdivzstepv
float d_tdivzstepv
Definition: r_local.h:482
D_CacheSurface
surfcache_t * D_CacheSurface(msurface_t *surface, int miplevel)
Definition: r_surf.c:575
dsprframe_t::height
int height
Definition: qfiles.h:176
vright
vec3_t vright
Definition: r_main.c:68
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:483
polydesc_t::pixel_width
int pixel_width
Definition: r_local.h:387
polydesc_t::stipple_parity
int stipple_parity
Definition: r_local.h:394
r_origin
vec3_t r_origin
Definition: r_main.c:69
xscaleinv
float xscaleinv
Definition: r_main.c:77
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:389
polydesc_t::viewer_position
float viewer_position[3]
Definition: r_local.h:392
model_s::extradata
void * extradata
Definition: r_model.h:235
vup
vec3_t vup
Definition: r_main.c:66
r_clip_verts
vec5_t r_clip_verts[2][MAXWORKINGVERTS+2]
Definition: r_poly.c:50
msurface_s::plane
mplane_t * plane
Definition: r_model.h:100
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:386
SURF_PLANEBACK
#define SURF_PLANEBACK
Definition: r_model.h:68
polydesc_t::t_offset
float t_offset
Definition: r_local.h:391
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:228
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:743
mtexinfo_s::image
image_t * image
Definition: r_model.h:87
polydesc_t::s_offset
float s_offset
Definition: r_local.h:391
d_ziorigin
float d_ziorigin
Definition: r_local.h:483
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:69
bbextentt
fixed16_t bbextentt
Definition: r_local.h:486
polydesc_t::nump
int nump
Definition: r_local.h:384
msurface_s::texinfo
mtexinfo_t * texinfo
Definition: r_model.h:112
polydesc_t::dist
float dist
Definition: r_local.h:390
SURF_FLOWING
#define SURF_FLOWING
Definition: qfiles.h:375
sadjust
fixed16_t sadjust
Definition: r_local.h:672
d_tdivzstepu
float d_tdivzstepu
Definition: r_local.h:481
r_newrefdef
refdef_t r_newrefdef
Definition: r_main.c:36
DotProduct
#define DotProduct(x, y)
Definition: q_shared.h:155
r_polydesc
polydesc_t r_polydesc
Definition: r_poly.c:43
F
#define F(X, Y, Z)
Definition: md4.c:13
bbextents
fixed16_t bbextents
Definition: r_local.h:673
refdef_t::time
float time
Definition: ref.h:127
d_zistepv
float d_zistepv
Definition: r_local.h:482
model_s::surfedges
int * surfedges
Definition: r_model.h:224
image_s::pixels
byte * pixels[4]
Definition: r_local.h:72
image_s::width
int width
Definition: r_local.h:69
VectorInverse
void VectorInverse(vec3_t v)
Definition: q_shared.c:775
d_zistepu
float d_zistepu
Definition: r_local.h:481
ycenter
float ycenter
Definition: r_local.h:538
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:43
entity_s::frame
int frame
Definition: ref.h:58
VectorCopy
#define VectorCopy(a, b)
Definition: q_shared.h:158
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:132
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:389
surfcache_s::data
byte data[4]
Definition: r_local.h:371
medge_t::v
unsigned short v[2]
Definition: r_model.h:79
vec5_t
vec_t vec5_t[5]
Definition: q_shared.h:128
d_sdivzstepu
float d_sdivzstepu
Definition: r_main.c:173
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:367
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:174
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:485
polydesc_t::pixel_height
int pixel_height
Definition: r_local.h:388
xcenter
float xcenter
Definition: r_main.c:75
vpn
vec3_t vpn
Definition: r_main.c:67
TransformVector
void TransformVector(vec3_t in, vec3_t out)
Definition: r_misc.c:215
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:127
polydesc_t::vright
vec3_t vright
Definition: r_local.h:389
msurface_s::firstedge
int firstedge
Definition: r_model.h:103