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