gl_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. #include "quakedef.h"
  16. #ifdef GLTEST
  17. typedef struct
  18. {
  19. plane_t *plane;
  20. vec3_t origin;
  21. vec3_t normal;
  22. vec3_t up;
  23. vec3_t right;
  24. vec3_t reflect;
  25. float length;
  26. } puff_t;
  27. #define MAX_PUFFS 64
  28. puff_t puffs[MAX_PUFFS];
  29. void Test_Init (void)
  30. {
  31. }
  32. plane_t junk;
  33. plane_t *HitPlane (vec3_t start, vec3_t end)
  34. {
  35. trace_t trace;
  36. // fill in a default trace
  37. memset (&trace, 0, sizeof(trace_t));
  38. trace.fraction = 1;
  39. trace.allsolid = true;
  40. VectorCopy (end, trace.endpos);
  41. SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
  42. junk = trace.plane;
  43. return &junk;
  44. }
  45. void Test_Spawn (vec3_t origin)
  46. {
  47. int i;
  48. puff_t *p;
  49. vec3_t temp;
  50. vec3_t normal;
  51. vec3_t incoming;
  52. plane_t *plane;
  53. float d;
  54. for (i=0,p=puffs ; i<MAX_PUFFS ; i++,p++)
  55. {
  56. if (p->length <= 0)
  57. break;
  58. }
  59. if (i == MAX_PUFFS)
  60. return;
  61. VectorSubtract (r_refdef.vieworg, origin, incoming);
  62. VectorSubtract (origin, incoming, temp);
  63. plane = HitPlane (r_refdef.vieworg, temp);
  64. VectorNormalize (incoming);
  65. d = DotProduct (incoming, plane->normal);
  66. VectorSubtract (vec3_origin, incoming, p->reflect);
  67. VectorMA (p->reflect, d*2, plane->normal, p->reflect);
  68. VectorCopy (origin, p->origin);
  69. VectorCopy (plane->normal, p->normal);
  70. CrossProduct (incoming, p->normal, p->up);
  71. CrossProduct (p->up, p->normal, p->right);
  72. p->length = 8;
  73. }
  74. void DrawPuff (puff_t *p)
  75. {
  76. vec3_t pts[2][3];
  77. int i, j;
  78. float s, d;
  79. for (i=0 ; i<2 ; i++)
  80. {
  81. if (i == 1)
  82. {
  83. s = 6;
  84. d = p->length;
  85. }
  86. else
  87. {
  88. s = 2;
  89. d = 0;
  90. }
  91. for (j=0 ; j<3 ; j++)
  92. {
  93. pts[i][0][j] = p->origin[j] + p->up[j]*s + p->reflect[j]*d;
  94. pts[i][1][j] = p->origin[j] + p->right[j]*s + p->reflect[j]*d;
  95. pts[i][2][j] = p->origin[j] + -p->right[j]*s + p->reflect[j]*d;
  96. }
  97. }
  98. glColor3f (1, 0, 0);
  99. #if 0
  100. glBegin (GL_LINES);
  101. glVertex3fv (p->origin);
  102. glVertex3f (p->origin[0] + p->length*p->reflect[0],
  103. p->origin[1] + p->length*p->reflect[1],
  104. p->origin[2] + p->length*p->reflect[2]);
  105. glVertex3fv (pts[0][0]);
  106. glVertex3fv (pts[1][0]);
  107. glVertex3fv (pts[0][1]);
  108. glVertex3fv (pts[1][1]);
  109. glVertex3fv (pts[0][2]);
  110. glVertex3fv (pts[1][2]);
  111. glEnd ();
  112. #endif
  113. glBegin (GL_QUADS);
  114. for (i=0 ; i<3 ; i++)
  115. {
  116. j = (i+1)%3;
  117. glVertex3fv (pts[0][j]);
  118. glVertex3fv (pts[1][j]);
  119. glVertex3fv (pts[1][i]);
  120. glVertex3fv (pts[0][i]);
  121. }
  122. glEnd ();
  123. glBegin (GL_TRIANGLES);
  124. glVertex3fv (pts[1][0]);
  125. glVertex3fv (pts[1][1]);
  126. glVertex3fv (pts[1][2]);
  127. glEnd ();
  128. p->length -= host_frametime*2;
  129. }
  130. void Test_Draw (void)
  131. {
  132. int i;
  133. puff_t *p;
  134. for (i=0, p=puffs ; i<MAX_PUFFS ; i++,p++)
  135. {
  136. if (p->length > 0)
  137. DrawPuff (p);
  138. }
  139. }
  140. #endif