d_part.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. Copyright (C) 1996-1997 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. // d_part.c: software driver module for drawing particles
  16. #include "quakedef.h"
  17. #include "d_local.h"
  18. /*
  19. ==============
  20. D_EndParticles
  21. ==============
  22. */
  23. void D_EndParticles (void)
  24. {
  25. // not used by software driver
  26. }
  27. /*
  28. ==============
  29. D_StartParticles
  30. ==============
  31. */
  32. void D_StartParticles (void)
  33. {
  34. // not used by software driver
  35. }
  36. #if !id386
  37. /*
  38. ==============
  39. D_DrawParticle
  40. ==============
  41. */
  42. void D_DrawParticle (particle_t *pparticle)
  43. {
  44. vec3_t local, transformed;
  45. float zi;
  46. byte *pdest;
  47. short *pz;
  48. int i, izi, pix, count, u, v;
  49. // transform point
  50. VectorSubtract (pparticle->org, r_origin, local);
  51. transformed[0] = DotProduct(local, r_pright);
  52. transformed[1] = DotProduct(local, r_pup);
  53. transformed[2] = DotProduct(local, r_ppn);
  54. if (transformed[2] < PARTICLE_Z_CLIP)
  55. return;
  56. // project the point
  57. // FIXME: preadjust xcenter and ycenter
  58. zi = 1.0 / transformed[2];
  59. u = (int)(xcenter + zi * transformed[0] + 0.5);
  60. v = (int)(ycenter - zi * transformed[1] + 0.5);
  61. if ((v > d_vrectbottom_particle) ||
  62. (u > d_vrectright_particle) ||
  63. (v < d_vrecty) ||
  64. (u < d_vrectx))
  65. {
  66. return;
  67. }
  68. pz = d_pzbuffer + (d_zwidth * v) + u;
  69. pdest = d_viewbuffer + d_scantable[v] + u;
  70. izi = (int)(zi * 0x8000);
  71. pix = izi >> d_pix_shift;
  72. if (pix < d_pix_min)
  73. pix = d_pix_min;
  74. else if (pix > d_pix_max)
  75. pix = d_pix_max;
  76. switch (pix)
  77. {
  78. case 1:
  79. count = 1 << d_y_aspect_shift;
  80. for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
  81. {
  82. if (pz[0] <= izi)
  83. {
  84. pz[0] = izi;
  85. pdest[0] = pparticle->color;
  86. }
  87. }
  88. break;
  89. case 2:
  90. count = 2 << d_y_aspect_shift;
  91. for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
  92. {
  93. if (pz[0] <= izi)
  94. {
  95. pz[0] = izi;
  96. pdest[0] = pparticle->color;
  97. }
  98. if (pz[1] <= izi)
  99. {
  100. pz[1] = izi;
  101. pdest[1] = pparticle->color;
  102. }
  103. }
  104. break;
  105. case 3:
  106. count = 3 << d_y_aspect_shift;
  107. for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
  108. {
  109. if (pz[0] <= izi)
  110. {
  111. pz[0] = izi;
  112. pdest[0] = pparticle->color;
  113. }
  114. if (pz[1] <= izi)
  115. {
  116. pz[1] = izi;
  117. pdest[1] = pparticle->color;
  118. }
  119. if (pz[2] <= izi)
  120. {
  121. pz[2] = izi;
  122. pdest[2] = pparticle->color;
  123. }
  124. }
  125. break;
  126. case 4:
  127. count = 4 << d_y_aspect_shift;
  128. for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
  129. {
  130. if (pz[0] <= izi)
  131. {
  132. pz[0] = izi;
  133. pdest[0] = pparticle->color;
  134. }
  135. if (pz[1] <= izi)
  136. {
  137. pz[1] = izi;
  138. pdest[1] = pparticle->color;
  139. }
  140. if (pz[2] <= izi)
  141. {
  142. pz[2] = izi;
  143. pdest[2] = pparticle->color;
  144. }
  145. if (pz[3] <= izi)
  146. {
  147. pz[3] = izi;
  148. pdest[3] = pparticle->color;
  149. }
  150. }
  151. break;
  152. default:
  153. count = pix << d_y_aspect_shift;
  154. for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
  155. {
  156. for (i=0 ; i<pix ; i++)
  157. {
  158. if (pz[i] <= izi)
  159. {
  160. pz[i] = izi;
  161. pdest[i] = pparticle->color;
  162. }
  163. }
  164. }
  165. break;
  166. }
  167. }
  168. #endif // !id386