]> icculus.org git repositories - taylor/freespace2.git/blob - src/fireball/warpineffect.cpp
ryan's struct patch for gcc 2.95
[taylor/freespace2.git] / src / fireball / warpineffect.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Fireball/WarpInEffect.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Code for rendering the warp in effects for ships
16  *
17  * $Log$
18  * Revision 1.3  2002/06/17 06:33:08  relnev
19  * ryan's struct patch for gcc 2.95
20  *
21  * Revision 1.2  2002/06/09 04:41:16  relnev
22  * added copyright header
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:08  root
25  * Initial import.
26  *
27  * 
28  * 3     7/22/99 1:22p Dave
29  * Enable proper zbuffering for warpin glow effect.
30  * 
31  * 2     10/07/98 10:52a Dave
32  * Initial checkin.
33  * 
34  * 1     10/07/98 10:48a Dave
35  * 
36  * 23    4/08/98 8:20p John
37  * Made "Apex" of warp effect not move.
38  * 
39  * 22    3/30/98 4:02p John
40  * Made machines with < 32 MB of RAM use every other frame of certain
41  * bitmaps.   Put in code to keep track of how much RAM we've malloc'd.
42  * 
43  * 21    3/29/98 12:39p John
44  * Made warp in glow page in
45  * 
46  * 20    3/26/98 5:21p John
47  * Added new code to preload all bitmaps at the start of a level.
48  * Commented it out, though.
49  * 
50  * 19    3/18/98 12:36p John
51  * Made hardware have nicer looking warp effect
52  * 
53  * 18    3/16/98 4:51p John
54  * Added low-level code to clip all polygons against an arbritary plane.
55  * Took out all old model_interp_zclip and used this new method instead.  
56  * 
57  * 17    3/10/98 4:18p John
58  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
59  * & Glide have popups and print screen.  Took out all >8bpp software
60  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
61  * support Fred.  Made zbuffering key off of functions rather than one
62  * global variable.
63  * 
64  * 16    3/04/98 7:07p John
65  * Added debug code to try to normalize a zerolength vector.
66  * 
67  * 15    2/26/98 3:28p John
68  * fixed optimize compiler warning
69  * 
70  * 14    2/24/98 6:36p John
71  * Made warp effect draw as a 4 poly cone.
72  * 
73  * 13    2/22/98 12:19p John
74  * Externalized some strings
75  * 
76  * 12    1/15/98 9:07p John
77  * Added noise to warp effect glow.
78  * 
79  * 11    1/15/98 4:58p John
80  * Made warp effect use a looping ani.  Made the scaling up & down be in
81  * software.
82  * 
83  * 10    12/30/97 6:44p John
84  * Made g3_Draw_bitmap functions account for aspect of bitmap.
85  * 
86  * 9     12/08/97 11:15a John
87  * added parameter to warpout for life.
88  * 
89  * 8     12/05/97 3:46p John
90  * made ship thruster glow scale instead of being an animation.
91  * 
92  * 7     12/02/97 3:59p John
93  * Added first rev of thruster glow, along with variable levels of
94  * translucency, which retquired some restructing of palman.
95  * 
96  * 6     10/24/97 12:18p John
97  * sped up warp effect by decreasing number of polys with distance.
98  * 
99  * 5     9/15/97 5:45p John
100  * took out chunk stuff.
101  * made pofview display thrusters as blue polies.
102  * 
103  * 4     9/12/97 4:02p John
104  * put in ship warp out effect.
105  * put in dynamic lighting for warp in/out
106  * 
107  * 3     9/09/97 4:49p John
108  * Almost done ship warp in code
109  * 
110  * 2     9/08/97 8:39a John
111  * added in code structure for grid
112  * 
113  * 1     9/05/97 10:07a John
114  *
115  * $NoKeywords: $
116  */
117
118
119 #include "vecmat.h"
120 #include "tmapper.h"
121 #include "2d.h"
122 #include "3d.h"
123 #include "bmpman.h"
124 #include "model.h"
125 #include "key.h"
126 #include "physics.h"
127 #include "floating.h"
128 #include "model.h"
129 #include "lighting.h"
130 #include "object.h"
131 #include "ship.h"
132 #include "systemvars.h"
133 #include "animplay.h"
134 #include "fireballs.h"
135 #include "linklist.h"
136 #include "timer.h"
137
138 DCF(norm,"normalize a zero length vector")
139 {
140         if ( Dc_command )       {
141                 vector tmp = vmd_zero_vector;
142                 vm_vec_normalize(&tmp);
143         }
144 }
145
146 void draw_face( vertex *v1, vertex *v2, vertex *v3 )
147 {
148         vector norm;
149         vertex *vertlist[3];
150
151         vm_vec_perp(&norm,(vector *)&v1->x,(vector *)&v2->x,(vector *)&v3->x);
152         if ( vm_vec_dot(&norm,(vector *)&v1->x ) >= 0.0 )       {
153                 vertlist[0] = v3;
154                 vertlist[1] = v2;
155                 vertlist[2] = v1;
156         } else {
157                 vertlist[0] = v1;
158                 vertlist[1] = v2;
159                 vertlist[2] = v3;
160         }
161
162         g3_draw_poly( 3, vertlist, TMAP_FLAG_TEXTURED );
163
164 }
165
166 void warpin_render(matrix *orient, vector *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius )
167 {
168         int i;
169
170         int saved_gr_zbuffering = gr_zbuffer_get();
171
172 //      gr_zbuffering = 0;
173
174         gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
175
176         float Grid_depth = radius/2.5f;
177
178         vector center;
179
180         vm_vec_scale_add( &center, pos, &orient->v.fvec, -(max_radius/2.5f)/3.0f );
181
182         vector vecs[5];
183         vertex verts[5];
184
185         vm_vec_scale_add( &vecs[0], &center, &orient->v.uvec, radius );
186         vm_vec_scale_add2( &vecs[0], &orient->v.rvec, -radius );
187         vm_vec_scale_add2( &vecs[0], &orient->v.fvec, Grid_depth );
188
189         vm_vec_scale_add( &vecs[1], &center, &orient->v.uvec, radius );
190         vm_vec_scale_add2( &vecs[1], &orient->v.rvec, radius );
191         vm_vec_scale_add2( &vecs[1], &orient->v.fvec, Grid_depth );
192
193         vm_vec_scale_add( &vecs[2], &center, &orient->v.uvec, -radius );
194         vm_vec_scale_add2( &vecs[2], &orient->v.rvec, radius );
195         vm_vec_scale_add2( &vecs[2], &orient->v.fvec, Grid_depth );
196
197         vm_vec_scale_add( &vecs[3], &center, &orient->v.uvec, -radius );
198         vm_vec_scale_add2( &vecs[3], &orient->v.rvec, -radius );
199         vm_vec_scale_add2( &vecs[3], &orient->v.fvec, Grid_depth );
200
201 //      vm_vec_scale_add( &vecs[4], &center, &orient->fvec, -Grid_depth );
202         vecs[4] = center;
203                         
204         verts[0].u = 0.01f; verts[0].v = 0.01f; 
205         verts[1].u = 0.99f; verts[1].v = 0.01f; 
206         verts[2].u = 0.99f; verts[2].v = 0.99f; 
207         verts[3].u = 0.01f; verts[3].v = 0.99f; 
208         verts[4].u = 0.5f; verts[4].v = 0.5f; 
209
210         for (i=0; i<5; i++ )    {
211                 g3_rotate_vertex( &verts[i], &vecs[i] );
212         }
213
214         draw_face( &verts[0], &verts[4], &verts[1] );
215         draw_face( &verts[1], &verts[4], &verts[2] );
216         draw_face( &verts[4], &verts[3], &verts[2] );
217         draw_face( &verts[0], &verts[3], &verts[4] );
218
219         if ( Warp_glow_bitmap != -1 )   {
220                 gr_set_bitmap( Warp_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
221
222                 float r = radius;
223
224                 int render_it;
225                 
226                 #define OUT_PERCENT1 0.80f
227                 #define OUT_PERCENT2 0.90f
228
229                 #define IN_PERCENT1 0.10f
230                 #define IN_PERCENT2 0.20f
231
232                 if ( life_percent < IN_PERCENT1 )       {
233                         // do nothing
234                         render_it = 0;
235                 } else if ( life_percent < IN_PERCENT2 )        {
236                         r *= ( life_percent-IN_PERCENT1 ) / (IN_PERCENT2-IN_PERCENT1); 
237                         render_it = 1;
238                 } else if ( life_percent < OUT_PERCENT1 )       {
239                         // do nothing
240                         render_it = 1;
241                 } else if ( life_percent < OUT_PERCENT2 )       {
242                         r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2-OUT_PERCENT1);
243                         render_it = 1;
244                 } else {
245                         // do nothing
246                         render_it = 0;
247                 }
248
249                 if (render_it)  {
250                         int saved_gr_zbuffering = gr_zbuffer_get();
251                         gr_zbuffer_set(GR_ZBUFF_READ);
252
253                         // Add in noise 
254                         //float Noise[NOISE_NUM_FRAMES] = { 
255                         int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;
256
257                         r *= (0.40f + Noise[noise_frame]*0.30f);
258                                                 
259                         g3_draw_bitmap( &verts[4], 0,r, TMAP_FLAG_TEXTURED );
260                         gr_zbuffer_set(saved_gr_zbuffering);
261                 }
262         }
263
264         gr_zbuffer_set( saved_gr_zbuffering );
265 }
266
267
268
269
270
271
272