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
316 // read in the nebula.tbl
317 read_file_text("nebula.tbl");
320 // background bitmaps
321 Neb2_bitmap_count = 0;
322 while(!optional_string("#end")){
324 required_string("+Nebula:");
325 stuff_string(name, F_NAME, NULL);
327 if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){
328 strcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name);
334 while(!optional_string("#end")){
336 required_string("+Poof:");
337 stuff_string(name, F_NAME, NULL);
339 if(Neb2_poof_count < MAX_NEB2_POOFS){
340 strcpy(Neb2_poof_filenames[Neb2_poof_count++], name);
344 // should always have 6 neb poofs
345 SDL_assert(Neb2_poof_count == 6);
350 void neb2_set_detail_level(int level)
354 Nd = &Neb2_detail[0];
357 if(level >= MAX_DETAIL_LEVEL){
358 Nd = &Neb2_detail[MAX_DETAIL_LEVEL-1];
362 Nd = &Neb2_detail[level];
364 // regen the player neb
368 // initialize nebula stuff - call from game_post_level_init(), so the mission has been loaded
369 void neb2_level_init()
373 // standalone servers can bail here
374 if(Game_mode & GM_STANDALONE_SERVER){
378 // if the mission is not a fullneb mission, skip
379 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
380 Neb2_render_mode = NEB2_RENDER_NONE;
386 if(gr_screen.mode == GR_DIRECT3D){
387 max_alpha_player = NEB2_MAX_ALPHA_D3D;
389 max_alpha_player = NEB2_MAX_ALPHA_GLIDE;
393 // by default we'll use pof rendering
394 Neb2_render_mode = NEB2_RENDER_POF;
395 stars_set_background_model(BACKGROUND_MODEL_FILENAME, Neb2_texture_name);
397 // load in all nebula bitmaps
398 for(idx=0; idx<Neb2_poof_count; idx++){
399 if(Neb2_poofs[idx] < 0){
400 Neb2_poofs[idx] = bm_load(Neb2_poof_filenames[idx]);
405 pneb_tossed_alpha = 0;
408 neb_tossed_alpha = 0;
410 neb_tossed_count = 0;
412 // setup proper fogging values
413 Neb_backg_fog_near = NEB_BACKG_FOG_NEAR;
414 Neb_backg_fog_far = NEB_BACKG_FOG_FAR;
420 // shutdown nebula stuff
421 void neb2_level_close()
425 // standalone servers can bail here
426 if(Game_mode & GM_STANDALONE_SERVER){
430 // if the mission is not a fullneb mission, skip
431 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
435 // unload all nebula bitmaps
436 for(idx=0; idx<Neb2_poof_count; idx++){
437 if(Neb2_poofs[idx] >= 0){
438 bm_unload(Neb2_poofs[idx]);
439 Neb2_poofs[idx] = -1;
443 // unflag the mission as being fullneb so stuff doesn't fog in the techdata room :D
444 The_mission.flags &= ~MISSION_FLAG_FULLNEB;
447 // call before beginning all rendering
448 void neb2_render_setup(vector *eye_pos, matrix *eye_orient)
450 // standalone servers can bail here
451 if(Game_mode & GM_STANDALONE_SERVER){
455 // if the mission is not a fullneb mission, skip
456 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
460 // pre-render the real background nebula
461 neb2_pre_render(eye_pos, eye_orient);
469 // load in all nebula bitmaps
470 for(idx=0; idx<Neb2_poof_count; idx++){
471 if((Neb2_poofs[idx] >= 0) && (Neb2_poof_flags & (1<<idx))){
472 bm_page_in_texture(Neb2_poofs[idx]);
477 // should we not render this object because its obscured by the nebula?
478 int neb_skip_opt = 1;
481 neb_skip_opt = !neb_skip_opt;
483 dc_printf("Using neb object skipping!\n");
485 dc_printf("Not using neb object skipping!\n");
488 int neb2_skip_render(object *objp, float z_depth)
490 float fog_near, fog_far;
492 // if we're never skipping
498 if(Neb2_render_mode == NEB2_RENDER_LAME){
502 // get near and far fog values based upon object type and rendering mode
503 neb2_get_fog_values(&fog_near, &fog_far, objp);
506 switch( objp->type ) {
507 // some objects we always render
515 // any weapon over 500 meters away
517 if(z_depth >= 500.0f){
522 // any small ship over the fog limit, or any cruiser 50% further than the fog limit
525 if((objp->instance >= 0) && (Ships[objp->instance].ship_info_index >= 0)){
526 sip = &Ship_info[Ships[objp->instance].ship_info_index];
531 // small ships over the fog limit by a small factor
532 if((sip->flags & SIF_SMALL_SHIP) && (z_depth >= (fog_far * 1.3f))){
537 if((sip->flags & SIF_BIG_SHIP) && (z_depth >= (fog_far * 2.0f))){
542 if((sip->flags & SIF_HUGE_SHIP) && (z_depth >= (fog_far * 3.0f))){
547 // any fireball over the fog limit for small ships
550 if(z_depth >= fog_far){
557 // any debris over the fog limit for small ships
560 if(z_depth >= fog_far){
567 // any asteroids 50% farther than the fog limit for small ships
569 if(z_depth >= (fog_far * 1.5f)){
574 // any countermeasures over 100 meters away
576 if(z_depth >= 100.0f){
581 // hmmm. unknown object type - should probably let it through
590 float neb2_get_lod_scale(int objnum)
596 if((objnum < 0) || (objnum >= MAX_OBJECTS) || (Objects[objnum].type != OBJ_SHIP) || (Objects[objnum].instance < 0) || (Objects[objnum].instance >= MAX_SHIPS)){
599 shipp = &Ships[Objects[objnum].instance];
600 sip = &Ship_info[shipp->ship_info_index];
603 if(sip->flags & SIF_SMALL_SHIP){
605 } else if(sip->flags & SIF_BIG_SHIP){
614 // --------------------------------------------------------------------------------------------------------
615 // NEBULA FORWARD DEFINITIONS
618 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
619 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v)
625 // get the eye position
626 neb2_get_eye_pos(&eye_pos);
628 // determine what alpha to draw this bitmap with
629 // higher alpha the closer the bitmap gets to the eye
630 dist = vm_vec_dist_quick(&eye_pos, v);
632 // if the point is inside the inner radius, alpha is based on distance to the player's eye,
633 // becoming more transparent as it gets close
634 if(dist <= inner_radius){
635 // alpha per meter between the magic # and the inner radius
636 alpha = Nd->max_alpha_glide / (inner_radius - magic_num);
638 // above value times the # of meters away we are
639 alpha *= (dist - magic_num);
640 return alpha < 0.0f ? 0.0f : alpha;
642 // if the point is outside the inner radius, it starts out as completely transparent at max
643 // outer radius, and becomes more opaque as it moves towards inner radius
644 else if(dist <= outer_radius){
645 // alpha per meter between the outer radius and the inner radius
646 alpha = Nd->max_alpha_glide / (outer_radius - inner_radius);
648 // above value times the range between the outer radius and the poof
649 return alpha < 0.0f ? 0.0f : alpha * (outer_radius - dist);
652 // otherwise transparent
656 // return an alpha value for a bitmap offscreen based upon "break" value
657 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha)
660 float per_pixel_x = incoming_alpha / (float)Nd->break_x;
661 float per_pixel_y = incoming_alpha / (float)Nd->break_y;
662 int off_x = ((sx < 0.0f) || (sx > (float)gr_screen.max_w));
663 int off_y = ((sy < 0.0f) || (sy > (float)gr_screen.max_h));
664 float off_x_amount = 0.0f;
665 float off_y_amount = 0.0f;
667 // determine how many pixels outside we are
670 off_x_amount = fl_abs(sx);
672 off_x_amount = sx - (float)gr_screen.max_w;
677 off_y_amount = fl_abs(sy);
679 off_y_amount = sy - (float)gr_screen.max_h;
685 // offscreen X and Y - and Y is greater
686 if(off_y && (off_y_amount > off_x_amount)){
687 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
689 alpha = incoming_alpha - (off_x_amount * per_pixel_x);
694 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
696 // should never get here
701 return alpha < 0.0f ? 0.0f : alpha;
704 // -------------------------------------------------------------------------------------------------
705 // WACKY LOCAL PLAYER NEBULA STUFF
713 float ws = Nd->cube_dim / (float)Neb2_slices;
714 float hs = Nd->cube_dim / (float)Neb2_slices;
715 float ds = Nd->cube_dim / (float)Neb2_slices;
717 // get the eye position
718 neb2_get_eye_pos(&eye_pos);
720 // check left, right (0, and 1, x and -x)
721 if(cube_cen.xyz.x - eye_pos.xyz.x > ws){
724 } else if(eye_pos.xyz.x - cube_cen.xyz.x > ws){
729 // check up, down (2, and 3, y and -y)
730 if(cube_cen.xyz.y - eye_pos.xyz.y > hs){
733 } else if(eye_pos.xyz.y - cube_cen.xyz.y > hs){
738 // check front, back (4, and 5, z and -z)
739 if(cube_cen.xyz.z - eye_pos.xyz.z > ds){
742 } else if(eye_pos.xyz.z - cube_cen.xyz.z > ds){
751 void neb2_copy(int xyz, int src, int dest)
757 for(idx1=0; idx1<Neb2_slices; idx1++){
758 for(idx2=0; idx2<Neb2_slices; idx2++){
759 Neb2_cubes[dest][idx1][idx2] = Neb2_cubes[src][idx1][idx2];
764 for(idx1=0; idx1<Neb2_slices; idx1++){
765 for(idx2=0; idx2<Neb2_slices; idx2++){
766 Neb2_cubes[idx1][dest][idx2] = Neb2_cubes[idx1][src][idx2];
771 for(idx1=0; idx1<Neb2_slices; idx1++){
772 for(idx2=0; idx2<Neb2_slices; idx2++){
773 Neb2_cubes[idx1][idx2][dest] = Neb2_cubes[idx1][idx2][src];
783 void neb2_gen_slice(int xyz, int src, vector *cube_center)
786 float h_incw, h_inch, h_incd;
791 ws = Nd->cube_dim / (float)Neb2_slices;
793 hs = Nd->cube_dim / (float)Neb2_slices;
795 ds = Nd->cube_dim / (float)Neb2_slices;
797 cube_corner = *cube_center;
798 cube_corner.xyz.x -= (Nd->cube_dim / 2.0f);
799 cube_corner.xyz.y -= (Nd->cube_dim / 2.0f);
800 cube_corner.xyz.z -= (Nd->cube_dim / 2.0f);
803 for(idx1=0; idx1<Neb2_slices; idx1++){
804 for(idx2=0; idx2<Neb2_slices; idx2++){
805 v = &Neb2_cubes[src][idx1][idx2].pt;
807 v->xyz.x = h_incw + (ws * (float)src) + frand_range(-Nd->wj, Nd->wj);
808 v->xyz.y = h_inch + (hs * (float)idx1) + frand_range(-Nd->hj, Nd->hj);
809 v->xyz.z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
810 vm_vec_add2(v, &cube_corner);
813 Neb2_cubes[src][idx1][idx2].bmap = neb2_get_bitmap();
815 // set the rotation speed
816 Neb2_cubes[src][idx1][idx2].rot = 0.0f;
817 Neb2_cubes[src][idx1][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
818 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
823 for(idx1=0; idx1<Neb2_slices; idx1++){
824 for(idx2=0; idx2<Neb2_slices; idx2++){
825 v = &Neb2_cubes[idx1][src][idx2].pt;
827 v->xyz.x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
828 v->xyz.y = h_inch + (hs * (float)src) + frand_range(-Nd->hj, Nd->hj);
829 v->xyz.z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
830 vm_vec_add2(v, &cube_corner);
833 Neb2_cubes[idx1][src][idx2].bmap = neb2_get_bitmap();
835 // set the rotation speed
836 Neb2_cubes[idx1][src][idx2].rot = 0.0f;
837 Neb2_cubes[idx1][src][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
838 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
843 for(idx1=0; idx1<Neb2_slices; idx1++){
844 for(idx2=0; idx2<Neb2_slices; idx2++){
845 v = &Neb2_cubes[idx1][idx2][src].pt;
847 v->xyz.x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
848 v->xyz.y = h_inch + (hs * (float)idx2) + frand_range(-Nd->hj, Nd->hj);
849 v->xyz.z = h_incd + (ds * (float)src) + frand_range(-Nd->dj, Nd->dj);
850 vm_vec_add2(v, &cube_corner);
853 Neb2_cubes[idx1][idx2][src].bmap = neb2_get_bitmap();
855 // set the rotation speed
856 Neb2_cubes[idx1][idx2][src].rot = 0.0f;
857 Neb2_cubes[idx1][idx2][src].rot_speed = frand_range(-max_rotation, max_rotation);
858 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
868 // regenerate the player nebula
875 mprintf(("Regenerating local nebula!\n"));
877 // get eye position and orientation
878 neb2_get_eye_pos(&eye_pos);
879 neb2_get_eye_orient(&eye_orient);
881 // determine the corner of the cube
884 // generate slices of the cube
885 for(idx=0; idx<Neb2_slices; idx++){
886 neb2_gen_slice(0, idx, &cube_cen);
890 float max_area = 100000000.0f;
893 dc_get_arg(ARG_FLOAT);
894 max_area = Dc_arg_float;
897 float g3_draw_rotated_bitmap_area(vertex *pnt, float angle, float rad, uint tmap_flags, float area);
899 int frames_total = 0;
902 void neb2_render_player()
905 int idx1, idx2, idx3;
913 float frame_area = max_area;
914 float total_area = 0.0f;
917 // standalone servers can bail here
918 if(Game_mode & GM_STANDALONE_SERVER){
922 // if the mission is not a fullneb mission, skip
923 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
932 // don't render in lame mode
933 if((Neb2_render_mode == NEB2_RENDER_LAME) || (Neb2_render_mode == NEB2_RENDER_NONE)){
937 // get eye position and orientation
938 neb2_get_eye_pos(&eye_pos);
939 neb2_get_eye_orient(&eye_orient);
941 // maybe swap stuff around if the player crossed a "border"
942 for(idx2=0; idx2<3; idx2++){
943 switch(crossed_border()){
948 cube_cen.xyz.x -= Nd->cube_dim / (float)Neb2_slices;
949 for(idx1=Neb2_slices-1; idx1>0; idx1--){
950 neb2_copy(0, idx1-1, idx1);
952 neb2_gen_slice(0, 0, &cube_cen);
956 cube_cen.xyz.x += Nd->cube_dim / (float)Neb2_slices;
957 for(idx1=0; idx1<Neb2_slices-1; idx1++){
958 neb2_copy(0, idx1+1, idx1);
960 neb2_gen_slice(0, Neb2_slices - 1, &cube_cen);
964 cube_cen.xyz.y -= Nd->cube_dim / (float)Neb2_slices;
965 for(idx1=Neb2_slices-1; idx1>0; idx1--){
966 neb2_copy(1, idx1-1, idx1);
968 neb2_gen_slice(1, 0, &cube_cen);
972 cube_cen.xyz.y += Nd->cube_dim / (float)Neb2_slices;
973 for(idx1=0; idx1<Neb2_slices-1; idx1++){
974 neb2_copy(1, idx1+1, idx1);
976 neb2_gen_slice(1, Neb2_slices - 1, &cube_cen);
980 cube_cen.xyz.z -= Nd->cube_dim / (float)Neb2_slices;
981 for(idx1=Neb2_slices-1; idx1>0; idx1--){
982 neb2_copy(2, idx1-1, idx1);
984 neb2_gen_slice(2, 0, &cube_cen);
988 cube_cen.xyz.z += Nd->cube_dim / (float)Neb2_slices;
989 for(idx1=0; idx1<Neb2_slices-1; idx1++){
990 neb2_copy(2, idx1+1, idx1);
992 neb2_gen_slice(2, Neb2_slices - 1, &cube_cen);
997 // if we've switched nebula rendering off
998 if(Neb2_render_mode == NEB2_RENDER_NONE){
1003 // render the nebula
1004 for(idx1=0; idx1<Neb2_slices; idx1++){
1005 for(idx2=0; idx2<Neb2_slices; idx2++){
1006 for(idx3=0; idx3<Neb2_slices; idx3++){
1010 Neb2_cubes[idx1][idx2][idx3].rot += (Neb2_cubes[idx1][idx2][idx3].rot_speed * flFrametime);
1011 if(Neb2_cubes[idx1][idx2][idx3].rot >= 360.0f){
1012 Neb2_cubes[idx1][idx2][idx3].rot = 0.0f;
1015 // optimization 1 - don't draw backfacing poly's
1017 if(vm_vec_dot_to_point(&eye_orient.v.fvec, &eye_pos, &Neb2_cubes[idx1][idx2][idx3].pt) <= 0.0f){
1022 // rotate and project the vertex into viewspace
1023 g3_rotate_vertex(&p, &Neb2_cubes[idx1][idx2][idx3].pt);
1025 g3_project_vertex(&ptemp);
1027 // get the proper alpha value
1028 alpha = neb2_get_alpha_2shell(Nd->cube_inner, Nd->cube_outer, Nd->prad/4.0f, &Neb2_cubes[idx1][idx2][idx3].pt);
1030 // optimization 2 - don't draw 0.0f or less poly's
1031 // this amounts to big savings
1032 if(alpha <= Nd->break_alpha){
1033 pneb_tossed_alpha++;
1037 // drop poly's which are offscreen at all
1038 // if the poly's are offscreen
1039 if((ptemp.sx < 0.0f) || (ptemp.sx > (float)gr_screen.max_w) || (ptemp.sy < 0.0f) || (ptemp.sy > (float)gr_screen.max_h) ){
1040 alpha = neb2_get_alpha_offscreen(ptemp.sx, ptemp.sy, alpha);
1043 // optimization 2 - don't draw 0.0f or less poly's
1044 // this amounts to big savings
1045 if(alpha <= Nd->break_alpha){
1046 pneb_tossed_alpha++;
1050 // set the bitmap and render
1051 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);
1054 this_area = g3_draw_rotated_bitmap_area(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED, max_area);
1055 total_area += this_area;
1056 frame_area -= this_area;
1059 g3_draw_rotated_bitmap(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED);
1065 frames_total += frame_rendered;
1067 frame_avg = (float)frames_total / (float)frame_count;
1069 // gr_set_color_fast(&Color_bright_red);
1070 // gr_printf(30, 100, "Area %.3f", total_area);
1071 #ifdef NEB2_THUMBNAIL
1074 gr_set_bitmap(tbmap);
1080 // call this when the player's viewpoint has changed, this will cause the code to properly reset
1081 // the eye's local poofs
1082 void neb2_eye_changed()
1087 // get near and far fog values based upon object type and rendering mode
1088 void neb2_get_fog_values(float *fnear, float *ffar, object *objp)
1092 // default values in case something truly nasty happens
1096 // determine what fog index to use
1097 if(objp->type == OBJ_SHIP){
1098 SDL_assert((objp->instance >= 0) && (objp->instance < MAX_SHIPS));
1099 if((objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
1100 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1102 fog_index = ship_query_general_type(objp->instance);
1103 SDL_assert(fog_index >= 0);
1105 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1109 // fog everything else like a fighter
1111 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1115 *fnear = Neb_ship_fog_vals[fog_index][0];
1116 *ffar = Neb_ship_fog_vals[fog_index][1];
1119 // given a position in space, return a value from 0.0 to 1.0 representing the fog level
1120 float neb2_get_fog_intensity(object *obj)
1122 float f_near, f_far, pct;
1124 // get near and far fog values based upon object type and rendering mode
1125 neb2_get_fog_values(&f_near, &f_far, obj);
1128 pct = vm_vec_dist_quick(&Eye_position, &obj->pos) / (f_far - f_near);
1131 } else if(pct > 1.0f){
1138 // fogging stuff --------------------------------------------------------------------
1140 // do a pre-render of the background nebula
1142 ubyte tpixels[ESIZE * ESIZE * 4]; // for 32 bits
1143 int last_esize = -1;
1144 int this_esize = ESIZE;
1145 extern float Viewer_zoom;
1146 float ex_scale, ey_scale;
1148 void neb2_pre_render(vector *eye_pos, matrix *eye_orient)
1150 // bail early in lame and poly modes
1151 if(Neb2_render_mode != NEB2_RENDER_POF){
1155 // set the view clip
1156 gr_screen.clip_width = this_esize;
1157 gr_screen.clip_height = this_esize;
1158 g3_start_frame(1); // Turn on zbuffering
1159 g3_set_view_matrix(eye_pos, eye_orient, Viewer_zoom);
1160 gr_set_clip(0, 0, this_esize, this_esize);
1162 // render the background properly
1163 // hack - turn off nebula stuff
1164 int neb_save = Neb2_render_mode;
1165 Neb2_render_mode = NEB2_RENDER_NONE;
1167 // draw background stuff nebula
1168 extern void stars_draw_background();
1169 stars_draw_background();
1171 Neb2_render_mode = neb_save;
1174 gr_get_region(0, this_esize, this_esize, (ubyte*)tpixels);
1176 #ifdef NEB2_THUMBNAIL
1178 tbmap = bm_create(16, this_esize, this_esize, tpixels, 0);
1179 bm_lock(tbmap, 16, 0);
1184 // maybe do some swizzling
1191 // if the size has changed between frames, make a new bitmap
1192 if(this_esize != last_esize){
1193 last_esize = this_esize;
1195 // recalculate ex_scale and ey_scale values for looking up color values
1196 ex_scale = (float)this_esize / (float)gr_screen.max_w;
1197 ey_scale = (float)this_esize / (float)gr_screen.max_h;
1200 // restore the game clip stuff
1201 extern void game_set_view_clip();
1202 game_set_view_clip();
1205 // wacky scheme for smoothing colors
1206 int wacky_scheme = 3;
1208 // get the color of the pixel in the small pre-rendered background nebula
1209 #define PIXEL_INDEX_SMALL(xv, yv) ( (this_esize * (yv) * gr_screen.bytes_per_pixel) + ((xv) * gr_screen.bytes_per_pixel) )
1210 void neb2_get_pixel(int x, int y, int *r, int *g, int *b)
1217 // if we're in lame rendering mode, return a constant value
1218 if(Neb2_render_mode == NEB2_RENDER_LAME){
1219 *r = Neb2_background_color[0];
1220 *g = Neb2_background_color[1];
1221 *b = Neb2_background_color[2];
1226 // get the proper pixel index to be looking up
1229 // select screen format
1230 BM_SELECT_SCREEN_FORMAT();
1232 // pixel plus all immediate neighbors (on the small screen - should be more effective than 2 or 1)
1233 xs = (int)(ex_scale * x);
1234 ys = (int)(ey_scale * y);
1236 // sometimes goes over by 1 in direct3d
1237 if(ys >= (this_esize - 1)){
1242 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys)], &rv, &gv, &bv, NULL);
1248 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys)], &rv, &gv, &bv, NULL); // left
1254 if(xs < this_esize - 1){
1255 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys)], &rv, &gv, &bv, NULL); // right
1262 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys - 1)], &rv, &gv, &bv, NULL); // top
1268 if(ys < this_esize - 2){
1269 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys + 1)], &rv, &gv, &bv, NULL); // bottom
1276 if((xs > 0) && (ys > 0)){
1277 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys - 1)], &rv, &gv, &bv, NULL); // upper left
1283 if((xs < this_esize - 1) && (ys < this_esize - 1)){
1284 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys + 1)], &rv, &gv, &bv, NULL); // lower right
1290 if((ys > 0) && (xs < this_esize - 1)){
1291 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys - 1)], &rv, &gv, &bv, NULL); // lower left
1297 if((ys < this_esize - 1) && (xs > 0)){
1298 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys + 1)], &rv, &gv, &bv, NULL); // upper right
1305 rv = (ubyte) (ra / avg_count);
1306 gv = (ubyte) (ga / avg_count);
1307 bv = (ubyte) (ba / avg_count);
1315 // get the color to fog the background color to
1316 void neb2_get_backg_color(int *r, int *g, int *b)
1318 *r = Neb2_background_color[0];
1319 *g = Neb2_background_color[1];
1320 *b = Neb2_background_color[2];
1323 // set the background color
1324 void neb2_set_backg_color(int r, int g, int b)
1326 Neb2_background_color[0] = r;
1327 Neb2_background_color[1] = g;
1328 Neb2_background_color[2] = b;
1331 // fill in the position of the eye for this frame
1332 void neb2_get_eye_pos(vector *eye)
1334 *eye = Eye_position;
1337 // fill in the eye orient for this frame
1338 void neb2_get_eye_orient(matrix *eye)
1343 // get a (semi) random bitmap to use for a poof
1344 int neb2_get_bitmap()
1348 static int neb2_choose = 0;
1350 // get a random count
1351 count = (int)frand_range(1.0f, 5.0f);
1355 // don't cycle too many times
1358 if(neb2_choose == MAX_NEB2_POOFS - 1){
1365 } while(!(Neb2_poof_flags & (1<<neb2_choose)) && (huh < 10));
1371 if(Neb2_poofs[neb2_choose] < 0){
1372 return Neb2_poofs[0];
1374 return Neb2_poofs[neb2_choose];
1377 // nebula DCF functions ------------------------------------------------------
1379 DCF(neb2, "list nebula console commands")
1381 dc_printf("neb2_fog <X> <float> <float> : set near and far fog planes for ship type X\n");
1382 dc_printf("where X is an integer from 1 - 11\n");
1383 dc_printf("1 = cargo containers, 2 = fighters/bombers, 3 = cruisers\n");
1384 dc_printf("4 = freighters, 5 = capital ships, 6 = transports, 7 = support ships\n");
1385 dc_printf("8 = navbuoys, 9 = sentryguns, 10 = escape pods, 11 = background nebula polygons\n\n");
1387 dc_printf("neb2_max_alpha : max alpha value (0.0 to 1.0) for cloud poofs. 0.0 is completely transparent\n");
1388 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");
1389 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");
1390 dc_printf("neb2_smooth : magic fog smoothing modes (0 - 3)\n");
1391 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");
1392 dc_printf("neb2_rot : set max rotation speed for poofs\n");
1393 dc_printf("neb2_prad : set cloud poof radius\n");
1394 dc_printf("neb2_cdim : poof cube dimension\n");
1395 dc_printf("neb2_cinner : poof cube inner dimension\n");
1396 dc_printf("neb2_couter : poof cube outer dimension\n");
1397 dc_printf("neb2_jitter : poof jitter\n");
1398 dc_printf("neb2_mode : switch between no nebula, polygon background, amd pof background (0, 1 and 2 respectively)\n\n");
1399 dc_printf("neb2_ff : flash fade/sec\n");
1400 dc_printf("neb2_background : rgb background color\n");
1402 dc_printf("neb2_fog_vals : display all the current settings for all above values\n");
1407 dc_get_arg(ARG_FLOAT);
1408 Nd->prad = Dc_arg_float;
1412 dc_get_arg(ARG_FLOAT);
1413 Nd->cube_dim = Dc_arg_float;
1416 DCF(neb2_cinner, "")
1418 dc_get_arg(ARG_FLOAT);
1419 Nd->cube_inner = Dc_arg_float;
1422 DCF(neb2_couter, "")
1424 dc_get_arg(ARG_FLOAT);
1425 Nd->cube_outer = Dc_arg_float;
1428 DCF(neb2_jitter, "")
1430 dc_get_arg(ARG_FLOAT);
1431 Nd->hj = Nd->dj = Nd->wj = Dc_arg_float;
1438 dc_get_arg(ARG_INT);
1440 dc_get_arg(ARG_FLOAT);
1441 fnear = Dc_arg_float;
1442 dc_get_arg(ARG_FLOAT);
1443 ffar = Dc_arg_float;
1445 if((index >= 1) && (index <= 11) && (fnear >= 0.0f) && (ffar >= 0.0f) && (ffar > fnear)){
1447 Neb_backg_fog_near = fnear;
1448 Neb_backg_fog_far = ffar;
1450 Neb_ship_fog_vals[index][0] = fnear;
1451 Neb_ship_fog_vals[index][1] = ffar;
1456 DCF(neb2_max_alpha, "")
1458 dc_get_arg(ARG_FLOAT);
1459 Nd->max_alpha_glide = Dc_arg_float;
1462 DCF(neb2_break_alpha, "")
1464 dc_get_arg(ARG_FLOAT);
1465 Nd->break_alpha = Dc_arg_float;
1468 DCF(neb2_break_off, "")
1470 dc_get_arg(ARG_INT);
1471 Nd->break_y = (float)Dc_arg_int;
1472 Nd->break_x = Nd->break_y * 1.3333f;
1475 DCF(neb2_smooth, "")
1478 dc_get_arg(ARG_INT);
1480 if((index >= 0) && (index <= 3)){
1481 wacky_scheme = index;
1485 DCF(neb2_select, "")
1487 dc_get_arg(ARG_INT);
1488 int bmap = Dc_arg_int;
1489 if((bmap >= 0) && (bmap < Neb2_poof_count)){
1490 dc_get_arg(ARG_INT);
1493 Neb2_poof_flags |= (1<<bmap);
1495 Neb2_poof_flags &= ~(1<<bmap);
1502 dc_get_arg(ARG_FLOAT);
1503 max_rotation = Dc_arg_float;
1508 dc_get_arg(ARG_FLOAT);
1509 neb2_flash_fade = Dc_arg_float;
1514 dc_get_arg(ARG_INT);
1517 case NEB2_RENDER_NONE:
1518 Neb2_render_mode = NEB2_RENDER_NONE;
1521 case NEB2_RENDER_POLY:
1522 Neb2_render_mode = NEB2_RENDER_POLY;
1525 case NEB2_RENDER_POF:
1526 Neb2_render_mode = NEB2_RENDER_POF;
1527 stars_set_background_model(BACKGROUND_MODEL_FILENAME, "Eraseme3");
1530 case NEB2_RENDER_LAME:
1531 Neb2_render_mode = NEB2_RENDER_LAME;
1536 DCF(neb2_slices, "")
1538 dc_get_arg(ARG_INT);
1539 Neb2_slices = Dc_arg_int;
1543 DCF(neb2_background, "")
1547 dc_get_arg(ARG_INT);
1549 dc_get_arg(ARG_INT);
1551 dc_get_arg(ARG_INT);
1554 Neb2_background_color[0] = r;
1555 Neb2_background_color[1] = g;
1556 Neb2_background_color[2] = b;
1559 DCF(neb2_fog_vals, "")
1561 dc_printf("neb2_fog : \n");
1563 dc_printf("(1)cargo containers : %f, %f\n", Neb_ship_fog_vals[1][0], Neb_ship_fog_vals[1][1]);
1564 dc_printf("(2)fighters/bombers : %f, %f\n", Neb_ship_fog_vals[2][0], Neb_ship_fog_vals[2][1]);
1565 dc_printf("(3)cruisers : %f, %f\n", Neb_ship_fog_vals[3][0], Neb_ship_fog_vals[3][1]);
1566 dc_printf("(4)freighters : %f, %f\n", Neb_ship_fog_vals[4][0], Neb_ship_fog_vals[4][1]);
1567 dc_printf("(5)cap ships : %f, %f\n", Neb_ship_fog_vals[5][0], Neb_ship_fog_vals[5][1]);
1568 dc_printf("(6)transports : %f, %f\n", Neb_ship_fog_vals[6][0], Neb_ship_fog_vals[6][1]);
1569 dc_printf("(7)support ships : %f, %f\n", Neb_ship_fog_vals[7][0], Neb_ship_fog_vals[7][1]);
1570 dc_printf("(8)navbuoys : %f, %f\n", Neb_ship_fog_vals[8][0], Neb_ship_fog_vals[8][1]);
1571 dc_printf("(9)sentry guns : %f, %f\n", Neb_ship_fog_vals[9][0], Neb_ship_fog_vals[9][1]);
1572 dc_printf("(10)escape pods : %f, %f\n", Neb_ship_fog_vals[10][0], Neb_ship_fog_vals[10][1]);
1573 dc_printf("(11)background polys : %f, %f\n\n", Neb_backg_fog_near, Neb_backg_fog_far);
1575 dc_printf("neb2_max_alpha : %f\n", Nd->max_alpha_glide);
1576 dc_printf("neb2_break_alpha : %f\n", Nd->break_alpha);
1577 dc_printf("neb2_break_off : %d\n", (int)Nd->break_y);
1578 dc_printf("neb2_smooth : %d\n", wacky_scheme);
1579 dc_printf("neb2_toggle : %s\n", Neb2_render_mode ? "on" : "off");
1580 dc_printf("neb2_rot : %f\n", max_rotation);
1581 dc_printf("neb2_prad : %f\n", Nd->prad);
1582 dc_printf("neb2_cdim : %f\n", Nd->cube_dim);
1583 dc_printf("neb2_couter : %f\n", Nd->cube_outer);
1584 dc_printf("neb2_cinner : %f\n", Nd->cube_inner);
1585 dc_printf("neb2_jitter : %f\n", Nd->wj);
1586 dc_printf("neb2_ff : %f\n", neb2_flash_fade);
1587 dc_printf("neb2_background : %d %d %d\n", Neb2_background_color[0], Neb2_background_color[1], Neb2_background_color[2]);
1591 DCF(neb2_create, "create a basic nebula")
1597 dc_get_arg(ARG_INT);
1598 if(Dc_arg_type & ARG_INT){
1599 points = Dc_arg_int;
1601 dc_get_arg(ARG_FLOAT);
1602 if(Dc_arg_type & ARG_FLOAT){
1603 rad1 = Dc_arg_float;
1605 dc_get_arg(ARG_FLOAT);
1606 if(Dc_arg_type & ARG_FLOAT){
1607 rad2 = Dc_arg_float;
1609 neb2_create(&vmd_zero_vector, points, rad1, -1.0f, rad2);
1612 DCF(neb2_del, "delete existing nebulae")
1614 for(int idx=0; idx<MAX_OBJECTS; idx++){
1615 if(Objects[idx].type == OBJ_NEB2){
1622 float magic1 = 1000.0f;
1623 float magic2 = -1.0f;
1624 float magic3 = 700.0f;
1625 DCF(neb2_def, "create a default nebula")
1628 vm_vec_make(&a, 0.0f, 0.0f, 0.0f);
1629 vm_vec_make(&b, 3600.0f, 700.0f, 0.0f);
1630 vm_vec_make(&c, -3000.0f, 20.0f, 480.0f);
1631 vm_vec_make(&d, -4000.0f, 100.0f, 100.0f);
1632 vm_vec_make(&e, 0.0f, 3000.0f, -400.0f);
1633 vm_vec_make(&f, 670.0f, -2500.0f, -1600.0f);
1635 neb2_create(&a, magic0, magic1, magic2, magic3);
1636 neb2_create(&b, magic0, magic1, magic2, magic3);
1637 neb2_create(&c, magic0, magic1, magic2, magic3);
1638 neb2_create(&d, magic0, magic1, magic2, magic3);
1639 neb2_create(&e, magic0, magic1, magic2, magic3);
1640 neb2_create(&f, magic0, magic1, magic2, magic3);
1643 DCF(neb2_plr, "regenerate the player's nebula")
1648 DCF(neb2_stats, "display info about the nebula rendering")
1650 dc_printf("Player poofs tried : %d\n", pneb_tried);
1651 dc_printf("Player poofs tossed (alpha): %d\n", pneb_tossed_alpha);
1652 dc_printf("Player poofs tossed (dot): %d\n", pneb_tossed_dot);
1653 dc_printf("Player poofs tossed (off): %d\n", pneb_tossed_off);
1655 dc_printf("Poofs tried : %d\n", neb_tried);
1656 dc_printf("Poofs tossed (alpha): %d\n", neb_tossed_alpha);
1657 dc_printf("Poofs tossed (dot): %d\n", neb_tossed_dot);
1658 dc_printf("Poofs tossed (count): %d\n", neb_tossed_count);
1660 dc_printf("Avg poofs/frame: %f\n", frame_avg);
1663 // create a nebula object, return objnum of the nebula or -1 on fail
1664 // NOTE : in most cases you will want to pass -1.0f for outer_radius. Trust me on this
1665 int neb2_create(vector *offset, int num_poofs, float inner_radius, float outer_radius, float max_poof_radius)
1671 // delete a nebula object
1672 void neb2_delete(object *objp)
1677 // renders a nebula object
1678 void neb2_render(object *objp)
1683 // preprocess the nebula object before simulation
1684 void neb2_process_pre(object *objp)
1689 // process the nebula object after simulating, but before rendering
1690 void neb2_process_post(object *objp)
1697 // add N poofs to the inner shell of the nebula
1698 // if orient and ang are specified, generate the poofs so that they are "visible" around
1699 // the orient v.fvec in a cone of ang degrees
1700 void neb2_add_inner(neb2 *neb, int num_poofs, matrix *orient, float ang)
1703 vector pt, pt2, pt3;
1704 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1706 // add the points a pick a random bitmap
1707 for(idx=neb->num_poofs; idx<final_index; idx++){
1709 // put a point directly in front of the player, between 0 and inner_radius distance away
1710 vm_vec_copy_scale(&pt, &orient->v.fvec, frand_range(neb->magic_num, neb->inner_radius));
1712 // rotate the point by -ang <-> ang around the up vector
1713 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1715 // rotate the point by -ang <-> ang around the right vector
1716 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1718 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1719 vm_vec_add(&neb->pts[idx], &pt3, &Objects[neb->objnum].pos);
1721 neb->pts[idx].xyz.x = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.xyz.x;
1722 neb->pts[idx].xyz.y = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.xyz.y;
1723 neb->pts[idx].xyz.z = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.xyz.z;
1726 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1731 // add N poofs to the outer shell of the nebula
1732 // if orient and ang are specified, generate the poofs so that they are "visible" around
1733 // the orient v.fvec in a cone of ang degrees
1734 void neb2_add_outer(neb2 *neb, int num_poofs, matrix *orient, float ang)
1738 vector pt, pt2, pt3;
1739 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1741 // add the points a pick a random bitmap
1742 for(idx=neb->num_poofs; idx<final_index; idx++){
1744 // put a point directly in front of the player, at outer_radius distance away
1745 vm_vec_copy_scale(&pt, &orient->v.fvec, neb->outer_radius);
1747 // rotate the point by -ang <-> ang around the up vector
1748 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1750 // rotate the point by -ang <-> ang around the right vector
1751 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1753 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1754 vm_vec_add(&neb->pts[idx], &pt, &Objects[neb->objnum].pos);
1756 // get a random point on the very outer radius, using spherical coords
1757 phi = fl_radian(frand_range(0.0f, 360.0f));
1758 theta = fl_radian(frand_range(0.0f, 360.f));
1760 neb->pts[idx].xyz.x = neb->outer_radius * (float)sin(phi) * (float)cos(theta);
1761 neb->pts[idx].xyz.y = neb->outer_radius * (float)sin(phi) * (float)sin(theta);
1762 neb->pts[idx].xyz.z = neb->outer_radius * (float)cos(phi);
1765 // pick a random bitmap and increment the # of poofs
1766 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1771 // return the alpha the passed poof should be rendered with, for a 1 shell nebula
1772 float neb2_get_alpha_1shell(neb2 *neb, int poof_index)
1778 // get the eye position
1779 neb2_get_eye_pos(&eye_pos);
1781 // determine what alpha to draw this bitmap with
1782 // higher alpha the closer the bitmap gets to the eye
1783 dist = vm_vec_dist_quick(&eye_pos, &neb->pts[poof_index]);
1785 // at poof radius or greater, alpha should be 1.0
1786 // scale from 0.0 to 1.0 between radius and magic
1787 if(dist >= neb->max_poof_radius){
1788 return max_alpha - 0.0001f;
1789 } else if(dist > neb->magic_num){
1790 // alpha per meter between the magic # and the max radius
1791 alpha = max_alpha / (neb->max_poof_radius - neb->magic_num);
1793 // above value times the # of meters away we are
1794 return alpha * (dist - neb->magic_num);
1797 // otherwise transparent