Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/model/modelrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ void model_render_insignias(const insignia_draw_data* insignia);
void model_render_set_wireframe_color(const color* clr);
bool render_tech_model(tech_render_type model_type, int x1, int y1, int x2, int y2, float zoom, bool lighting, int class_idx, const matrix* orient, const SCP_string& pof_filename = "", float closeup_zoom = 0, const vec3d* closeup_pos = &vmd_zero_vector);

float convert_distance_and_diameter_to_pixel_size(float distance, float diameter, float field_of_view_deg, int screen_height);

float model_render_get_diameter_clamped_to_min_pixel_size(const vec3d* pos, float diameter, float min_pixel_size);

void model_render_determine_color(color* clr, float alpha, gr_alpha_blend blend_mode, bool no_texturing, bool desaturate);
Expand Down
7 changes: 6 additions & 1 deletion code/weapon/weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ enum class FiringPattern {

float weapon_get_lifetime_pct(const weapon& wp);
float weapon_get_age(const weapon& wp);
float weapon_get_viewing_angle(const weapon& wp);
float weapon_get_apparent_size(const weapon& wp);

float beam_get_warmup_lifetime_pct(const beam& wp);
float beam_get_warmdown_lifetime_pct(const beam& wp);
Expand Down Expand Up @@ -742,14 +744,17 @@ struct weapon_info
std::pair {"Lifetime", modular_curves_functional_input<weapon_get_lifetime_pct>{}},
std::pair {"Age", modular_curves_functional_input<weapon_get_age>{}},
std::pair {"Base Velocity", modular_curves_submember_input<&weapon::weapon_max_vel>{}},
std::pair {"Base Damage", modular_curves_submember_input<&weapon::weapon_info_index, &Weapon_info, &weapon_info::damage>{}},
std::pair {"Max Hitpoints", modular_curves_submember_input<&weapon::weapon_info_index, &Weapon_info, &weapon_info::weapon_hitpoints>{}},
std::pair {"Current Hitpoints", modular_curves_submember_input<&weapon::objnum, &Objects, &object::hull_strength>{}},
std::pair {"Hitpoints Fraction", modular_curves_math_input<
modular_curves_submember_input<&weapon::objnum, &Objects, &object::hull_strength>,
modular_curves_submember_input<&weapon::weapon_info_index, &Weapon_info, &weapon_info::weapon_hitpoints>,
ModularCurvesMathOperators::division
>{}},
std::pair {"Parent Radius", modular_curves_submember_input<&weapon::objnum, &Objects, &object::parent, &Objects, &object::radius>{}}
std::pair {"Parent Radius", modular_curves_submember_input<&weapon::objnum, &Objects, &object::parent, &Objects, &object::radius>{}},
std::pair {"Viewing Angle", modular_curves_functional_input<weapon_get_viewing_angle>{}},
std::pair {"Apparent Size", modular_curves_functional_input<weapon_get_apparent_size>{}}
);

public:
Expand Down
26 changes: 24 additions & 2 deletions code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "tracing/Monitor.h"
#include "tracing/tracing.h"
#include "weapon.h"
#include "model/modelrender.h"


// Since SSMs are parsed after weapons, if we want to allow SSM strikes to be specified by name, we need to store those names until after SSMs are parsed.
Expand Down Expand Up @@ -9257,7 +9258,7 @@ void weapon_render(object* obj, model_draw_list *scene)
wp->laser_headon_bitmap_frame += flFrametime;

if (anim_has_curve) {
framenum = fl2i(i2fl(wip->laser_headon_bitmap.num_frames - 1) * anim_state);
headon_framenum = fl2i(i2fl(wip->laser_headon_bitmap.num_frames - 1) * anim_state);
} else {
headon_framenum = bm_get_anim_frame(wip->laser_headon_bitmap.first_frame, wp->laser_headon_bitmap_frame, wip->laser_headon_bitmap.total_time, true);
}
Expand Down Expand Up @@ -9363,7 +9364,7 @@ void weapon_render(object* obj, model_draw_list *scene)
wp->laser_glow_headon_bitmap_frame -= wip->laser_glow_headon_bitmap.total_time;

if (anim_has_curve) {
framenum = fl2i(i2fl(wip->laser_glow_headon_bitmap.num_frames) * anim_state);
headon_framenum = fl2i(i2fl(wip->laser_glow_headon_bitmap.num_frames) * anim_state);
} else {
headon_framenum = fl2i((wp->laser_glow_headon_bitmap_frame * wip->laser_glow_headon_bitmap.num_frames) / wip->laser_glow_headon_bitmap.total_time);
}
Expand Down Expand Up @@ -10467,4 +10468,25 @@ float weapon_get_lifetime_pct(const weapon& wp) {

float weapon_get_age(const weapon& wp) {
return f2fl(Missiontime - wp.creation_time);
}

float weapon_get_viewing_angle(const weapon& wp) {
object* wep_objp = &Objects[wp.objnum];

vec3d reye;
vm_vec_sub(&reye, &Eye_position, &wep_objp->pos);
Comment thread
Goober5000 marked this conversation as resolved.
Outdated
vm_vec_normalize(&reye);
return vm_vec_dot(&reye, &wep_objp->orient.vec.fvec);
}

float weapon_get_apparent_size(const weapon& wp) {
object* wep_objp = &Objects[wp.objnum];

float dist = vm_vec_dist(&Eye_position, &wep_objp->pos);

return convert_distance_and_diameter_to_pixel_size(
dist,
wep_objp->radius,
fl_degrees(g3_get_hfov(Eye_fov)),
gr_screen.max_h) / i2fl(gr_screen.max_h);
}