r_sprite.c (3782B)
1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 // r_sprite.c 21 #include "r_local.h" 22 23 extern polydesc_t r_polydesc; 24 25 void R_BuildPolygonFromSurface(msurface_t *fa); 26 void R_PolygonCalculateGradients (void); 27 28 extern void R_PolyChooseSpanletRoutine( float alpha, qboolean isturbulent ); 29 30 extern vec5_t r_clip_verts[2][MAXWORKINGVERTS+2]; 31 32 extern void R_ClipAndDrawPoly( float alpha, qboolean isturbulent, qboolean textured ); 33 34 /* 35 ** R_DrawSprite 36 ** 37 ** Draw currententity / currentmodel as a single texture 38 ** mapped polygon 39 */ 40 void R_DrawSprite (void) 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", 54 currententity->frame); 55 currententity->frame = 0; 56 } 57 #endif 58 currententity->frame %= s_psprite->numframes; 59 60 s_psprframe = &s_psprite->frames[currententity->frame]; 61 62 r_polydesc.pixels = currentmodel->skins[currententity->frame]->pixels[0]; 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. 68 VectorCopy (vup, r_polydesc.vup); 69 VectorCopy (vright, r_polydesc.vright); 70 VectorCopy (vpn, r_polydesc.vpn); 71 72 // build the sprite poster in worldspace 73 VectorScale (r_polydesc.vright, 74 s_psprframe->width - s_psprframe->origin_x, right); 75 VectorScale (r_polydesc.vup, 76 s_psprframe->height - s_psprframe->origin_y, up); 77 VectorScale (r_polydesc.vright, 78 -s_psprframe->origin_x, left); 79 VectorScale (r_polydesc.vup, 80 -s_psprframe->origin_y, down); 81 82 // invert UP vector for sprites 83 VectorInverse( r_polydesc.vup ); 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; 112 r_polydesc.s_offset = ( r_polydesc.pixel_width >> 1); 113 r_polydesc.t_offset = ( r_polydesc.pixel_height >> 1); 114 VectorCopy( modelorg, r_polydesc.viewer_position ); 115 116 r_polydesc.stipple_parity = 1; 117 if ( currententity->flags & RF_TRANSLUCENT ) 118 R_ClipAndDrawPoly ( currententity->alpha, false, true ); 119 else 120 R_ClipAndDrawPoly ( 1.0F, false, true ); 121 r_polydesc.stipple_parity = 0; 122 } 123