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/Nebula/Neb.cpp $
18 * Revision 1.9 2004/09/20 01:31:44 theoddone33
21 * Revision 1.8 2003/05/25 02:30:43 taylor
24 * Revision 1.7 2002/06/17 06:33:09 relnev
25 * ryan's struct patch for gcc 2.95
27 * Revision 1.6 2002/06/09 04:41:23 relnev
28 * added copyright header
30 * Revision 1.5 2002/06/01 03:32:00 relnev
31 * fix texture loading mistake.
33 * enable some d3d stuff for opengl also
35 * Revision 1.4 2002/05/26 20:22:48 theoddone33
36 * Most of network/ works
38 * Revision 1.3 2002/05/07 03:16:47 theoddone33
39 * The Great Newline Fix
41 * Revision 1.2 2002/05/04 04:36:56 theoddone33
42 * More changes, took out a lot of the sound stuff which will bite later but
45 * Revision 1.1.1.1 2002/05/03 03:28:10 root
49 * 50 8/30/99 5:01p Dave
50 * Made d3d do less state changing in the nebula. Use new chat server for
53 * 49 8/10/99 6:54p Dave
54 * Mad optimizations. Added paging to the nebula effect.
56 * 48 8/05/99 2:05a Dave
59 * 47 7/30/99 10:55a Anoop
60 * Hmm. Fixed release build problem again, with area-rotated bitmaps.
62 * 46 7/29/99 10:47p Dave
63 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
65 * 44 7/29/99 12:05a Dave
66 * Nebula speed optimizations.
68 * 43 7/19/99 7:20p Dave
69 * Beam tooling. Specialized player-killed-self messages. Fixed d3d nebula
72 * 42 7/18/99 5:20p Dave
73 * Jump node icon. Fixed debris fogging. Framerate warning stuff.
75 * 41 7/13/99 1:15p Dave
76 * 32 bit support. Whee!
78 * 40 7/09/99 5:54p Dave
79 * Seperated cruiser types into individual types. Added tons of new
80 * briefing icons. Campaign screen.
82 * 39 7/07/99 10:44a Jamesa
83 * Make sure the nebula regens properly after loading a mission.
85 * 38 6/11/99 2:32p Dave
86 * Toned down nebula brightness a bit.
88 * 37 5/26/99 3:39p Dave
89 * Fixed nebula regeneration problem. Removed optimizations from
92 * 36 5/26/99 11:46a Dave
93 * Added ship-blasting lighting and made the randomization of lighting
94 * much more customizable.
96 * 35 5/24/99 5:45p Dave
97 * Added detail levels to the nebula, with a decent speedup. Split nebula
98 * lightning into its own section.
111 #include "freespace.h"
114 #include "starfield.h"
119 #include "grinternal.h"
121 #include "alphacolors.h"
123 // --------------------------------------------------------------------------------------------------------
124 // NEBULA DEFINES/VARS
127 // #define NEB2_THUMBNAIL
130 3D CARDS THAT FOG PROPERLY
136 3D CARDS THAT DON'T FOG PROPERLY
141 // if nebula rendering is active (DCF stuff - not mission specific)
142 int Neb2_render_mode = NEB2_RENDER_NONE;
144 // array of neb2 poofs
145 char Neb2_poof_filenames[MAX_NEB2_POOFS][MAX_FILENAME_LEN] = {
146 "", "", "", "", "", ""
148 int Neb2_poofs[MAX_NEB2_POOFS] = { -1, -1, -1, -1, -1, -1 };
149 int Neb2_poof_flags = ( (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) );
150 int Neb2_poof_count = 0;
152 // array of neb2 bitmaps
153 char Neb2_bitmap_filenames[MAX_NEB2_BITMAPS][MAX_FILENAME_LEN] = {
154 "", "", "", "", "", ""
156 int Neb2_bitmap[MAX_NEB2_BITMAPS] = { -1, -1, -1, -1, -1, -1 };
157 int Neb2_bitmap_count = 0;
159 // texture to use for this level
160 char Neb2_texture_name[MAX_FILENAME_LEN] = "";
163 #define NF_USED (1<<0) // if this nebula slot is used
165 float max_rotation = 3.75f;
166 float neb2_flash_fade = 0.3f;
168 // fog values for different ship types
169 float Neb_ship_fog_vals[MAX_SHIP_TYPE_COUNTS][2] = {
170 {0.0f, 0.0f}, // SHIP_TYPE_NONE
171 {10.0f, 500.0f}, // SHIP_TYPE_CARGO
172 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER_BOMBER
173 {10.0f, 600.0f}, // SHIP_TYPE_CRUISER
174 {10.0f, 600.0f}, // SHIP_TYPE_FREIGHTER
175 {10.0f, 750.0f}, // SHIP_TYPE_CAPITAL
176 {10.0f, 500.0f}, // SHIP_TYPE_TRANSPORT
177 {10.0f, 500.0f}, // SHIP_TYPE_REPAIR_REARM
178 {10.0f, 500.0f}, // SHIP_TYPE_NAVBUOY
179 {10.0f, 500.0f}, // SHIP_TYPE_SENTRYGUN
180 {10.0f, 600.0f}, // SHIP_TYPE_ESCAPEPOD
181 {10.0f, 1000.0f}, // SHIP_TYPE_SUPERCAP
182 {10.0f, 500.0f}, // SHIP_TYPE_STEALTH
183 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER
184 {10.0f, 500.0f}, // SHIP_TYPE_BOMBER
185 {10.0f, 750.0f}, // SHIP_TYPE_DRYDOCK
186 {10.0f, 600.0f}, // SHIP_TYPE_AWACS
187 {10.0f, 600.0f}, // SHIP_TYPE_GAS_MINER
188 {10.0f, 600.0f}, // SHIP_TYPE_CORVETTE
189 {10.0f, 1000.0f}, // SHIP_TYPE_KNOSSOS_DEVICE
192 // fog near and far values for rendering the background nebula
193 #define NEB_BACKG_FOG_NEAR 4.5f
194 #define NEB_BACKG_FOG_FAR 10.0f
195 float Neb_backg_fog_near = NEB_BACKG_FOG_NEAR;
196 float Neb_backg_fog_far = NEB_BACKG_FOG_FAR;
199 int pneb_tried = 0; // total pnebs tried to render
200 int pneb_tossed_alpha = 0; // pnebs tossed because of alpha optimization
201 int pneb_tossed_dot = 0; // pnebs tossed because of dot product
202 int pneb_tossed_off = 0; // pnebs tossed because of being offscree
203 int neb_tried = 0; // total nebs tried
204 int neb_tossed_alpha = 0; // nebs tossed because of alpha
205 int neb_tossed_dot = 0; // nebs tossed because of dot product
206 int neb_tossed_count = 0; // nebs tossed because of max render count
208 // the AWACS suppresion level for the nebula
209 float Neb2_awacs = -1.0f;
211 // how many "slices" are in the current player nebuls
214 cube_poof Neb2_cubes[MAX_CPTS][MAX_CPTS][MAX_CPTS];
216 // nebula detail level
217 typedef struct neb2_detail {
218 float max_alpha_glide; // max alpha for this detail level in Glide
219 float max_alpha_d3d; // max alpha for this detail level in D3d
220 float break_alpha; // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
221 float break_x, break_y; // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
222 float cube_dim; // total dimension of player poof cube
223 float cube_inner; // inner radius of the player poof cube
224 float cube_outer; // outer radius of the player pood cube
225 float prad; // radius of the poofs
226 float wj, hj, dj; // width, height, depth jittering. best left at 1.0
228 neb2_detail Neb2_detail[MAX_DETAIL_LEVEL] = {
229 { // lowest detail level
230 0.575f, // max alpha for this detail level in Glide
231 0.71f, // max alpha for this detail level in D3d
232 0.13f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
233 150.0f, 150.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
234 510.0f, // total dimension of player poof cube
235 50.0f, // inner radius of the player poof cube
236 250.0f, // outer radius of the player pood cube
237 120.0f, // radius of the poofs
238 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
240 { // 2nd lowest detail level
241 0.575f, // max alpha for this detail level in Glide
242 0.71f, // max alpha for this detail level in D3d
243 0.125f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
244 300.0f, 300.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
245 550.0f, // total dimension of player poof cube
246 100.0f, // inner radius of the player poof cube
247 250.0f, // outer radius of the player pood cube
248 125.0f, // radius of the poofs
249 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
251 { // 2nd highest detail level
252 0.575f, // max alpha for this detail level in Glide
253 0.71f, // max alpha for this detail level in D3d
254 0.1f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
255 300.0f, 300.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
256 550.0f, // total dimension of player poof cube
257 150.0f, // inner radius of the player poof cube
258 250.0f, // outer radius of the player pood cube
259 125.0f, // radius of the poofs
260 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
262 { // higest detail level
263 0.475f, // max alpha for this detail level in Glide
264 0.575f, // max alpha for this detail level in D3d
265 0.05f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
266 200.0f, 200.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
267 750.0f, // total dimension of player poof cube
268 200.0f, // inner radius of the player poof cube
269 360.0f, // outer radius of the player pood cube
270 150.0f, // radius of the poofs
271 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
274 neb2_detail *Nd = &Neb2_detail[MAX_DETAIL_LEVEL - 2];
276 int Neb2_background_color[3] = {0, 0, 255}; // rgb background color (used for lame rendering)
280 // --------------------------------------------------------------------------------------------------------
281 // NEBULA FORWARD DECLARATIONS
284 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
285 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v);
287 // return an alpha value for a bitmap offscreen based upon "break" value
288 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha);
290 // do a pre-render of the background nebula
291 void neb2_pre_render(vector *eye_pos, matrix *eye_orient);
293 // fill in the position of the eye for this frame
294 void neb2_get_eye_pos(vector *eye);
296 // fill in the eye orient for this frame
297 void neb2_get_eye_orient(matrix *eye);
299 // get a (semi) random bitmap to use for a poof
300 int neb2_get_bitmap();
302 // regenerate the player nebula
306 // --------------------------------------------------------------------------------------------------------
310 // initialize neb2 stuff at game startup
317 // read in the nebula.tbl
318 read_file_text("nebula.tbl");
321 // background bitmaps
322 Neb2_bitmap_count = 0;
323 while(!optional_string("#end")){
325 required_string("+Nebula:");
326 stuff_string(name, F_NAME, NULL);
328 if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){
329 SDL_strlcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name, sizeof(Neb2_bitmap_filenames[0]));
335 while(!optional_string("#end")){
337 required_string("+Poof:");
338 stuff_string(name, F_NAME, NULL);
340 if(Neb2_poof_count < MAX_NEB2_POOFS){
341 SDL_strlcpy(Neb2_poof_filenames[Neb2_poof_count++], name, sizeof(Neb2_poof_filenames[0]));
344 } catch (parse_error_t rval) {
345 Error(LOCATION, "Unable to parse nebula.tbl! Code = %i.\n", (int)rval);
348 // should always have 6 neb poofs
349 SDL_assert(Neb2_poof_count == 6);
354 void neb2_set_detail_level(int level)
358 Nd = &Neb2_detail[0];
361 if(level >= MAX_DETAIL_LEVEL){
362 Nd = &Neb2_detail[MAX_DETAIL_LEVEL-1];
366 Nd = &Neb2_detail[level];
368 // regen the player neb
372 // initialize nebula stuff - call from game_post_level_init(), so the mission has been loaded
373 void neb2_level_init()
377 // standalone servers can bail here
378 if(Game_mode & GM_STANDALONE_SERVER){
382 // if the mission is not a fullneb mission, skip
383 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
384 Neb2_render_mode = NEB2_RENDER_NONE;
390 if(gr_screen.mode == GR_DIRECT3D){
391 max_alpha_player = NEB2_MAX_ALPHA_D3D;
393 max_alpha_player = NEB2_MAX_ALPHA_GLIDE;
397 // by default we'll use pof rendering
398 Neb2_render_mode = NEB2_RENDER_POF;
399 stars_set_background_model(BACKGROUND_MODEL_FILENAME, Neb2_texture_name);
401 // load in all nebula bitmaps
402 for(idx=0; idx<Neb2_poof_count; idx++){
403 if(Neb2_poofs[idx] < 0){
404 Neb2_poofs[idx] = bm_load(Neb2_poof_filenames[idx]);
409 pneb_tossed_alpha = 0;
412 neb_tossed_alpha = 0;
414 neb_tossed_count = 0;
416 // setup proper fogging values
417 Neb_backg_fog_near = NEB_BACKG_FOG_NEAR;
418 Neb_backg_fog_far = NEB_BACKG_FOG_FAR;
424 // shutdown nebula stuff
425 void neb2_level_close()
429 // standalone servers can bail here
430 if(Game_mode & GM_STANDALONE_SERVER){
434 // if the mission is not a fullneb mission, skip
435 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
439 // unload all nebula bitmaps
440 for(idx=0; idx<Neb2_poof_count; idx++){
441 if(Neb2_poofs[idx] >= 0){
442 bm_unload(Neb2_poofs[idx]);
443 Neb2_poofs[idx] = -1;
447 // unflag the mission as being fullneb so stuff doesn't fog in the techdata room :D
448 The_mission.flags &= ~MISSION_FLAG_FULLNEB;
451 // call before beginning all rendering
452 void neb2_render_setup(vector *eye_pos, matrix *eye_orient)
454 // standalone servers can bail here
455 if(Game_mode & GM_STANDALONE_SERVER){
459 // if the mission is not a fullneb mission, skip
460 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
464 // pre-render the real background nebula
465 neb2_pre_render(eye_pos, eye_orient);
473 // load in all nebula bitmaps
474 for(idx=0; idx<Neb2_poof_count; idx++){
475 if((Neb2_poofs[idx] >= 0) && (Neb2_poof_flags & (1<<idx))){
476 bm_page_in_texture(Neb2_poofs[idx]);
481 // should we not render this object because its obscured by the nebula?
482 int neb_skip_opt = 1;
485 neb_skip_opt = !neb_skip_opt;
487 dc_printf("Using neb object skipping!\n");
489 dc_printf("Not using neb object skipping!\n");
492 int neb2_skip_render(object *objp, float z_depth)
494 float fog_near, fog_far;
496 // if we're never skipping
502 if(Neb2_render_mode == NEB2_RENDER_LAME){
506 // get near and far fog values based upon object type and rendering mode
507 neb2_get_fog_values(&fog_near, &fog_far, objp);
510 switch( objp->type ) {
511 // some objects we always render
519 // any weapon over 500 meters away
521 if(z_depth >= 500.0f){
526 // any small ship over the fog limit, or any cruiser 50% further than the fog limit
529 if((objp->instance >= 0) && (Ships[objp->instance].ship_info_index >= 0)){
530 sip = &Ship_info[Ships[objp->instance].ship_info_index];
535 // small ships over the fog limit by a small factor
536 if((sip->flags & SIF_SMALL_SHIP) && (z_depth >= (fog_far * 1.3f))){
541 if((sip->flags & SIF_BIG_SHIP) && (z_depth >= (fog_far * 2.0f))){
546 if((sip->flags & SIF_HUGE_SHIP) && (z_depth >= (fog_far * 3.0f))){
551 // any fireball over the fog limit for small ships
554 if(z_depth >= fog_far){
561 // any debris over the fog limit for small ships
564 if(z_depth >= fog_far){
571 // any asteroids 50% farther than the fog limit for small ships
573 if(z_depth >= (fog_far * 1.5f)){
578 // any countermeasures over 100 meters away
580 if(z_depth >= 100.0f){
585 // hmmm. unknown object type - should probably let it through
594 float neb2_get_lod_scale(int objnum)
600 if((objnum < 0) || (objnum >= MAX_OBJECTS) || (Objects[objnum].type != OBJ_SHIP) || (Objects[objnum].instance < 0) || (Objects[objnum].instance >= MAX_SHIPS)){
603 shipp = &Ships[Objects[objnum].instance];
604 sip = &Ship_info[shipp->ship_info_index];
607 if(sip->flags & SIF_SMALL_SHIP){
609 } else if(sip->flags & SIF_BIG_SHIP){
618 // --------------------------------------------------------------------------------------------------------
619 // NEBULA FORWARD DEFINITIONS
622 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
623 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v)
629 // get the eye position
630 neb2_get_eye_pos(&eye_pos);
632 // determine what alpha to draw this bitmap with
633 // higher alpha the closer the bitmap gets to the eye
634 dist = vm_vec_dist_quick(&eye_pos, v);
636 // if the point is inside the inner radius, alpha is based on distance to the player's eye,
637 // becoming more transparent as it gets close
638 if(dist <= inner_radius){
639 // alpha per meter between the magic # and the inner radius
640 alpha = Nd->max_alpha_glide / (inner_radius - magic_num);
642 // above value times the # of meters away we are
643 alpha *= (dist - magic_num);
644 return alpha < 0.0f ? 0.0f : alpha;
646 // if the point is outside the inner radius, it starts out as completely transparent at max
647 // outer radius, and becomes more opaque as it moves towards inner radius
648 else if(dist <= outer_radius){
649 // alpha per meter between the outer radius and the inner radius
650 alpha = Nd->max_alpha_glide / (outer_radius - inner_radius);
652 // above value times the range between the outer radius and the poof
653 return alpha < 0.0f ? 0.0f : alpha * (outer_radius - dist);
656 // otherwise transparent
660 // return an alpha value for a bitmap offscreen based upon "break" value
661 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha)
664 float per_pixel_x = incoming_alpha / (float)Nd->break_x;
665 float per_pixel_y = incoming_alpha / (float)Nd->break_y;
666 int off_x = ((sx < 0.0f) || (sx > (float)gr_screen.max_w));
667 int off_y = ((sy < 0.0f) || (sy > (float)gr_screen.max_h));
668 float off_x_amount = 0.0f;
669 float off_y_amount = 0.0f;
671 // determine how many pixels outside we are
674 off_x_amount = fl_abs(sx);
676 off_x_amount = sx - (float)gr_screen.max_w;
681 off_y_amount = fl_abs(sy);
683 off_y_amount = sy - (float)gr_screen.max_h;
689 // offscreen X and Y - and Y is greater
690 if(off_y && (off_y_amount > off_x_amount)){
691 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
693 alpha = incoming_alpha - (off_x_amount * per_pixel_x);
698 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
700 // should never get here
705 return alpha < 0.0f ? 0.0f : alpha;
708 // -------------------------------------------------------------------------------------------------
709 // WACKY LOCAL PLAYER NEBULA STUFF
717 float ws = Nd->cube_dim / (float)Neb2_slices;
718 float hs = Nd->cube_dim / (float)Neb2_slices;
719 float ds = Nd->cube_dim / (float)Neb2_slices;
721 // get the eye position
722 neb2_get_eye_pos(&eye_pos);
724 // check left, right (0, and 1, x and -x)
725 if(cube_cen.xyz.x - eye_pos.xyz.x > ws){
728 } else if(eye_pos.xyz.x - cube_cen.xyz.x > ws){
733 // check up, down (2, and 3, y and -y)
734 if(cube_cen.xyz.y - eye_pos.xyz.y > hs){
737 } else if(eye_pos.xyz.y - cube_cen.xyz.y > hs){
742 // check front, back (4, and 5, z and -z)
743 if(cube_cen.xyz.z - eye_pos.xyz.z > ds){
746 } else if(eye_pos.xyz.z - cube_cen.xyz.z > ds){
755 void neb2_copy(int xyz, int src, int dest)
761 for(idx1=0; idx1<Neb2_slices; idx1++){
762 for(idx2=0; idx2<Neb2_slices; idx2++){
763 Neb2_cubes[dest][idx1][idx2] = Neb2_cubes[src][idx1][idx2];
768 for(idx1=0; idx1<Neb2_slices; idx1++){
769 for(idx2=0; idx2<Neb2_slices; idx2++){
770 Neb2_cubes[idx1][dest][idx2] = Neb2_cubes[idx1][src][idx2];
775 for(idx1=0; idx1<Neb2_slices; idx1++){
776 for(idx2=0; idx2<Neb2_slices; idx2++){
777 Neb2_cubes[idx1][idx2][dest] = Neb2_cubes[idx1][idx2][src];
787 void neb2_gen_slice(int xyz, int src, vector *cube_center)
790 float h_incw, h_inch, h_incd;
795 ws = Nd->cube_dim / (float)Neb2_slices;
797 hs = Nd->cube_dim / (float)Neb2_slices;
799 ds = Nd->cube_dim / (float)Neb2_slices;
801 cube_corner = *cube_center;
802 cube_corner.xyz.x -= (Nd->cube_dim / 2.0f);
803 cube_corner.xyz.y -= (Nd->cube_dim / 2.0f);
804 cube_corner.xyz.z -= (Nd->cube_dim / 2.0f);
807 for(idx1=0; idx1<Neb2_slices; idx1++){
808 for(idx2=0; idx2<Neb2_slices; idx2++){
809 v = &Neb2_cubes[src][idx1][idx2].pt;
811 v->xyz.x = h_incw + (ws * (float)src) + frand_range(-Nd->wj, Nd->wj);
812 v->xyz.y = h_inch + (hs * (float)idx1) + frand_range(-Nd->hj, Nd->hj);
813 v->xyz.z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
814 vm_vec_add2(v, &cube_corner);
817 Neb2_cubes[src][idx1][idx2].bmap = neb2_get_bitmap();
819 // set the rotation speed
820 Neb2_cubes[src][idx1][idx2].rot = 0.0f;
821 Neb2_cubes[src][idx1][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
822 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
827 for(idx1=0; idx1<Neb2_slices; idx1++){
828 for(idx2=0; idx2<Neb2_slices; idx2++){
829 v = &Neb2_cubes[idx1][src][idx2].pt;
831 v->xyz.x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
832 v->xyz.y = h_inch + (hs * (float)src) + frand_range(-Nd->hj, Nd->hj);
833 v->xyz.z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
834 vm_vec_add2(v, &cube_corner);
837 Neb2_cubes[idx1][src][idx2].bmap = neb2_get_bitmap();
839 // set the rotation speed
840 Neb2_cubes[idx1][src][idx2].rot = 0.0f;
841 Neb2_cubes[idx1][src][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
842 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
847 for(idx1=0; idx1<Neb2_slices; idx1++){
848 for(idx2=0; idx2<Neb2_slices; idx2++){
849 v = &Neb2_cubes[idx1][idx2][src].pt;
851 v->xyz.x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
852 v->xyz.y = h_inch + (hs * (float)idx2) + frand_range(-Nd->hj, Nd->hj);
853 v->xyz.z = h_incd + (ds * (float)src) + frand_range(-Nd->dj, Nd->dj);
854 vm_vec_add2(v, &cube_corner);
857 Neb2_cubes[idx1][idx2][src].bmap = neb2_get_bitmap();
859 // set the rotation speed
860 Neb2_cubes[idx1][idx2][src].rot = 0.0f;
861 Neb2_cubes[idx1][idx2][src].rot_speed = frand_range(-max_rotation, max_rotation);
862 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
872 // regenerate the player nebula
879 mprintf(("Regenerating local nebula!\n"));
881 // get eye position and orientation
882 neb2_get_eye_pos(&eye_pos);
883 neb2_get_eye_orient(&eye_orient);
885 // determine the corner of the cube
888 // generate slices of the cube
889 for(idx=0; idx<Neb2_slices; idx++){
890 neb2_gen_slice(0, idx, &cube_cen);
894 float max_area = 100000000.0f;
897 dc_get_arg(ARG_FLOAT);
898 max_area = Dc_arg_float;
901 float g3_draw_rotated_bitmap_area(vertex *pnt, float angle, float rad, uint tmap_flags, float area);
903 int frames_total = 0;
906 void neb2_render_player()
909 int idx1, idx2, idx3;
917 float frame_area = max_area;
918 float total_area = 0.0f;
921 // standalone servers can bail here
922 if(Game_mode & GM_STANDALONE_SERVER){
926 // if the mission is not a fullneb mission, skip
927 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
936 // don't render in lame mode
937 if((Neb2_render_mode == NEB2_RENDER_LAME) || (Neb2_render_mode == NEB2_RENDER_NONE)){
941 // get eye position and orientation
942 neb2_get_eye_pos(&eye_pos);
943 neb2_get_eye_orient(&eye_orient);
945 // maybe swap stuff around if the player crossed a "border"
946 for(idx2=0; idx2<3; idx2++){
947 switch(crossed_border()){
952 cube_cen.xyz.x -= Nd->cube_dim / (float)Neb2_slices;
953 for(idx1=Neb2_slices-1; idx1>0; idx1--){
954 neb2_copy(0, idx1-1, idx1);
956 neb2_gen_slice(0, 0, &cube_cen);
960 cube_cen.xyz.x += Nd->cube_dim / (float)Neb2_slices;
961 for(idx1=0; idx1<Neb2_slices-1; idx1++){
962 neb2_copy(0, idx1+1, idx1);
964 neb2_gen_slice(0, Neb2_slices - 1, &cube_cen);
968 cube_cen.xyz.y -= Nd->cube_dim / (float)Neb2_slices;
969 for(idx1=Neb2_slices-1; idx1>0; idx1--){
970 neb2_copy(1, idx1-1, idx1);
972 neb2_gen_slice(1, 0, &cube_cen);
976 cube_cen.xyz.y += Nd->cube_dim / (float)Neb2_slices;
977 for(idx1=0; idx1<Neb2_slices-1; idx1++){
978 neb2_copy(1, idx1+1, idx1);
980 neb2_gen_slice(1, Neb2_slices - 1, &cube_cen);
984 cube_cen.xyz.z -= Nd->cube_dim / (float)Neb2_slices;
985 for(idx1=Neb2_slices-1; idx1>0; idx1--){
986 neb2_copy(2, idx1-1, idx1);
988 neb2_gen_slice(2, 0, &cube_cen);
992 cube_cen.xyz.z += Nd->cube_dim / (float)Neb2_slices;
993 for(idx1=0; idx1<Neb2_slices-1; idx1++){
994 neb2_copy(2, idx1+1, idx1);
996 neb2_gen_slice(2, Neb2_slices - 1, &cube_cen);
1001 // if we've switched nebula rendering off
1002 if(Neb2_render_mode == NEB2_RENDER_NONE){
1007 // render the nebula
1008 for(idx1=0; idx1<Neb2_slices; idx1++){
1009 for(idx2=0; idx2<Neb2_slices; idx2++){
1010 for(idx3=0; idx3<Neb2_slices; idx3++){
1014 Neb2_cubes[idx1][idx2][idx3].rot += (Neb2_cubes[idx1][idx2][idx3].rot_speed * flFrametime);
1015 if(Neb2_cubes[idx1][idx2][idx3].rot >= 360.0f){
1016 Neb2_cubes[idx1][idx2][idx3].rot = 0.0f;
1019 // optimization 1 - don't draw backfacing poly's
1021 if(vm_vec_dot_to_point(&eye_orient.v.fvec, &eye_pos, &Neb2_cubes[idx1][idx2][idx3].pt) <= 0.0f){
1026 // rotate and project the vertex into viewspace
1027 g3_rotate_vertex(&p, &Neb2_cubes[idx1][idx2][idx3].pt);
1029 g3_project_vertex(&ptemp);
1031 // get the proper alpha value
1032 alpha = neb2_get_alpha_2shell(Nd->cube_inner, Nd->cube_outer, Nd->prad/4.0f, &Neb2_cubes[idx1][idx2][idx3].pt);
1034 // optimization 2 - don't draw 0.0f or less poly's
1035 // this amounts to big savings
1036 if(alpha <= Nd->break_alpha){
1037 pneb_tossed_alpha++;
1041 // drop poly's which are offscreen at all
1042 // if the poly's are offscreen
1043 if((ptemp.sx < 0.0f) || (ptemp.sx > (float)gr_screen.max_w) || (ptemp.sy < 0.0f) || (ptemp.sy > (float)gr_screen.max_h) ){
1044 alpha = neb2_get_alpha_offscreen(ptemp.sx, ptemp.sy, alpha);
1047 // optimization 2 - don't draw 0.0f or less poly's
1048 // this amounts to big savings
1049 if(alpha <= Nd->break_alpha){
1050 pneb_tossed_alpha++;
1054 // set the bitmap and render
1055 gr_set_bitmap(Neb2_cubes[idx1][idx2][idx3].bmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha + Neb2_cubes[idx1][idx2][idx3].flash, -1, -1);
1058 this_area = g3_draw_rotated_bitmap_area(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED, max_area);
1059 total_area += this_area;
1060 frame_area -= this_area;
1063 g3_draw_rotated_bitmap(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED);
1069 frames_total += frame_rendered;
1071 frame_avg = (float)frames_total / (float)frame_count;
1073 // gr_set_color_fast(&Color_bright_red);
1074 // gr_printf(30, 100, "Area %.3f", total_area);
1075 #ifdef NEB2_THUMBNAIL
1078 gr_set_bitmap(tbmap);
1084 // call this when the player's viewpoint has changed, this will cause the code to properly reset
1085 // the eye's local poofs
1086 void neb2_eye_changed()
1091 // get near and far fog values based upon object type and rendering mode
1092 void neb2_get_fog_values(float *fnear, float *ffar, object *objp)
1096 // default values in case something truly nasty happens
1100 // determine what fog index to use
1101 if(objp->type == OBJ_SHIP){
1102 SDL_assert((objp->instance >= 0) && (objp->instance < MAX_SHIPS));
1103 if((objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
1104 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1106 fog_index = ship_query_general_type(objp->instance);
1107 SDL_assert(fog_index >= 0);
1109 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1113 // fog everything else like a fighter
1115 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1119 *fnear = Neb_ship_fog_vals[fog_index][0];
1120 *ffar = Neb_ship_fog_vals[fog_index][1];
1123 // given a position in space, return a value from 0.0 to 1.0 representing the fog level
1124 float neb2_get_fog_intensity(object *obj)
1126 float f_near, f_far, pct;
1128 // get near and far fog values based upon object type and rendering mode
1129 neb2_get_fog_values(&f_near, &f_far, obj);
1132 pct = vm_vec_dist_quick(&Eye_position, &obj->pos) / (f_far - f_near);
1135 } else if(pct > 1.0f){
1142 // fogging stuff --------------------------------------------------------------------
1144 // do a pre-render of the background nebula
1146 ubyte tpixels[ESIZE * ESIZE * 4]; // for 32 bits
1147 int last_esize = -1;
1148 int this_esize = ESIZE;
1149 extern float Viewer_zoom;
1150 float ex_scale, ey_scale;
1152 void neb2_pre_render(vector *eye_pos, matrix *eye_orient)
1154 // bail early in lame and poly modes
1155 if(Neb2_render_mode != NEB2_RENDER_POF){
1159 // set the view clip
1160 gr_screen.clip_width = this_esize;
1161 gr_screen.clip_height = this_esize;
1162 g3_start_frame(1); // Turn on zbuffering
1163 g3_set_view_matrix(eye_pos, eye_orient, Viewer_zoom);
1164 gr_set_clip(0, 0, this_esize, this_esize);
1166 // render the background properly
1167 // hack - turn off nebula stuff
1168 int neb_save = Neb2_render_mode;
1169 Neb2_render_mode = NEB2_RENDER_NONE;
1171 // draw background stuff nebula
1172 extern void stars_draw_background();
1173 stars_draw_background();
1175 Neb2_render_mode = neb_save;
1178 gr_get_region(0, this_esize, this_esize, (ubyte*)tpixels);
1180 #ifdef NEB2_THUMBNAIL
1182 tbmap = bm_create(16, this_esize, this_esize, tpixels, 0);
1183 bm_lock(tbmap, 16, 0);
1188 // maybe do some swizzling
1195 // if the size has changed between frames, make a new bitmap
1196 if(this_esize != last_esize){
1197 last_esize = this_esize;
1199 // recalculate ex_scale and ey_scale values for looking up color values
1200 ex_scale = (float)this_esize / (float)gr_screen.max_w;
1201 ey_scale = (float)this_esize / (float)gr_screen.max_h;
1204 // restore the game clip stuff
1205 extern void game_set_view_clip();
1206 game_set_view_clip();
1209 // wacky scheme for smoothing colors
1210 int wacky_scheme = 3;
1212 // get the color of the pixel in the small pre-rendered background nebula
1213 #define PIXEL_INDEX_SMALL(xv, yv) ( (this_esize * (yv) * gr_screen.bytes_per_pixel) + ((xv) * gr_screen.bytes_per_pixel) )
1214 void neb2_get_pixel(int x, int y, int *r, int *g, int *b)
1221 // if we're in lame rendering mode, return a constant value
1222 if(Neb2_render_mode == NEB2_RENDER_LAME){
1223 *r = Neb2_background_color[0];
1224 *g = Neb2_background_color[1];
1225 *b = Neb2_background_color[2];
1230 // get the proper pixel index to be looking up
1233 // select screen format
1234 BM_SELECT_SCREEN_FORMAT();
1236 // pixel plus all immediate neighbors (on the small screen - should be more effective than 2 or 1)
1237 xs = (int)(ex_scale * x);
1238 ys = (int)(ey_scale * y);
1240 // sometimes goes over by 1 in direct3d
1241 if(ys >= (this_esize - 1)){
1246 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys)], &rv, &gv, &bv, NULL);
1252 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys)], &rv, &gv, &bv, NULL); // left
1258 if(xs < this_esize - 1){
1259 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys)], &rv, &gv, &bv, NULL); // right
1266 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys - 1)], &rv, &gv, &bv, NULL); // top
1272 if(ys < this_esize - 2){
1273 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys + 1)], &rv, &gv, &bv, NULL); // bottom
1280 if((xs > 0) && (ys > 0)){
1281 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys - 1)], &rv, &gv, &bv, NULL); // upper left
1287 if((xs < this_esize - 1) && (ys < this_esize - 1)){
1288 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys + 1)], &rv, &gv, &bv, NULL); // lower right
1294 if((ys > 0) && (xs < this_esize - 1)){
1295 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys - 1)], &rv, &gv, &bv, NULL); // lower left
1301 if((ys < this_esize - 1) && (xs > 0)){
1302 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys + 1)], &rv, &gv, &bv, NULL); // upper right
1309 rv = (ubyte) (ra / avg_count);
1310 gv = (ubyte) (ga / avg_count);
1311 bv = (ubyte) (ba / avg_count);
1319 // get the color to fog the background color to
1320 void neb2_get_backg_color(int *r, int *g, int *b)
1322 *r = Neb2_background_color[0];
1323 *g = Neb2_background_color[1];
1324 *b = Neb2_background_color[2];
1327 // set the background color
1328 void neb2_set_backg_color(int r, int g, int b)
1330 Neb2_background_color[0] = r;
1331 Neb2_background_color[1] = g;
1332 Neb2_background_color[2] = b;
1335 // fill in the position of the eye for this frame
1336 void neb2_get_eye_pos(vector *eye)
1338 *eye = Eye_position;
1341 // fill in the eye orient for this frame
1342 void neb2_get_eye_orient(matrix *eye)
1347 // get a (semi) random bitmap to use for a poof
1348 int neb2_get_bitmap()
1352 static int neb2_choose = 0;
1354 // get a random count
1355 count = (int)frand_range(1.0f, 5.0f);
1359 // don't cycle too many times
1362 if(neb2_choose == MAX_NEB2_POOFS - 1){
1369 } while(!(Neb2_poof_flags & (1<<neb2_choose)) && (huh < 10));
1375 if(Neb2_poofs[neb2_choose] < 0){
1376 return Neb2_poofs[0];
1378 return Neb2_poofs[neb2_choose];
1381 // nebula DCF functions ------------------------------------------------------
1383 DCF(neb2, "list nebula console commands")
1385 dc_printf("neb2_fog <X> <float> <float> : set near and far fog planes for ship type X\n");
1386 dc_printf("where X is an integer from 1 - 11\n");
1387 dc_printf("1 = cargo containers, 2 = fighters/bombers, 3 = cruisers\n");
1388 dc_printf("4 = freighters, 5 = capital ships, 6 = transports, 7 = support ships\n");
1389 dc_printf("8 = navbuoys, 9 = sentryguns, 10 = escape pods, 11 = background nebula polygons\n\n");
1391 dc_printf("neb2_max_alpha : max alpha value (0.0 to 1.0) for cloud poofs. 0.0 is completely transparent\n");
1392 dc_printf("neb2_break_alpha : alpha value (0.0 to 1.0) at which faded polygons are not drawn. higher values generally equals higher framerate, with more visual cloud popping\n");
1393 dc_printf("neb2_break_off : how many pixels offscreen (left, right, top, bottom) when a cloud poof becomes fully transparent. Lower values cause quicker fading\n");
1394 dc_printf("neb2_smooth : magic fog smoothing modes (0 - 3)\n");
1395 dc_printf("neb2_select : <int> <int> where the first # is the bitmap to be adjusting (0 through 5), and the second int is a 0 or 1, to turn off and on\n");
1396 dc_printf("neb2_rot : set max rotation speed for poofs\n");
1397 dc_printf("neb2_prad : set cloud poof radius\n");
1398 dc_printf("neb2_cdim : poof cube dimension\n");
1399 dc_printf("neb2_cinner : poof cube inner dimension\n");
1400 dc_printf("neb2_couter : poof cube outer dimension\n");
1401 dc_printf("neb2_jitter : poof jitter\n");
1402 dc_printf("neb2_mode : switch between no nebula, polygon background, amd pof background (0, 1 and 2 respectively)\n\n");
1403 dc_printf("neb2_ff : flash fade/sec\n");
1404 dc_printf("neb2_background : rgb background color\n");
1406 dc_printf("neb2_fog_vals : display all the current settings for all above values\n");
1411 dc_get_arg(ARG_FLOAT);
1412 Nd->prad = Dc_arg_float;
1416 dc_get_arg(ARG_FLOAT);
1417 Nd->cube_dim = Dc_arg_float;
1420 DCF(neb2_cinner, "")
1422 dc_get_arg(ARG_FLOAT);
1423 Nd->cube_inner = Dc_arg_float;
1426 DCF(neb2_couter, "")
1428 dc_get_arg(ARG_FLOAT);
1429 Nd->cube_outer = Dc_arg_float;
1432 DCF(neb2_jitter, "")
1434 dc_get_arg(ARG_FLOAT);
1435 Nd->hj = Nd->dj = Nd->wj = Dc_arg_float;
1442 dc_get_arg(ARG_INT);
1444 dc_get_arg(ARG_FLOAT);
1445 fnear = Dc_arg_float;
1446 dc_get_arg(ARG_FLOAT);
1447 ffar = Dc_arg_float;
1449 if((index >= 1) && (index <= 11) && (fnear >= 0.0f) && (ffar >= 0.0f) && (ffar > fnear)){
1451 Neb_backg_fog_near = fnear;
1452 Neb_backg_fog_far = ffar;
1454 Neb_ship_fog_vals[index][0] = fnear;
1455 Neb_ship_fog_vals[index][1] = ffar;
1460 DCF(neb2_max_alpha, "")
1462 dc_get_arg(ARG_FLOAT);
1463 Nd->max_alpha_glide = Dc_arg_float;
1466 DCF(neb2_break_alpha, "")
1468 dc_get_arg(ARG_FLOAT);
1469 Nd->break_alpha = Dc_arg_float;
1472 DCF(neb2_break_off, "")
1474 dc_get_arg(ARG_INT);
1475 Nd->break_y = (float)Dc_arg_int;
1476 Nd->break_x = Nd->break_y * 1.3333f;
1479 DCF(neb2_smooth, "")
1482 dc_get_arg(ARG_INT);
1484 if((index >= 0) && (index <= 3)){
1485 wacky_scheme = index;
1489 DCF(neb2_select, "")
1491 dc_get_arg(ARG_INT);
1492 int bmap = Dc_arg_int;
1493 if((bmap >= 0) && (bmap < Neb2_poof_count)){
1494 dc_get_arg(ARG_INT);
1497 Neb2_poof_flags |= (1<<bmap);
1499 Neb2_poof_flags &= ~(1<<bmap);
1506 dc_get_arg(ARG_FLOAT);
1507 max_rotation = Dc_arg_float;
1512 dc_get_arg(ARG_FLOAT);
1513 neb2_flash_fade = Dc_arg_float;
1518 dc_get_arg(ARG_INT);
1521 case NEB2_RENDER_NONE:
1522 Neb2_render_mode = NEB2_RENDER_NONE;
1525 case NEB2_RENDER_POLY:
1526 Neb2_render_mode = NEB2_RENDER_POLY;
1529 case NEB2_RENDER_POF:
1530 Neb2_render_mode = NEB2_RENDER_POF;
1531 stars_set_background_model(BACKGROUND_MODEL_FILENAME, "Eraseme3");
1534 case NEB2_RENDER_LAME:
1535 Neb2_render_mode = NEB2_RENDER_LAME;
1540 DCF(neb2_slices, "")
1542 dc_get_arg(ARG_INT);
1543 Neb2_slices = Dc_arg_int;
1547 DCF(neb2_background, "")
1551 dc_get_arg(ARG_INT);
1553 dc_get_arg(ARG_INT);
1555 dc_get_arg(ARG_INT);
1558 Neb2_background_color[0] = r;
1559 Neb2_background_color[1] = g;
1560 Neb2_background_color[2] = b;
1563 DCF(neb2_fog_vals, "")
1565 dc_printf("neb2_fog : \n");
1567 dc_printf("(1)cargo containers : %f, %f\n", Neb_ship_fog_vals[1][0], Neb_ship_fog_vals[1][1]);
1568 dc_printf("(2)fighters/bombers : %f, %f\n", Neb_ship_fog_vals[2][0], Neb_ship_fog_vals[2][1]);
1569 dc_printf("(3)cruisers : %f, %f\n", Neb_ship_fog_vals[3][0], Neb_ship_fog_vals[3][1]);
1570 dc_printf("(4)freighters : %f, %f\n", Neb_ship_fog_vals[4][0], Neb_ship_fog_vals[4][1]);
1571 dc_printf("(5)cap ships : %f, %f\n", Neb_ship_fog_vals[5][0], Neb_ship_fog_vals[5][1]);
1572 dc_printf("(6)transports : %f, %f\n", Neb_ship_fog_vals[6][0], Neb_ship_fog_vals[6][1]);
1573 dc_printf("(7)support ships : %f, %f\n", Neb_ship_fog_vals[7][0], Neb_ship_fog_vals[7][1]);
1574 dc_printf("(8)navbuoys : %f, %f\n", Neb_ship_fog_vals[8][0], Neb_ship_fog_vals[8][1]);
1575 dc_printf("(9)sentry guns : %f, %f\n", Neb_ship_fog_vals[9][0], Neb_ship_fog_vals[9][1]);
1576 dc_printf("(10)escape pods : %f, %f\n", Neb_ship_fog_vals[10][0], Neb_ship_fog_vals[10][1]);
1577 dc_printf("(11)background polys : %f, %f\n\n", Neb_backg_fog_near, Neb_backg_fog_far);
1579 dc_printf("neb2_max_alpha : %f\n", Nd->max_alpha_glide);
1580 dc_printf("neb2_break_alpha : %f\n", Nd->break_alpha);
1581 dc_printf("neb2_break_off : %d\n", (int)Nd->break_y);
1582 dc_printf("neb2_smooth : %d\n", wacky_scheme);
1583 dc_printf("neb2_toggle : %s\n", Neb2_render_mode ? "on" : "off");
1584 dc_printf("neb2_rot : %f\n", max_rotation);
1585 dc_printf("neb2_prad : %f\n", Nd->prad);
1586 dc_printf("neb2_cdim : %f\n", Nd->cube_dim);
1587 dc_printf("neb2_couter : %f\n", Nd->cube_outer);
1588 dc_printf("neb2_cinner : %f\n", Nd->cube_inner);
1589 dc_printf("neb2_jitter : %f\n", Nd->wj);
1590 dc_printf("neb2_ff : %f\n", neb2_flash_fade);
1591 dc_printf("neb2_background : %d %d %d\n", Neb2_background_color[0], Neb2_background_color[1], Neb2_background_color[2]);
1595 DCF(neb2_create, "create a basic nebula")
1601 dc_get_arg(ARG_INT);
1602 if(Dc_arg_type & ARG_INT){
1603 points = Dc_arg_int;
1605 dc_get_arg(ARG_FLOAT);
1606 if(Dc_arg_type & ARG_FLOAT){
1607 rad1 = Dc_arg_float;
1609 dc_get_arg(ARG_FLOAT);
1610 if(Dc_arg_type & ARG_FLOAT){
1611 rad2 = Dc_arg_float;
1613 neb2_create(&vmd_zero_vector, points, rad1, -1.0f, rad2);
1616 DCF(neb2_del, "delete existing nebulae")
1618 for(int idx=0; idx<MAX_OBJECTS; idx++){
1619 if(Objects[idx].type == OBJ_NEB2){
1626 float magic1 = 1000.0f;
1627 float magic2 = -1.0f;
1628 float magic3 = 700.0f;
1629 DCF(neb2_def, "create a default nebula")
1632 vm_vec_make(&a, 0.0f, 0.0f, 0.0f);
1633 vm_vec_make(&b, 3600.0f, 700.0f, 0.0f);
1634 vm_vec_make(&c, -3000.0f, 20.0f, 480.0f);
1635 vm_vec_make(&d, -4000.0f, 100.0f, 100.0f);
1636 vm_vec_make(&e, 0.0f, 3000.0f, -400.0f);
1637 vm_vec_make(&f, 670.0f, -2500.0f, -1600.0f);
1639 neb2_create(&a, magic0, magic1, magic2, magic3);
1640 neb2_create(&b, magic0, magic1, magic2, magic3);
1641 neb2_create(&c, magic0, magic1, magic2, magic3);
1642 neb2_create(&d, magic0, magic1, magic2, magic3);
1643 neb2_create(&e, magic0, magic1, magic2, magic3);
1644 neb2_create(&f, magic0, magic1, magic2, magic3);
1647 DCF(neb2_plr, "regenerate the player's nebula")
1652 DCF(neb2_stats, "display info about the nebula rendering")
1654 dc_printf("Player poofs tried : %d\n", pneb_tried);
1655 dc_printf("Player poofs tossed (alpha): %d\n", pneb_tossed_alpha);
1656 dc_printf("Player poofs tossed (dot): %d\n", pneb_tossed_dot);
1657 dc_printf("Player poofs tossed (off): %d\n", pneb_tossed_off);
1659 dc_printf("Poofs tried : %d\n", neb_tried);
1660 dc_printf("Poofs tossed (alpha): %d\n", neb_tossed_alpha);
1661 dc_printf("Poofs tossed (dot): %d\n", neb_tossed_dot);
1662 dc_printf("Poofs tossed (count): %d\n", neb_tossed_count);
1664 dc_printf("Avg poofs/frame: %f\n", frame_avg);
1667 // create a nebula object, return objnum of the nebula or -1 on fail
1668 // NOTE : in most cases you will want to pass -1.0f for outer_radius. Trust me on this
1669 int neb2_create(vector *offset, int num_poofs, float inner_radius, float outer_radius, float max_poof_radius)
1675 // delete a nebula object
1676 void neb2_delete(object *objp)
1681 // renders a nebula object
1682 void neb2_render(object *objp)
1687 // preprocess the nebula object before simulation
1688 void neb2_process_pre(object *objp)
1693 // process the nebula object after simulating, but before rendering
1694 void neb2_process_post(object *objp)
1701 // add N poofs to the inner shell of the nebula
1702 // if orient and ang are specified, generate the poofs so that they are "visible" around
1703 // the orient v.fvec in a cone of ang degrees
1704 void neb2_add_inner(neb2 *neb, int num_poofs, matrix *orient, float ang)
1707 vector pt, pt2, pt3;
1708 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1710 // add the points a pick a random bitmap
1711 for(idx=neb->num_poofs; idx<final_index; idx++){
1713 // put a point directly in front of the player, between 0 and inner_radius distance away
1714 vm_vec_copy_scale(&pt, &orient->v.fvec, frand_range(neb->magic_num, neb->inner_radius));
1716 // rotate the point by -ang <-> ang around the up vector
1717 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1719 // rotate the point by -ang <-> ang around the right vector
1720 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1722 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1723 vm_vec_add(&neb->pts[idx], &pt3, &Objects[neb->objnum].pos);
1725 neb->pts[idx].xyz.x = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.xyz.x;
1726 neb->pts[idx].xyz.y = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.xyz.y;
1727 neb->pts[idx].xyz.z = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.xyz.z;
1730 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1735 // add N poofs to the outer shell of the nebula
1736 // if orient and ang are specified, generate the poofs so that they are "visible" around
1737 // the orient v.fvec in a cone of ang degrees
1738 void neb2_add_outer(neb2 *neb, int num_poofs, matrix *orient, float ang)
1742 vector pt, pt2, pt3;
1743 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1745 // add the points a pick a random bitmap
1746 for(idx=neb->num_poofs; idx<final_index; idx++){
1748 // put a point directly in front of the player, at outer_radius distance away
1749 vm_vec_copy_scale(&pt, &orient->v.fvec, neb->outer_radius);
1751 // rotate the point by -ang <-> ang around the up vector
1752 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1754 // rotate the point by -ang <-> ang around the right vector
1755 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1757 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1758 vm_vec_add(&neb->pts[idx], &pt, &Objects[neb->objnum].pos);
1760 // get a random point on the very outer radius, using spherical coords
1761 phi = fl_radian(frand_range(0.0f, 360.0f));
1762 theta = fl_radian(frand_range(0.0f, 360.f));
1764 neb->pts[idx].xyz.x = neb->outer_radius * (float)sin(phi) * (float)cos(theta);
1765 neb->pts[idx].xyz.y = neb->outer_radius * (float)sin(phi) * (float)sin(theta);
1766 neb->pts[idx].xyz.z = neb->outer_radius * (float)cos(phi);
1769 // pick a random bitmap and increment the # of poofs
1770 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1775 // return the alpha the passed poof should be rendered with, for a 1 shell nebula
1776 float neb2_get_alpha_1shell(neb2 *neb, int poof_index)
1782 // get the eye position
1783 neb2_get_eye_pos(&eye_pos);
1785 // determine what alpha to draw this bitmap with
1786 // higher alpha the closer the bitmap gets to the eye
1787 dist = vm_vec_dist_quick(&eye_pos, &neb->pts[poof_index]);
1789 // at poof radius or greater, alpha should be 1.0
1790 // scale from 0.0 to 1.0 between radius and magic
1791 if(dist >= neb->max_poof_radius){
1792 return max_alpha - 0.0001f;
1793 } else if(dist > neb->magic_num){
1794 // alpha per meter between the magic # and the max radius
1795 alpha = max_alpha / (neb->max_poof_radius - neb->magic_num);
1797 // above value times the # of meters away we are
1798 return alpha * (dist - neb->magic_num);
1801 // otherwise transparent