r_sprite.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // r_sprite.c
  16. #include "r_local.h"
  17. extern polydesc_t r_polydesc;
  18. void R_BuildPolygonFromSurface(msurface_t *fa);
  19. void R_PolygonCalculateGradients (void);
  20. extern void R_PolyChooseSpanletRoutine( float alpha, qboolean isturbulent );
  21. extern vec5_t r_clip_verts[2][MAXWORKINGVERTS+2];
  22. extern void R_ClipAndDrawPoly( float alpha, qboolean isturbulent, qboolean textured );
  23. /*
  24. ** R_DrawSprite
  25. **
  26. ** Draw currententity / currentmodel as a single texture
  27. ** mapped polygon
  28. */
  29. void R_DrawSprite (void)
  30. {
  31. vec5_t *pverts;
  32. vec3_t left, up, right, down;
  33. dsprite_t *s_psprite;
  34. dsprframe_t *s_psprframe;
  35. s_psprite = (dsprite_t *)currentmodel->extradata;
  36. #if 0
  37. if (currententity->frame >= s_psprite->numframes
  38. || currententity->frame < 0)
  39. {
  40. ri.Con_Printf (PRINT_ALL, "No such sprite frame %i\n",
  41. currententity->frame);
  42. currententity->frame = 0;
  43. }
  44. #endif
  45. currententity->frame %= s_psprite->numframes;
  46. s_psprframe = &s_psprite->frames[currententity->frame];
  47. r_polydesc.pixels = currentmodel->skins[currententity->frame]->pixels[0];
  48. r_polydesc.pixel_width = s_psprframe->width;
  49. r_polydesc.pixel_height = s_psprframe->height;
  50. r_polydesc.dist = 0;
  51. // generate the sprite's axes, completely parallel to the viewplane.
  52. VectorCopy (vup, r_polydesc.vup);
  53. VectorCopy (vright, r_polydesc.vright);
  54. VectorCopy (vpn, r_polydesc.vpn);
  55. // build the sprite poster in worldspace
  56. VectorScale (r_polydesc.vright,
  57. s_psprframe->width - s_psprframe->origin_x, right);
  58. VectorScale (r_polydesc.vup,
  59. s_psprframe->height - s_psprframe->origin_y, up);
  60. VectorScale (r_polydesc.vright,
  61. -s_psprframe->origin_x, left);
  62. VectorScale (r_polydesc.vup,
  63. -s_psprframe->origin_y, down);
  64. // invert UP vector for sprites
  65. VectorInverse( r_polydesc.vup );
  66. pverts = r_clip_verts[0];
  67. pverts[0][0] = r_entorigin[0] + up[0] + left[0];
  68. pverts[0][1] = r_entorigin[1] + up[1] + left[1];
  69. pverts[0][2] = r_entorigin[2] + up[2] + left[2];
  70. pverts[0][3] = 0;
  71. pverts[0][4] = 0;
  72. pverts[1][0] = r_entorigin[0] + up[0] + right[0];
  73. pverts[1][1] = r_entorigin[1] + up[1] + right[1];
  74. pverts[1][2] = r_entorigin[2] + up[2] + right[2];
  75. pverts[1][3] = s_psprframe->width;
  76. pverts[1][4] = 0;
  77. pverts[2][0] = r_entorigin[0] + down[0] + right[0];
  78. pverts[2][1] = r_entorigin[1] + down[1] + right[1];
  79. pverts[2][2] = r_entorigin[2] + down[2] + right[2];
  80. pverts[2][3] = s_psprframe->width;
  81. pverts[2][4] = s_psprframe->height;
  82. pverts[3][0] = r_entorigin[0] + down[0] + left[0];
  83. pverts[3][1] = r_entorigin[1] + down[1] + left[1];
  84. pverts[3][2] = r_entorigin[2] + down[2] + left[2];
  85. pverts[3][3] = 0;
  86. pverts[3][4] = s_psprframe->height;
  87. r_polydesc.nump = 4;
  88. r_polydesc.s_offset = ( r_polydesc.pixel_width >> 1);
  89. r_polydesc.t_offset = ( r_polydesc.pixel_height >> 1);
  90. VectorCopy( modelorg, r_polydesc.viewer_position );
  91. r_polydesc.stipple_parity = 1;
  92. if ( currententity->flags & RF_TRANSLUCENT )
  93. R_ClipAndDrawPoly ( currententity->alpha, false, true );
  94. else
  95. R_ClipAndDrawPoly ( 1.0F, false, true );
  96. r_polydesc.stipple_parity = 0;
  97. }