FS2_Open
Open source remastering of the Freespace 2 engine
warpineffect.cpp
Go to the documentation of this file.
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 
13 #include "cmdline/cmdline.h"
14 #include "globalincs/pstypes.h"
15 #include "graphics/tmapper.h"
16 #include "math/vecmat.h"
17 #include "mission/missionparse.h"
18 #include "model/model.h"
19 #include "nebula/neb.h"
20 #include "render/3d.h"
21 #include "ship/ship.h"
22 
23 extern int Warp_model;
24 extern int Warp_glow_bitmap;
25 extern int Warp_ball_bitmap;
26 
27 
29 {
30  vec3d norm;
31  vertex *vertlist[3];
32 
33  vm_vec_perp(&norm,&v1->world, &v2->world, &v3->world);
34  if ( vm_vec_dot(&norm, &v1->world ) >= 0.0 ) {
35  vertlist[0] = v3;
36  vertlist[1] = v2;
37  vertlist[2] = v1;
38  } else {
39  vertlist[0] = v1;
40  vertlist[1] = v2;
41  vertlist[2] = v3;
42  }
43 
45 
46 }
47 
49 {
50  vec3d norm;
51  vertex vertlist[3];
52 
53  vm_vec_perp(&norm,&v1->world, &v2->world, &v3->world);
54  if ( vm_vec_dot(&norm, &v1->world ) >= 0.0 ) {
55  vertlist[0] = *v3;
56  vertlist[1] = *v2;
57  vertlist[2] = *v1;
58  } else {
59  vertlist[0] = *v1;
60  vertlist[1] = *v2;
61  vertlist[2] = *v3;
62  }
63 
64  batch_add_tri(texture, TMAP_FLAG_TEXTURED | TMAP_HTL_3D_UNLIT, vertlist, 1.0f);
65 }
66 
67 void warpin_render(object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d)
68 {
69  vec3d center;
70  vec3d vecs[5];
71  vertex verts[5];
72  int saved_gr_zbuffering = gr_zbuffer_get();
73 
75 
76  vm_vec_scale_add( &center, pos, &orient->vec.fvec, -(max_radius/2.5f)/3.0f );
77 
78  memset(verts, 0, sizeof(verts));
79 
80  if (Warp_glow_bitmap >= 0) {
81  float r = radius;
82  bool render_it = true;
83 
84  #define OUT_PERCENT1 0.80f
85  #define OUT_PERCENT2 0.90f
86 
87  #define IN_PERCENT1 0.10f
88  #define IN_PERCENT2 0.20f
89 
91  {
92  if ( (life_percent >= IN_PERCENT1) && (life_percent < IN_PERCENT2) ) {
93  r *= (life_percent - IN_PERCENT1) / (IN_PERCENT2 - IN_PERCENT1);
94  //render_it = true;
95  } else if ( (life_percent >= OUT_PERCENT1) && (life_percent < OUT_PERCENT2) ) {
96  r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2 - OUT_PERCENT1);
97  //render_it = true;
98  }
99  }
100 
101  if (render_it) {
102  // Add in noise
103  int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;
104 
105  r *= (0.40f + Noise[noise_frame] * 0.30f);
106 
107  // Bobboau's warp thingie, toggled by cmdline
108  if (Cmdline_warp_flash) {
109  r += powf((2.0f * life_percent) - 1.0f, 24.0f) * max_radius * 1.5f;
110  }
111 
112  vecs[4] = center;
113  verts[4].texture_position.u = 0.5f; verts[4].texture_position.v = 0.5f;
114 
115  if (Cmdline_nohtl) {
116  g3_rotate_vertex( &verts[4], &vecs[4] );
117  } else {
118  g3_transfer_vertex( &verts[4], &vecs[4] );
119  }
120 
121  float alpha = (The_mission.flags & MISSION_FLAG_FULLNEB) ? (1.0f - neb2_get_fog_intensity(obj)) : 1.0f;
123 
125  }
126  }
127 
128  if ( (Warp_model >= 0) && (warp_3d || Cmdline_3dwarp) ) {
129  model_render_params render_info;
130 
131  vec3d scale;
132  scale.xyz.z = scale.xyz.y = scale.xyz.x = radius / 25.0f;
133  render_info.set_warp_params(texture_bitmap_num, radius/max_radius, scale);
134 
135  float dist = vm_vec_dist_quick( pos, &Eye_position );
136  render_info.set_detail_level_lock((int)(dist / (radius * 10.0f)));
137 
139 
140  model_render_immediate( &render_info, Warp_model, orient, pos );
141  } else {
142  float Grid_depth = radius/2.5f;
143 
144  gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
145 
146  vm_vec_scale_add( &vecs[0], &center, &orient->vec.uvec, radius );
147  vm_vec_scale_add2( &vecs[0], &orient->vec.rvec, -radius );
148  vm_vec_scale_add2( &vecs[0], &orient->vec.fvec, Grid_depth );
149 
150  vm_vec_scale_add( &vecs[1], &center, &orient->vec.uvec, radius );
151  vm_vec_scale_add2( &vecs[1], &orient->vec.rvec, radius );
152  vm_vec_scale_add2( &vecs[1], &orient->vec.fvec, Grid_depth );
153 
154  vm_vec_scale_add( &vecs[2], &center, &orient->vec.uvec, -radius );
155  vm_vec_scale_add2( &vecs[2], &orient->vec.rvec, radius );
156  vm_vec_scale_add2( &vecs[2], &orient->vec.fvec, Grid_depth );
157 
158  vm_vec_scale_add( &vecs[3], &center, &orient->vec.uvec, -radius );
159  vm_vec_scale_add2( &vecs[3], &orient->vec.rvec, -radius );
160  vm_vec_scale_add2( &vecs[3], &orient->vec.fvec, Grid_depth );
161 
162  // vm_vec_scale_add( &vecs[4], ¢er, &orient->vec.fvec, -Grid_depth );
163  vecs[4] = center;
164 
165  verts[0].texture_position.u = 0.01f;
166  verts[0].texture_position.v = 0.01f;
167 
168  verts[1].texture_position.u = 0.99f;
169  verts[1].texture_position.v = 0.01f;
170 
171  verts[2].texture_position.u = 0.99f;
172  verts[2].texture_position.v = 0.99f;
173 
174  verts[3].texture_position.u = 0.01f;
175  verts[3].texture_position.v = 0.99f;
176 
177  verts[4].texture_position.u = 0.5f;
178  verts[4].texture_position.v = 0.5f;
179 
180  if (Cmdline_nohtl) {
181  g3_rotate_vertex( &verts[0], &vecs[0] );
182  g3_rotate_vertex( &verts[1], &vecs[1] );
183  g3_rotate_vertex( &verts[2], &vecs[2] );
184  g3_rotate_vertex( &verts[3], &vecs[3] );
185  g3_rotate_vertex( &verts[4], &vecs[4] );
186  } else {
187  g3_transfer_vertex( &verts[0], &vecs[0] );
188  g3_transfer_vertex( &verts[1], &vecs[1] );
189  g3_transfer_vertex( &verts[2], &vecs[2] );
190  g3_transfer_vertex( &verts[3], &vecs[3] );
191  g3_transfer_vertex( &verts[4], &vecs[4] );
192  }
193 
194  int cull = gr_set_cull(0); // fixes rendering problem in D3D - taylor
195  draw_face( &verts[0], &verts[4], &verts[1] );
196  draw_face( &verts[1], &verts[4], &verts[2] );
197  draw_face( &verts[4], &verts[3], &verts[2] );
198  draw_face( &verts[0], &verts[3], &verts[4] );
199  gr_set_cull(cull);
200  }
201 
202  if (Warp_ball_bitmap > -1 && Cmdline_warp_flash == 1) {
203  flash_ball warp_ball(20, .1f,.25f, &vmd_z_vector, &vmd_zero_vector, 4.0f, 0.5f);
204  float adg = (2.0f * life_percent) - 1.0f;
205  float pct = (powf(adg, 4.0f) - powf(adg, 128.0f)) * 4.0f;
206 
207  if (pct > 0.00001f) {
208  g3_start_instance_matrix(pos, orient, true);
209 
211 
212  warp_ball.render(max_radius * pct * 0.5f, adg * adg, adg * adg * 6.0f);
213 
214  g3_done_instance(true);
215  }
216  }
217 
218  gr_zbuffer_set( saved_gr_zbuffering );
219 }
220 
221 void warpin_queue_render(draw_list *scene, object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d)
222 {
223  vec3d center;
224  vec3d vecs[5];
225  vertex verts[5];
226 
227  vm_vec_scale_add( &center, pos, &orient->vec.fvec, -(max_radius/2.5f)/3.0f );
228 
229 
230  if (Warp_glow_bitmap >= 0) {
231  float r = radius;
232  bool render_it = true;
233 
234 #define OUT_PERCENT1 0.80f
235 #define OUT_PERCENT2 0.90f
236 
237 #define IN_PERCENT1 0.10f
238 #define IN_PERCENT2 0.20f
239 
240  if (Cmdline_warp_flash)
241  {
242  if ( (life_percent >= IN_PERCENT1) && (life_percent < IN_PERCENT2) ) {
243  r *= (life_percent - IN_PERCENT1) / (IN_PERCENT2 - IN_PERCENT1);
244  //render_it = true;
245  } else if ( (life_percent >= OUT_PERCENT1) && (life_percent < OUT_PERCENT2) ) {
246  r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2 - OUT_PERCENT1);
247  //render_it = true;
248  }
249  }
250 
251  if (render_it) {
252  // Add in noise
253  int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;
254 
255  r *= (0.40f + Noise[noise_frame] * 0.30f);
256 
257  // Bobboau's warp thingie, toggled by cmdline
258  if (Cmdline_warp_flash) {
259  r += powf((2.0f * life_percent) - 1.0f, 24.0f) * max_radius * 1.5f;
260  }
261 
262  vecs[4] = center;
263  verts[4].texture_position.u = 0.5f; verts[4].texture_position.v = 0.5f;
264 
265  if (Cmdline_nohtl) {
266  g3_rotate_vertex( &verts[4], &vecs[4] );
267  } else {
268  g3_transfer_vertex( &verts[4], &vecs[4] );
269  }
270 
271  float alpha = (The_mission.flags & MISSION_FLAG_FULLNEB) ? (1.0f - neb2_get_fog_intensity(obj)) : 1.0f;
272 
274  }
275  }
276 
277  if ( (Warp_model >= 0) && (warp_3d || Cmdline_3dwarp) ) {
278  model_render_params render_info;
279 
280  float scale = radius / 25.0f;
281 
282  vec3d warp_scale;
283 
284  warp_scale.xyz.x = warp_scale.xyz.y = warp_scale.xyz.z = scale;
285 
286  float dist = vm_vec_dist_quick( pos, &Eye_position );
287 
288  render_info.set_warp_params(texture_bitmap_num, radius/max_radius, warp_scale);
289  render_info.set_detail_level_lock((int)(dist / (radius * 10.0f)));
291 
292  model_render_queue( &render_info, scene, Warp_model, orient, pos);
293  } else {
294  float Grid_depth = radius/2.5f;
295 
296  // gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
297 
298  vm_vec_scale_add( &vecs[0], &center, &orient->vec.uvec, radius );
299  vm_vec_scale_add2( &vecs[0], &orient->vec.rvec, -radius );
300  vm_vec_scale_add2( &vecs[0], &orient->vec.fvec, Grid_depth );
301 
302  vm_vec_scale_add( &vecs[1], &center, &orient->vec.uvec, radius );
303  vm_vec_scale_add2( &vecs[1], &orient->vec.rvec, radius );
304  vm_vec_scale_add2( &vecs[1], &orient->vec.fvec, Grid_depth );
305 
306  vm_vec_scale_add( &vecs[2], &center, &orient->vec.uvec, -radius );
307  vm_vec_scale_add2( &vecs[2], &orient->vec.rvec, radius );
308  vm_vec_scale_add2( &vecs[2], &orient->vec.fvec, Grid_depth );
309 
310  vm_vec_scale_add( &vecs[3], &center, &orient->vec.uvec, -radius );
311  vm_vec_scale_add2( &vecs[3], &orient->vec.rvec, -radius );
312  vm_vec_scale_add2( &vecs[3], &orient->vec.fvec, Grid_depth );
313 
314  // vm_vec_scale_add( &vecs[4], ¢er, &orient->vec.fvec, -Grid_depth );
315  vecs[4] = center;
316 
317  verts[0].texture_position.u = 0.01f;
318  verts[0].texture_position.v = 0.01f;
319 
320  verts[1].texture_position.u = 0.99f;
321  verts[1].texture_position.v = 0.01f;
322 
323  verts[2].texture_position.u = 0.99f;
324  verts[2].texture_position.v = 0.99f;
325 
326  verts[3].texture_position.u = 0.01f;
327  verts[3].texture_position.v = 0.99f;
328 
329  verts[4].texture_position.u = 0.5f;
330  verts[4].texture_position.v = 0.5f;
331 
332  if (Cmdline_nohtl) {
333  g3_rotate_vertex( &verts[0], &vecs[0] );
334  g3_rotate_vertex( &verts[1], &vecs[1] );
335  g3_rotate_vertex( &verts[2], &vecs[2] );
336  g3_rotate_vertex( &verts[3], &vecs[3] );
337  g3_rotate_vertex( &verts[4], &vecs[4] );
338  } else {
339  g3_transfer_vertex( &verts[0], &vecs[0] );
340  g3_transfer_vertex( &verts[1], &vecs[1] );
341  g3_transfer_vertex( &verts[2], &vecs[2] );
342  g3_transfer_vertex( &verts[3], &vecs[3] );
343  g3_transfer_vertex( &verts[4], &vecs[4] );
344  }
345 
346  warpin_batch_draw_face( texture_bitmap_num, &verts[0], &verts[4], &verts[1] );
347  warpin_batch_draw_face( texture_bitmap_num, &verts[1], &verts[4], &verts[2] );
348  warpin_batch_draw_face( texture_bitmap_num, &verts[4], &verts[3], &verts[2] );
349  warpin_batch_draw_face( texture_bitmap_num, &verts[0], &verts[3], &verts[4] );
350  }
351 
352  if (Warp_ball_bitmap > -1 && Cmdline_warp_flash == 1) {
353  //flash_ball warp_ball(20, .1f,.25f, &vmd_z_vector, &vmd_zero_vector, 4.0f, 0.5f);
354  flash_ball warp_ball(20, .1f,.25f, &orient->vec.fvec, pos, 4.0f, 0.5f);
355 
356  float adg = (2.0f * life_percent) - 1.0f;
357  float pct = (powf(adg, 4.0f) - powf(adg, 128.0f)) * 4.0f;
358 
359  if (pct > 0.00001f) {
360  warp_ball.render(Warp_ball_bitmap, max_radius * pct * 0.5f, adg * adg, adg * adg * 6.0f);
361  }
362  }
363 }
#define gr_zbuffer_set
Definition: 2d.h:817
void warpin_queue_render(draw_list *scene, object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d)
void render(float rad, float intinsity, float life)
Definition: 3ddraw.cpp:2186
fix Missiontime
Definition: systemvars.cpp:19
#define MR_NO_CULL
Definition: model.h:879
#define MR_NORMAL
Definition: model.h:858
vec3d vmd_z_vector
Definition: vecmat.cpp:27
void vm_vec_scale_add(vec3d *dest, const vec3d *src1, const vec3d *src2, float k)
Definition: vecmat.cpp:266
int Cmdline_3dwarp
Definition: cmdline.cpp:377
#define MISSION_FLAG_FULLNEB
Definition: missionparse.h:70
float v
Definition: pstypes.h:135
void warpin_render(object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d)
#define GR_ZBUFF_READ
Definition: 2d.h:674
ubyte g3_transfer_vertex(vertex *dest, const vec3d *src)
Definition: 3dmath.cpp:84
Definition: pstypes.h:88
void set_flags(uint flags)
#define MR_NO_LIGHTING
Definition: model.h:867
struct vec3d::@225::@227 xyz
#define TMAP_HTL_3D_UNLIT
Definition: tmapper.h:63
void model_render_immediate(model_render_params *render_info, int model_num, matrix *orient, vec3d *pos, int render, bool sort)
GLclampf f
Definition: Glext.h:7097
GLenum GLuint texture
Definition: Glext.h:5872
void set_detail_level_lock(int detail_level_lock)
void vm_vec_scale_add2(vec3d *dest, const vec3d *src, float k)
Definition: vecmat.cpp:284
hull_check orient
Definition: lua.cpp:5049
GLenum GLenum GLenum GLenum GLenum scale
Definition: Glext.h:8503
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
GLfloat GLfloat GLfloat v2
Definition: Glext.h:5640
int Warp_model
Definition: fireballs.cpp:32
float Noise[NOISE_NUM_FRAMES]
Definition: systemvars.cpp:83
void g3_done_instance(bool set_api=false)
Definition: 3dsetup.cpp:341
uv_pair texture_position
Definition: pstypes.h:174
void model_render_queue(model_render_params *interp, draw_list *scene, int model_num, matrix *orient, vec3d *pos)
int Cmdline_nohtl
Definition: cmdline.cpp:438
#define GR_ALPHABLEND_FILTER
Definition: 2d.h:349
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
struct matrix::@228::@230 vec
float neb2_get_fog_intensity(object *obj)
Definition: neb.cpp:1185
void draw_face(vertex *v1, vertex *v2, vertex *v3)
ubyte g3_rotate_vertex(vertex *dest, const vec3d *src)
Definition: 3dmath.cpp:97
#define IN_PERCENT2
int Warp_ball_bitmap
Definition: fireballs.cpp:55
int Warp_glow_bitmap
Definition: fireballs.cpp:54
float u
Definition: pstypes.h:135
#define OUT_PERCENT1
void warpin_batch_draw_face(int texture, vertex *v1, vertex *v2, vertex *v3)
#define IN_PERCENT1
#define gr_set_cull
Definition: 2d.h:838
GLfloat GLfloat v1
Definition: Glext.h:5639
vec3d Eye_position
Definition: 3dsetup.cpp:27
float vm_vec_dist_quick(const vec3d *v0, const vec3d *v1)
Definition: vecmat.cpp:417
#define fl2i(fl)
Definition: floating.h:33
int batch_add_bitmap(int texture, int tmap_flags, vertex *pnt, int orient, float rad, float alpha, float depth)
Definition: grbatch.cpp:724
void set_warp_params(int bitmap, float alpha, vec3d &scale)
void g3_start_instance_matrix(const vec3d *pos, const matrix *orient, bool set_api=true)
Definition: 3dsetup.cpp:249
#define TMAP_FLAG_TEXTURED
Definition: tmapper.h:36
Definition: 3d.h:383
int g3_draw_bitmap(vertex *pos, int orient, float radius, uint tmap_flags, float depth=0.0f)
Definition: 3ddraw.cpp:649
hull_check pos
Definition: lua.cpp:5050
int batch_add_tri(int texture, int tmap_flags, vertex *verts, float alpha)
Definition: grbatch.cpp:828
GLsizei GLsizei GLuint * obj
Definition: Glext.h:5619
float vm_vec_dot(const vec3d *v0, const vec3d *v1)
Definition: vecmat.cpp:312
vec3d * vm_vec_perp(vec3d *dest, const vec3d *p0, const vec3d *p1, const vec3d *p2)
Definition: vecmat.cpp:667
#define GR_BITBLT_MODE_NORMAL
Definition: 2d.h:351
#define OUT_PERCENT2
vec3d world
Definition: pstypes.h:172
#define gr_zbuffer_get
Definition: 2d.h:816
mission The_mission
#define MR_NO_BATCH
Definition: model.h:881
int g3_draw_poly(int nv, vertex **pointlist, uint tmap_flags)
Definition: 3ddraw.cpp:207
GLclampf GLclampf GLclampf alpha
Definition: Glext.h:5177
vec3d vmd_zero_vector
Definition: vecmat.cpp:24
#define NOISE_NUM_FRAMES
Definition: systemvars.h:130
#define MR_NO_FOGGING
Definition: model.h:884
GLfloat GLfloat GLfloat GLfloat v3
Definition: Glext.h:5641
int Cmdline_warp_flash
Definition: cmdline.cpp:380