1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19*/
20
21#include "quakedef.h"
22
23#ifdef GLTEST
24
25typedef struct
26{
27	plane_t	*plane;
28	vec3_t	origin;
29	vec3_t	normal;
30	vec3_t	up;
31	vec3_t	right;
32	vec3_t	reflect;
33	float	length;
34} puff_t;
35
36#define	MAX_PUFFS	64
37
38puff_t	puffs[MAX_PUFFS];
39
40
41void Test_Init (void)
42{
43}
44
45
46
47plane_t	junk;
48plane_t	*HitPlane (vec3_t start, vec3_t end)
49{
50	trace_t		trace;
51
52// fill in a default trace
53	memset (&trace, 0, sizeof(trace_t));
54	trace.fraction = 1;
55	trace.allsolid = true;
56	VectorCopy (end, trace.endpos);
57
58	SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
59
60	junk = trace.plane;
61	return &junk;
62}
63
64void Test_Spawn (vec3_t origin)
65{
66	int		i;
67	puff_t	*p;
68	vec3_t	temp;
69	vec3_t	normal;
70	vec3_t	incoming;
71	plane_t	*plane;
72	float	d;
73
74	for (i=0,p=puffs ; i<MAX_PUFFS ; i++,p++)
75	{
76		if (p->length <= 0)
77			break;
78	}
79	if (i == MAX_PUFFS)
80		return;
81
82	VectorSubtract (r_refdef.vieworg, origin, incoming);
83	VectorSubtract (origin, incoming, temp);
84	plane = HitPlane (r_refdef.vieworg, temp);
85
86	VectorNormalize (incoming);
87	d = DotProduct (incoming, plane->normal);
88	VectorSubtract (vec3_origin, incoming, p->reflect);
89	VectorMA (p->reflect, d*2, plane->normal, p->reflect);
90
91	VectorCopy (origin, p->origin);
92	VectorCopy (plane->normal, p->normal);
93
94	CrossProduct (incoming, p->normal, p->up);
95
96	CrossProduct (p->up, p->normal, p->right);
97
98	p->length = 8;
99}
100
101void DrawPuff (puff_t *p)
102{
103	vec3_t	pts[2][3];
104	int		i, j;
105	float	s, d;
106
107	for (i=0 ; i<2 ; i++)
108	{
109		if (i == 1)
110		{
111			s = 6;
112			d = p->length;
113		}
114		else
115		{
116			s = 2;
117			d = 0;
118		}
119
120		for (j=0 ; j<3 ; j++)
121		{
122			pts[i][0][j] = p->origin[j] + p->up[j]*s + p->reflect[j]*d;
123			pts[i][1][j] = p->origin[j] + p->right[j]*s + p->reflect[j]*d;
124			pts[i][2][j] = p->origin[j] + -p->right[j]*s + p->reflect[j]*d;
125		}
126	}
127
128	glColor3f (1, 0, 0);
129
130#if 0
131	glBegin (GL_LINES);
132	glVertex3fv (p->origin);
133	glVertex3f (p->origin[0] + p->length*p->reflect[0],
134		p->origin[1] + p->length*p->reflect[1],
135		p->origin[2] + p->length*p->reflect[2]);
136
137	glVertex3fv (pts[0][0]);
138	glVertex3fv (pts[1][0]);
139
140	glVertex3fv (pts[0][1]);
141	glVertex3fv (pts[1][1]);
142
143	glVertex3fv (pts[0][2]);
144	glVertex3fv (pts[1][2]);
145
146	glEnd ();
147#endif
148
149	glBegin (GL_QUADS);
150	for (i=0 ; i<3 ; i++)
151	{
152		j = (i+1)%3;
153		glVertex3fv (pts[0][j]);
154		glVertex3fv (pts[1][j]);
155		glVertex3fv (pts[1][i]);
156		glVertex3fv (pts[0][i]);
157	}
158	glEnd ();
159
160	glBegin (GL_TRIANGLES);
161	glVertex3fv (pts[1][0]);
162	glVertex3fv (pts[1][1]);
163	glVertex3fv (pts[1][2]);
164	glEnd ();
165
166	p->length -= host_frametime*2;
167}
168
169
170void Test_Draw (void)
171{
172	int		i;
173	puff_t	*p;
174
175	for (i=0, p=puffs ; i<MAX_PUFFS ; i++,p++)
176	{
177		if (p->length > 0)
178			DrawPuff (p);
179	}
180}
181
182#endif
183