2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Fireball/WarpInEffect.cpp $
15 * Code for rendering the warp in effects for ships
18 * Revision 1.4 2004/09/20 01:31:44 theoddone33
21 * Revision 1.3 2002/06/17 06:33:08 relnev
22 * ryan's struct patch for gcc 2.95
24 * Revision 1.2 2002/06/09 04:41:16 relnev
25 * added copyright header
27 * Revision 1.1.1.1 2002/05/03 03:28:08 root
31 * 3 7/22/99 1:22p Dave
32 * Enable proper zbuffering for warpin glow effect.
34 * 2 10/07/98 10:52a Dave
37 * 1 10/07/98 10:48a Dave
39 * 23 4/08/98 8:20p John
40 * Made "Apex" of warp effect not move.
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.
46 * 21 3/29/98 12:39p John
47 * Made warp in glow page in
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.
53 * 19 3/18/98 12:36p John
54 * Made hardware have nicer looking warp effect
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.
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
67 * 16 3/04/98 7:07p John
68 * Added debug code to try to normalize a zerolength vector.
70 * 15 2/26/98 3:28p John
71 * fixed optimize compiler warning
73 * 14 2/24/98 6:36p John
74 * Made warp effect draw as a 4 poly cone.
76 * 13 2/22/98 12:19p John
77 * Externalized some strings
79 * 12 1/15/98 9:07p John
80 * Added noise to warp effect glow.
82 * 11 1/15/98 4:58p John
83 * Made warp effect use a looping ani. Made the scaling up & down be in
86 * 10 12/30/97 6:44p John
87 * Made g3_Draw_bitmap functions account for aspect of bitmap.
89 * 9 12/08/97 11:15a John
90 * added parameter to warpout for life.
92 * 8 12/05/97 3:46p John
93 * made ship thruster glow scale instead of being an animation.
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.
99 * 6 10/24/97 12:18p John
100 * sped up warp effect by decreasing number of polys with distance.
102 * 5 9/15/97 5:45p John
103 * took out chunk stuff.
104 * made pofview display thrusters as blue polies.
106 * 4 9/12/97 4:02p John
107 * put in ship warp out effect.
108 * put in dynamic lighting for warp in/out
110 * 3 9/09/97 4:49p John
111 * Almost done ship warp in code
113 * 2 9/08/97 8:39a John
114 * added in code structure for grid
116 * 1 9/05/97 10:07a John
130 #include "floating.h"
132 #include "lighting.h"
135 #include "systemvars.h"
136 #include "animplay.h"
137 #include "fireballs.h"
138 #include "linklist.h"
141 DCF(norm,"normalize a zero length vector")
144 vector tmp = vmd_zero_vector;
145 vm_vec_normalize(&tmp);
149 void draw_face( vertex *v1, vertex *v2, vertex *v3 )
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 ) {
165 g3_draw_poly( 3, vertlist, TMAP_FLAG_TEXTURED );
169 void warpin_render(matrix *orient, vector *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius )
173 int saved_gr_zbuffering = gr_zbuffer_get();
175 // gr_zbuffering = 0;
177 gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1 );
179 float Grid_depth = radius/2.5f;
183 vm_vec_scale_add( ¢er, pos, &orient->v.fvec, -(max_radius/2.5f)/3.0f );
188 vm_vec_scale_add( &vecs[0], ¢er, &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 );
192 vm_vec_scale_add( &vecs[1], ¢er, &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 );
196 vm_vec_scale_add( &vecs[2], ¢er, &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 );
200 vm_vec_scale_add( &vecs[3], ¢er, &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 );
204 // vm_vec_scale_add( &vecs[4], ¢er, &orient->fvec, -Grid_depth );
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;
213 for (i=0; i<5; i++ ) {
214 g3_rotate_vertex( &verts[i], &vecs[i] );
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] );
222 if ( Warp_glow_bitmap != -1 ) {
223 gr_set_bitmap( Warp_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1 );
229 #define OUT_PERCENT1 0.80f
230 #define OUT_PERCENT2 0.90f
232 #define IN_PERCENT1 0.10f
233 #define IN_PERCENT2 0.20f
235 if ( life_percent < IN_PERCENT1 ) {
238 } else if ( life_percent < IN_PERCENT2 ) {
239 r *= ( life_percent-IN_PERCENT1 ) / (IN_PERCENT2-IN_PERCENT1);
241 } else if ( life_percent < OUT_PERCENT1 ) {
244 } else if ( life_percent < OUT_PERCENT2 ) {
245 r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2-OUT_PERCENT1);
253 int saved_gr_zbuffering = gr_zbuffer_get();
254 gr_zbuffer_set(GR_ZBUFF_READ);
257 //float Noise[NOISE_NUM_FRAMES] = {
258 int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;
260 r *= (0.40f + Noise[noise_frame]*0.30f);
262 g3_draw_bitmap( &verts[4], 0,r, TMAP_FLAG_TEXTURED );
263 gr_zbuffer_set(saved_gr_zbuffering);
267 gr_zbuffer_set( saved_gr_zbuffering );