void HudGaugeShield::showShields(object *objp, int mode) { // static int fod_model = -1; float max_shield; int hud_color_index, range; int sx, sy, i; ship *sp; ship_info *sip; hud_frames *sgp=NULL; if ( objp->type != OBJ_SHIP ) return; // Goober5000 - don't show if primitive sensors if ( Ships[Player_obj->instance].flags[Ship::Ship_Flags::Primitive_sensors] ) return; sp = &Ships[objp->instance]; sip = &Ship_info[sp->ship_info_index]; // bool digitus_improbus = (fod_model != -2 && strstr(sp->ship_name, "Sathanas") != NULL); if ( sip->shield_icon_index == 255 && !(sip->flags[Ship::Info_Flags::Generate_hud_icon]) /*&& !digitus_improbus*/) { return; } setGaugeColor(); // load in shield frames if not already loaded if (sip->shield_icon_index != 255) { sgp = &Shield_gauges.at(sip->shield_icon_index); if ( (sgp->first_frame == -1) && (sip->shield_icon_index < Hud_shield_filenames.size()) ) { sgp->first_frame = bm_load_animation(Hud_shield_filenames.at(sip->shield_icon_index).c_str(), &sgp->num_frames); if (sgp->first_frame == -1) { if (!shield_ani_warning_displayed_already) { shield_ani_warning_displayed_already = true; Warning(LOCATION, "Could not load in the HUD shield ani: %s\n", Hud_shield_filenames.at(sip->shield_icon_index).c_str()); } return; } } } sx = position[0]; sy = position[1]; sx += fl2i(HUD_offset_x); sy += fl2i(HUD_offset_y); // draw the ship first maybeFlashShield(SHIELD_HIT_PLAYER, Shield_hit_data[SHIELD_HIT_PLAYER].hull_hit_index); if(sip->shield_icon_index != 255) { renderBitmap(sgp->first_frame, sx, sy); } else { bool g3_yourself = !g3_in_frame(); angles rot_angles = {-1.570796327f,0.0f,0.0f}; matrix object_orient; vm_angles_2_matrix(&object_orient, &rot_angles); gr_screen.clip_width = 112; gr_screen.clip_height = 93; //Fire it up if(g3_yourself) g3_start_frame(1); hud_save_restore_camera_data(1); setClip(sx, sy, 112, 93); //if(!digitus_improbus) g3_set_view_matrix( &sip->closeup_pos, &vmd_identity_matrix, sip->closeup_zoom * 2.5f); /*else { vec3d finger_vec = {0.0f, 0.0f, 176.0f}; g3_set_view_matrix( &finger_vec, &vmd_identity_matrix, 1.0f); }*/ gr_set_proj_matrix(0.5f*Proj_fov, gr_screen.clip_aspect, Min_draw_distance, Max_draw_distance); gr_set_view_matrix(&Eye_position, &Eye_matrix); //We're ready to show stuff //if(!digitus_improbus) { model_render_params render_info; render_info.set_flags(MR_NO_LIGHTING | MR_AUTOCENTER | MR_NO_FOGGING); render_info.set_replacement_textures(sp->ship_replacement_textures); render_info.set_detail_level_lock(1); render_info.set_object_number(OBJ_INDEX(objp)); model_render_immediate( &render_info, sip->model_num, &object_orient, &vmd_zero_vector ); } /*else { if(fod_model == -1) { fod_model = model_load(NOX("FoD.pof"), 0, NULL); if(fod_model == -1) { fod_model = -2; return; } } model_render(fod_model, &object_orient, &vmd_zero_vector, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_AUTOCENTER | MR_NO_FOGGING, -1, -1); }*/ //We're done gr_end_view_matrix(); gr_end_proj_matrix(); if(g3_yourself) g3_end_frame(); hud_save_restore_camera_data(0); resetClip(); } if(!sip->max_shield_strength) return; // draw the quadrants // // Draw shield quadrants at one of NUM_SHIELD_LEVELS max_shield = get_max_shield_quad(objp); coord2d shield_icon_coords[6]; for ( i = 0; i < objp->n_quadrants; i++ ) { if ( objp->flags[Object::Object_Flags::No_shields] ) { break; } if ( !(sip->flags[Ship::Info_Flags::Model_point_shields]) ) { if ( objp->shield_quadrant[Quadrant_xlate[i]] < 0.1f ) continue; } else { if ( objp->shield_quadrant[i] < 0.1f ) continue; } range = MAX(HUD_COLOR_ALPHA_MAX, HUD_color_alpha + objp->n_quadrants); if ( !(sip->flags[Ship::Info_Flags::Model_point_shields]) ) hud_color_index = fl2i( (objp->shield_quadrant[Quadrant_xlate[i]] / max_shield) * range); else hud_color_index = fl2i( (objp->shield_quadrant[i] / max_shield) * range); Assert(hud_color_index >= 0 && hud_color_index <= range); if ( hud_color_index < 0 ) { hud_color_index = 0; } if ( hud_color_index >= HUD_NUM_COLOR_LEVELS ) { hud_color_index = HUD_NUM_COLOR_LEVELS - 1; } int flash=0; flash = maybeFlashShield(mode, i); if ( !flash ) { // gr_set_color_fast(&HUD_color_defaults[hud_color_index]); setGaugeColor(hud_color_index); if(sip->shield_icon_index != 255) { int framenum = sgp->first_frame+i+1; if (framenum < sgp->first_frame+sgp->num_frames) renderBitmap(framenum, sx, sy); } else { //Ugh, draw four shield quadrants static const int TRI_EDGE = 6; static const int BAR_LENGTH = 112; static const int BAR_HEIGHT = 54; static const int BAR_WIDTH = 6; static const int SHIELD_OFFSET = BAR_WIDTH + TRI_EDGE + 3; switch(i) { //Top case 0: shield_icon_coords[0].x = sx; shield_icon_coords[0].y = sy+BAR_WIDTH+TRI_EDGE; shield_icon_coords[1].x = sx; shield_icon_coords[1].y = sy; shield_icon_coords[2].x = sx+TRI_EDGE; shield_icon_coords[2].y = sy+BAR_WIDTH; shield_icon_coords[3].x = sx+BAR_LENGTH; shield_icon_coords[3].y = sy; shield_icon_coords[4].x = sx+BAR_LENGTH-TRI_EDGE; shield_icon_coords[4].y = sy+BAR_WIDTH; shield_icon_coords[5].x = sx+BAR_LENGTH; shield_icon_coords[5].y = sy+BAR_WIDTH+TRI_EDGE; renderShieldIcon(shield_icon_coords); break; //Left case 3: sy += SHIELD_OFFSET; shield_icon_coords[0].x = sx+BAR_WIDTH+TRI_EDGE; shield_icon_coords[0].y = sy+BAR_HEIGHT; shield_icon_coords[1].x = sx; shield_icon_coords[1].y = sy+BAR_HEIGHT; shield_icon_coords[2].x = sx+BAR_WIDTH; shield_icon_coords[2].y = sy+BAR_HEIGHT-TRI_EDGE; shield_icon_coords[3].x = sx; shield_icon_coords[3].y = sy; shield_icon_coords[4].x = sx+BAR_WIDTH; shield_icon_coords[4].y = sy+TRI_EDGE; shield_icon_coords[5].x = sx+BAR_WIDTH+TRI_EDGE; shield_icon_coords[5].y = sy; renderShieldIcon(shield_icon_coords); sy -= SHIELD_OFFSET + BAR_WIDTH + TRI_EDGE; break; //Right case 1: sx += BAR_LENGTH; sy += SHIELD_OFFSET; shield_icon_coords[0].x = sx-BAR_WIDTH-TRI_EDGE; shield_icon_coords[0].y = sy; shield_icon_coords[1].x = sx; shield_icon_coords[1].y = sy; shield_icon_coords[2].x = sx-BAR_WIDTH; shield_icon_coords[2].y = sy+TRI_EDGE; shield_icon_coords[3].x = sx; shield_icon_coords[3].y = sy+BAR_HEIGHT; shield_icon_coords[4].x = sx-BAR_WIDTH; shield_icon_coords[4].y = sy+BAR_HEIGHT-TRI_EDGE; shield_icon_coords[5].x = sx-BAR_WIDTH-TRI_EDGE; shield_icon_coords[5].y = sy+BAR_HEIGHT; renderShieldIcon(shield_icon_coords); sx -= BAR_LENGTH; sy -= SHIELD_OFFSET; break; //Bottom case 2: sy += BAR_HEIGHT + SHIELD_OFFSET*2 - BAR_WIDTH - TRI_EDGE; shield_icon_coords[0].x = sx+BAR_LENGTH; shield_icon_coords[0].y = sy; shield_icon_coords[1].x = sx+BAR_LENGTH; shield_icon_coords[1].y = sy+BAR_WIDTH+TRI_EDGE; shield_icon_coords[2].x = sx+BAR_LENGTH-TRI_EDGE; shield_icon_coords[2].y = sy+TRI_EDGE; shield_icon_coords[3].x = sx; shield_icon_coords[3].y = sy+BAR_WIDTH+TRI_EDGE; shield_icon_coords[4].x = sx+TRI_EDGE; shield_icon_coords[4].y = sy+TRI_EDGE; shield_icon_coords[5].x = sx; shield_icon_coords[5].y = sy; renderShieldIcon(shield_icon_coords); sy -= BAR_HEIGHT + SHIELD_OFFSET*2 - BAR_WIDTH - TRI_EDGE; break; //Whoops? default: nprintf(("HUD", "Invalid shield quadrant %d specified!\n", i)); break; } } } } // hud_set_default_color(); }
void techroom_ships_render(float frametime) { // render all the common stuff tech_common_render(); if(Cur_entry_index == -1) return; // now render the trackball ship, which is unique to the ships tab float rev_rate = REVOLUTION_RATE; angles rot_angles, view_angles; int z, i, j; ship_info *sip = &Ship_info[Cur_entry_index]; model_render_params render_info; if (sip->uses_team_colors) { render_info.set_team_color(sip->default_team_name, "none", 0, 0); } // get correct revolution rate z = sip->flags; if (z & SIF_BIG_SHIP) { rev_rate *= 1.7f; } if (z & SIF_HUGE_SHIP) { rev_rate *= 3.0f; } // rotate the ship as much as required for this frame Techroom_ship_rot += PI2 * frametime / rev_rate; while (Techroom_ship_rot > PI2){ Techroom_ship_rot -= PI2; } // reorient ship if (Trackball_active) { int dx, dy; matrix mat1, mat2; if (Trackball_active) { mouse_get_delta(&dx, &dy); if (dx || dy) { vm_trackball(-dx, -dy, &mat1); vm_matrix_x_matrix(&mat2, &mat1, &Techroom_ship_orient); Techroom_ship_orient = mat2; } } } else { // setup stuff needed to render the ship view_angles.p = -0.6f; view_angles.b = 0.0f; view_angles.h = 0.0f; vm_angles_2_matrix(&Techroom_ship_orient, &view_angles); rot_angles.p = 0.0f; rot_angles.b = 0.0f; rot_angles.h = Techroom_ship_rot; vm_rotate_matrix_by_angles(&Techroom_ship_orient, &rot_angles); } gr_set_clip(Tech_ship_display_coords[gr_screen.res][SHIP_X_COORD], Tech_ship_display_coords[gr_screen.res][SHIP_Y_COORD], Tech_ship_display_coords[gr_screen.res][SHIP_W_COORD], Tech_ship_display_coords[gr_screen.res][SHIP_H_COORD], GR_RESIZE_MENU); // render the ship g3_start_frame(1); g3_set_view_matrix(&sip->closeup_pos, &vmd_identity_matrix, sip->closeup_zoom * 1.3f); // lighting for techroom light_reset(); vec3d light_dir = vmd_zero_vector; light_dir.xyz.y = 1.0f; light_dir.xyz.x = 0.0000001f; light_add_directional(&light_dir, 0.85f, 1.0f, 1.0f, 1.0f); light_rotate_all(); // lighting for techroom Glowpoint_use_depth_buffer = false; model_clear_instance(Techroom_ship_modelnum); render_info.set_detail_level_lock(0); polymodel *pm = model_get(Techroom_ship_modelnum); for (i = 0; i < sip->n_subsystems; i++) { model_subsystem *msp = &sip->subsystems[i]; if (msp->type == SUBSYSTEM_TURRET) { float p = 0.0f; float h = 0.0f; for (j = 0; j < msp->n_triggers; j++) { // special case for turrets p = msp->triggers[j].angle.xyz.x; h = msp->triggers[j].angle.xyz.y; } if ( msp->subobj_num >= 0 ) { model_set_instance_techroom(Techroom_ship_modelnum, msp->subobj_num, 0.0f, h ); } if ( (msp->subobj_num != msp->turret_gun_sobj) && (msp->turret_gun_sobj >= 0) ) { model_set_instance_techroom(Techroom_ship_modelnum, msp->turret_gun_sobj, p, 0.0f ); } } } if(Cmdline_shadow_quality) { gr_reset_clip(); shadows_start_render(&Eye_matrix, &Eye_position, Proj_fov, gr_screen.clip_aspect, -sip->closeup_pos.xyz.z + pm->rad, -sip->closeup_pos.xyz.z + pm->rad + 200.0f, -sip->closeup_pos.xyz.z + pm->rad + 2000.0f, -sip->closeup_pos.xyz.z + pm->rad + 10000.0f); render_info.set_flags(MR_NO_TEXTURING | MR_NO_LIGHTING | MR_AUTOCENTER); model_render_immediate(&render_info, Techroom_ship_modelnum, &Techroom_ship_orient, &vmd_zero_vector); shadows_end_render(); gr_set_clip(Tech_ship_display_coords[gr_screen.res][SHIP_X_COORD], Tech_ship_display_coords[gr_screen.res][SHIP_Y_COORD], Tech_ship_display_coords[gr_screen.res][SHIP_W_COORD], Tech_ship_display_coords[gr_screen.res][SHIP_H_COORD], GR_RESIZE_MENU); } if (!Cmdline_nohtl) { gr_set_proj_matrix(Proj_fov, gr_screen.clip_aspect, Min_draw_distance, Max_draw_distance); gr_set_view_matrix(&Eye_position, &Eye_matrix); } uint render_flags = MR_AUTOCENTER; if(sip->flags2 & SIF2_NO_LIGHTING) render_flags |= MR_NO_LIGHTING; render_info.set_flags(render_flags); model_render_immediate(&render_info, Techroom_ship_modelnum, &Techroom_ship_orient, &vmd_zero_vector); Glowpoint_use_depth_buffer = true; batch_render_all(); if (!Cmdline_nohtl) { gr_end_view_matrix(); gr_end_proj_matrix(); } g3_end_frame(); gr_reset_clip(); }
void warpin_render(object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d) { vec3d center; vec3d vecs[5]; vertex verts[5]; int saved_gr_zbuffering = gr_zbuffer_get(); gr_zbuffer_set(GR_ZBUFF_READ); vm_vec_scale_add( ¢er, pos, &orient->vec.fvec, -(max_radius/2.5f)/3.0f ); memset(verts, 0, sizeof(verts)); if (Warp_glow_bitmap >= 0) { float r = radius; bool render_it = true; #define OUT_PERCENT1 0.80f #define OUT_PERCENT2 0.90f #define IN_PERCENT1 0.10f #define IN_PERCENT2 0.20f if (Cmdline_warp_flash) { if ( (life_percent >= IN_PERCENT1) && (life_percent < IN_PERCENT2) ) { r *= (life_percent - IN_PERCENT1) / (IN_PERCENT2 - IN_PERCENT1); //render_it = true; } else if ( (life_percent >= OUT_PERCENT1) && (life_percent < OUT_PERCENT2) ) { r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2 - OUT_PERCENT1); //render_it = true; } } if (render_it) { // Add in noise int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES; r *= (0.40f + Noise[noise_frame] * 0.30f); // Bobboau's warp thingie, toggled by cmdline if (Cmdline_warp_flash) { r += powf((2.0f * life_percent) - 1.0f, 24.0f) * max_radius * 1.5f; } vecs[4] = center; verts[4].texture_position.u = 0.5f; verts[4].texture_position.v = 0.5f; g3_transfer_vertex( &verts[4], &vecs[4] ); float alpha = (The_mission.flags[Mission::Mission_Flags::Fullneb]) ? (1.0f - neb2_get_fog_intensity(obj)) : 1.0f; gr_set_bitmap( Warp_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha ); g3_draw_bitmap( &verts[4], 0, r, TMAP_FLAG_TEXTURED | TMAP_HTL_3D_UNLIT ); } } if ( (Warp_model >= 0) && (warp_3d || Cmdline_3dwarp) ) { model_render_params render_info; vec3d scale; scale.xyz.z = scale.xyz.y = scale.xyz.x = radius / 25.0f; render_info.set_warp_params(texture_bitmap_num, radius/max_radius, scale); float dist = vm_vec_dist_quick( pos, &Eye_position ); render_info.set_detail_level_lock((int)(dist / (radius * 10.0f))); render_info.set_flags(MR_NO_LIGHTING | MR_NORMAL | MR_NO_FOGGING | MR_NO_CULL | MR_NO_BATCH); model_render_immediate( &render_info, Warp_model, orient, pos ); } else { float Grid_depth = radius/2.5f; gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f ); vm_vec_scale_add( &vecs[0], ¢er, &orient->vec.uvec, radius ); vm_vec_scale_add2( &vecs[0], &orient->vec.rvec, -radius ); vm_vec_scale_add2( &vecs[0], &orient->vec.fvec, Grid_depth ); vm_vec_scale_add( &vecs[1], ¢er, &orient->vec.uvec, radius ); vm_vec_scale_add2( &vecs[1], &orient->vec.rvec, radius ); vm_vec_scale_add2( &vecs[1], &orient->vec.fvec, Grid_depth ); vm_vec_scale_add( &vecs[2], ¢er, &orient->vec.uvec, -radius ); vm_vec_scale_add2( &vecs[2], &orient->vec.rvec, radius ); vm_vec_scale_add2( &vecs[2], &orient->vec.fvec, Grid_depth ); vm_vec_scale_add( &vecs[3], ¢er, &orient->vec.uvec, -radius ); vm_vec_scale_add2( &vecs[3], &orient->vec.rvec, -radius ); vm_vec_scale_add2( &vecs[3], &orient->vec.fvec, Grid_depth ); // vm_vec_scale_add( &vecs[4], ¢er, &orient->vec.fvec, -Grid_depth ); vecs[4] = center; verts[0].texture_position.u = 0.01f; verts[0].texture_position.v = 0.01f; verts[1].texture_position.u = 0.99f; verts[1].texture_position.v = 0.01f; verts[2].texture_position.u = 0.99f; verts[2].texture_position.v = 0.99f; verts[3].texture_position.u = 0.01f; verts[3].texture_position.v = 0.99f; verts[4].texture_position.u = 0.5f; verts[4].texture_position.v = 0.5f; g3_transfer_vertex( &verts[0], &vecs[0] ); g3_transfer_vertex( &verts[1], &vecs[1] ); g3_transfer_vertex( &verts[2], &vecs[2] ); g3_transfer_vertex( &verts[3], &vecs[3] ); g3_transfer_vertex( &verts[4], &vecs[4] ); int cull = gr_set_cull(0); // fixes rendering problem in D3D - taylor draw_face( &verts[0], &verts[4], &verts[1] ); draw_face( &verts[1], &verts[4], &verts[2] ); draw_face( &verts[4], &verts[3], &verts[2] ); draw_face( &verts[0], &verts[3], &verts[4] ); gr_set_cull(cull); } if (Warp_ball_bitmap > -1 && Cmdline_warp_flash == 1) { flash_ball warp_ball(20, .1f,.25f, &vmd_z_vector, &vmd_zero_vector, 4.0f, 0.5f); float adg = (2.0f * life_percent) - 1.0f; float pct = (powf(adg, 4.0f) - powf(adg, 128.0f)) * 4.0f; if (pct > 0.00001f) { g3_start_instance_matrix(pos, orient, true); gr_set_bitmap(Warp_ball_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.9999f); warp_ball.render(max_radius * pct * 0.5f, adg * adg, adg * adg * 6.0f); g3_done_instance(true); } } gr_zbuffer_set( saved_gr_zbuffering ); }