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