Skip to content

Commit

Permalink
Cockpit fov option (scp-fs2open#5924)
Browse files Browse the repository at this point in the history
* add cockpit fov to in-game options and use a define for the default fov value for both fov options

* Add a controlling toggle option

* constexpr

* localization
  • Loading branch information
Mike Nelson committed Mar 25, 2024
1 parent 7fdcd4a commit 620afa0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
46 changes: 43 additions & 3 deletions code/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "ship/ship.h" //compute_slew_matrix

//*************************IMPORTANT GLOBALS*************************
fov_t VIEWER_ZOOM_DEFAULT = 0.75f; // Default viewer zoom, 0.625 as per multi-lateral agreement on 3/24/97
fov_t COCKPIT_ZOOM_DEFAULT = 0.75f;
fov_t VIEWER_ZOOM_DEFAULT = DEFAULT_FOV;
fov_t COCKPIT_ZOOM_DEFAULT = DEFAULT_FOV;
float Sexp_fov = 0.0f;
warp_camera Warp_camera;

Expand Down Expand Up @@ -54,6 +54,9 @@ APPLY_TO_FOV_T(*, mul)
APPLY_TO_FOV_T(+, add)
APPLY_TO_FOV_T(-, sub)

// Used to set the default value for in-game options
static constexpr float fov_default = DEFAULT_FOV;

static SCP_string fov_display(float val)
{
auto degrees = fl_degrees(val);
Expand All @@ -71,11 +74,48 @@ auto FovOption = options::OptionBuilder<float>("Graphics.FOV",
return true;
})
.display(fov_display)
.default_val(0.75f)
.default_val(fov_default)
.level(options::ExpertLevel::Advanced)
.importance(60)
.finish();

bool Use_cockpit_fov = false;

auto CockpitFOVToggleOption = options::OptionBuilder<bool>("Graphics.CockpitFOVToggle",
std::pair<const char*, int>{"Cockpit FOV Toggle", 1838},
std::pair<const char*, int>{"Whether or not to use a different FOV for cockpit rendering from normal rendering", 1839})
.category(std::make_pair("Graphics", 1825))
.default_val(false)
.change_listener([](bool val, bool) {
if (!val) {
COCKPIT_ZOOM_DEFAULT = VIEWER_ZOOM_DEFAULT;
}
return true; // This option will always persist so we never return false
})
.level(options::ExpertLevel::Advanced)
.bind_to(&Use_cockpit_fov)
.importance(61)
.finish();

auto CockpitFovOption = options::OptionBuilder<float>("Graphics.CockpitFOV",
std::pair<const char*, int>{"Cockpit Field Of View", 1840},
std::pair<const char*, int>{"The vertical field of view for cockpit rendering. Only works if cockpits are active and cockpit FOV toggle is turned on.", 1841})
.category(std::make_pair("Graphics", 1825))
.range(0.436332f, 1.5708f)
.change_listener([](const float& val, bool) {
if (Use_cockpit_fov){
COCKPIT_ZOOM_DEFAULT = val;
} else {
COCKPIT_ZOOM_DEFAULT = VIEWER_ZOOM_DEFAULT;
}
return true;
})
.display(fov_display)
.default_val(fov_default)
.level(options::ExpertLevel::Advanced)
.importance(62)
.finish();

//*************************CLASS: camera*************************
//This is where the camera class begins! :D
camera::camera(const char *in_name, int in_signature)
Expand Down
2 changes: 2 additions & 0 deletions code/camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#define EXTERN_CAM_BBOX_CONSTANT_PADDING 5.0f
#define EXTERN_CAM_BBOX_MULTIPLIER_PADDING 1.5f

#define DEFAULT_FOV 0.75f;

struct asymmetric_fov {
float left, right, up, down;
friend asymmetric_fov operator* (const asymmetric_fov&, const float&);
Expand Down
2 changes: 1 addition & 1 deletion code/cmdline/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ bool SetCmdlineParams()
if (val > 0.1) {
VIEWER_ZOOM_DEFAULT = val;
} else {
VIEWER_ZOOM_DEFAULT = 0.75f;
VIEWER_ZOOM_DEFAULT = DEFAULT_FOV;
}
}

Expand Down
2 changes: 1 addition & 1 deletion code/localization/localize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool *Lcl_unexpected_tstring_check = nullptr;
// NOTE: with map storage of XSTR strings, the indexes no longer need to be contiguous,
// but internal strings should still increment XSTR_SIZE to avoid collisions.
// retail XSTR_SIZE = 1570
// #define XSTR_SIZE 1838 // This is the next available ID
// #define XSTR_SIZE 1842 // This is the next available ID


// struct to allow for strings.tbl-determined x offset
Expand Down

0 comments on commit 620afa0

Please sign in to comment.