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.3 2002/06/17 06:33:08 relnev
19 * ryan's struct patch for gcc 2.95
21 * Revision 1.2 2002/06/09 04:41:16 relnev
22 * added copyright header
24 * Revision 1.1.1.1 2002/05/03 03:28:08 root
28 * 3 7/22/99 1:22p Dave
29 * Enable proper zbuffering for warpin glow effect.
31 * 2 10/07/98 10:52a Dave
34 * 1 10/07/98 10:48a Dave
36 * 23 4/08/98 8:20p John
37 * Made "Apex" of warp effect not move.
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.
43 * 21 3/29/98 12:39p John
44 * Made warp in glow page in
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.
50 * 19 3/18/98 12:36p John
51 * Made hardware have nicer looking warp effect
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.
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
64 * 16 3/04/98 7:07p John
65 * Added debug code to try to normalize a zerolength vector.
67 * 15 2/26/98 3:28p John
68 * fixed optimize compiler warning
70 * 14 2/24/98 6:36p John
71 * Made warp effect draw as a 4 poly cone.
73 * 13 2/22/98 12:19p John
74 * Externalized some strings
76 * 12 1/15/98 9:07p John
77 * Added noise to warp effect glow.
79 * 11 1/15/98 4:58p John
80 * Made warp effect use a looping ani. Made the scaling up & down be in
83 * 10 12/30/97 6:44p John
84 * Made g3_Draw_bitmap functions account for aspect of bitmap.
86 * 9 12/08/97 11:15a John
87 * added parameter to warpout for life.
89 * 8 12/05/97 3:46p John
90 * made ship thruster glow scale instead of being an animation.
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.
96 * 6 10/24/97 12:18p John
97 * sped up warp effect by decreasing number of polys with distance.
99 * 5 9/15/97 5:45p John
100 * took out chunk stuff.
101 * made pofview display thrusters as blue polies.
103 * 4 9/12/97 4:02p John
104 * put in ship warp out effect.
105 * put in dynamic lighting for warp in/out
107 * 3 9/09/97 4:49p John
108 * Almost done ship warp in code
110 * 2 9/08/97 8:39a John
111 * added in code structure for grid
113 * 1 9/05/97 10:07a John
127 #include "floating.h"
129 #include "lighting.h"
132 #include "systemvars.h"
133 #include "animplay.h"
134 #include "fireballs.h"
135 #include "linklist.h"
138 DCF(norm,"normalize a zero length vector")
141 vector tmp = vmd_zero_vector;
142 vm_vec_normalize(&tmp);
146 void draw_face( vertex *v1, vertex *v2, vertex *v3 )
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 ) {
162 g3_draw_poly( 3, vertlist, TMAP_FLAG_TEXTURED );
166 void warpin_render(matrix *orient, vector *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius )
170 int saved_gr_zbuffering = gr_zbuffer_get();
172 // gr_zbuffering = 0;
174 gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
176 float Grid_depth = radius/2.5f;
180 vm_vec_scale_add( ¢er, pos, &orient->v.fvec, -(max_radius/2.5f)/3.0f );
185 vm_vec_scale_add( &vecs[0], ¢er, &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 );
189 vm_vec_scale_add( &vecs[1], ¢er, &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 );
193 vm_vec_scale_add( &vecs[2], ¢er, &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 );
197 vm_vec_scale_add( &vecs[3], ¢er, &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 );
201 // vm_vec_scale_add( &vecs[4], ¢er, &orient->fvec, -Grid_depth );
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;
210 for (i=0; i<5; i++ ) {
211 g3_rotate_vertex( &verts[i], &vecs[i] );
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] );
219 if ( Warp_glow_bitmap != -1 ) {
220 gr_set_bitmap( Warp_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
226 #define OUT_PERCENT1 0.80f
227 #define OUT_PERCENT2 0.90f
229 #define IN_PERCENT1 0.10f
230 #define IN_PERCENT2 0.20f
232 if ( life_percent < IN_PERCENT1 ) {
235 } else if ( life_percent < IN_PERCENT2 ) {
236 r *= ( life_percent-IN_PERCENT1 ) / (IN_PERCENT2-IN_PERCENT1);
238 } else if ( life_percent < OUT_PERCENT1 ) {
241 } else if ( life_percent < OUT_PERCENT2 ) {
242 r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2-OUT_PERCENT1);
250 int saved_gr_zbuffering = gr_zbuffer_get();
251 gr_zbuffer_set(GR_ZBUFF_READ);
254 //float Noise[NOISE_NUM_FRAMES] = {
255 int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;
257 r *= (0.40f + Noise[noise_frame]*0.30f);
259 g3_draw_bitmap( &verts[4], 0,r, TMAP_FLAG_TEXTURED );
260 gr_zbuffer_set(saved_gr_zbuffering);
264 gr_zbuffer_set( saved_gr_zbuffering );