Added FOV and mouse sensitivity settings
This commit is contained in:
parent
af2786164a
commit
1d73c0bd9f
@ -25,7 +25,9 @@ toml::Wrapper create_wrapper(EngineSettings& settings) {
|
|||||||
|
|
||||||
toml::Section& camera = wrapper.add("camera");
|
toml::Section& camera = wrapper.add("camera");
|
||||||
camera.add("fov-effects", &settings.camera.fovEvents);
|
camera.add("fov-effects", &settings.camera.fovEvents);
|
||||||
|
camera.add("fov", &settings.camera.fov);
|
||||||
camera.add("shaking", &settings.camera.shaking);
|
camera.add("shaking", &settings.camera.shaking);
|
||||||
|
camera.add("sensitivity", &settings.camera.sensitivity);
|
||||||
|
|
||||||
toml::Section& graphics = wrapper.add("graphics");
|
toml::Section& graphics = wrapper.add("graphics");
|
||||||
graphics.add("fog-curve", &settings.graphics.fogCurve);
|
graphics.add("fog-curve", &settings.graphics.fogCurve);
|
||||||
|
|||||||
@ -147,7 +147,7 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
|
|||||||
Shader* backShader = assets->getShader("background");
|
Shader* backShader = assets->getShader("background");
|
||||||
backShader->use();
|
backShader->use();
|
||||||
backShader->uniformMatrix("u_view", camera->getView(false));
|
backShader->uniformMatrix("u_view", camera->getView(false));
|
||||||
backShader->uniform1f("u_zoom", camera->zoom);
|
backShader->uniform1f("u_zoom", camera->zoom*camera->getFov()/(3.141592*0.5f));
|
||||||
backShader->uniform1f("u_ar", (float)Window::width/(float)Window::height);
|
backShader->uniform1f("u_ar", (float)Window::width/(float)Window::height);
|
||||||
skybox->draw(backShader);
|
skybox->draw(backShader);
|
||||||
|
|
||||||
|
|||||||
@ -120,7 +120,7 @@ void GUI::act(float delta) {
|
|||||||
|
|
||||||
void GUI::draw(Batch2D* batch, Assets* assets) {
|
void GUI::draw(Batch2D* batch, Assets* assets) {
|
||||||
menu->setCoord((Window::size() - menu->size()) / 2.0f);
|
menu->setCoord((Window::size() - menu->size()) / 2.0f);
|
||||||
uicamera->fov = Window::height;
|
uicamera->setFov(Window::height);
|
||||||
|
|
||||||
Shader* uishader = assets->getShader("ui");
|
Shader* uishader = assets->getShader("ui");
|
||||||
uishader->use();
|
uishader->use();
|
||||||
|
|||||||
@ -303,7 +303,7 @@ void HudRenderer::draw(const GfxContext& ctx){
|
|||||||
|
|
||||||
debugPanel->visible(level->player->debug);
|
debugPanel->visible(level->player->debug);
|
||||||
|
|
||||||
uicamera->fov = height;
|
uicamera->setFov(height);
|
||||||
|
|
||||||
Shader* uishader = assets->getShader("ui");
|
Shader* uishader = assets->getShader("ui");
|
||||||
uishader->use();
|
uishader->use();
|
||||||
@ -337,7 +337,7 @@ void HudRenderer::draw(const GfxContext& ctx){
|
|||||||
|
|
||||||
Block* cblock = contentIds->getBlockDef(player->choosenBlock);
|
Block* cblock = contentIds->getBlockDef(player->choosenBlock);
|
||||||
assert(cblock != nullptr);
|
assert(cblock != nullptr);
|
||||||
blocksPreview->draw(cblock, width - 56, uicamera->fov - 56, 48, vec4(1.0f));
|
blocksPreview->draw(cblock, width - 56, uicamera->getFov() - 56, 48, vec4(1.0f));
|
||||||
//drawBlockPreview(cblock, width - 56, uicamera->fov - 56, 48, 48, vec4(1.0f));
|
//drawBlockPreview(cblock, width - 56, uicamera->fov - 56, 48, 48, vec4(1.0f));
|
||||||
}
|
}
|
||||||
uishader->use();
|
uishader->use();
|
||||||
|
|||||||
@ -200,6 +200,7 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
|
|||||||
Panel* panel = new Panel(vec2(400, 200), vec4(5.0f), 1.0f);
|
Panel* panel = new Panel(vec2(400, 200), vec4(5.0f), 1.0f);
|
||||||
panel->color(vec4(0.0f));
|
panel->color(vec4(0.0f));
|
||||||
|
|
||||||
|
// TODO: simplify repeating code for trackbars
|
||||||
/* Load Distance setting track bar */{
|
/* Load Distance setting track bar */{
|
||||||
panel->add((new Label(L""))->textSupplier([=]() {
|
panel->add((new Label(L""))->textSupplier([=]() {
|
||||||
return L"Load Distance: " +
|
return L"Load Distance: " +
|
||||||
@ -250,6 +251,39 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
|
|||||||
panel->add(trackbar);
|
panel->add(trackbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fov setting track bar */{
|
||||||
|
panel->add((new Label(L""))->textSupplier([=]() {
|
||||||
|
int fov = (int)engine->getSettings().camera.fov;
|
||||||
|
return L"FOV: "+std::to_wstring(fov)+L"°";
|
||||||
|
}));
|
||||||
|
|
||||||
|
TrackBar* trackbar = new TrackBar(30.0, 120.0, 90, 1, 4);
|
||||||
|
trackbar->supplier([=]() {
|
||||||
|
return engine->getSettings().camera.fov;
|
||||||
|
});
|
||||||
|
trackbar->consumer([=](double value) {
|
||||||
|
engine->getSettings().camera.fov = value;
|
||||||
|
});
|
||||||
|
panel->add(trackbar);
|
||||||
|
}
|
||||||
|
/* Camera sensitivity setting track bar */{
|
||||||
|
panel->add((new Label(L""))->textSupplier([=]() {
|
||||||
|
std::wstringstream ss;
|
||||||
|
ss << std::fixed << std::setprecision(1);
|
||||||
|
ss << engine->getSettings().camera.sensitivity;
|
||||||
|
return L"Sensitivity: "+ss.str();
|
||||||
|
}));
|
||||||
|
|
||||||
|
TrackBar* trackbar = new TrackBar(0.1, 10.0, 2.0, 0.1, 4);
|
||||||
|
trackbar->supplier([=]() {
|
||||||
|
return engine->getSettings().camera.sensitivity;
|
||||||
|
});
|
||||||
|
trackbar->consumer([=](double value) {
|
||||||
|
engine->getSettings().camera.sensitivity = value;
|
||||||
|
});
|
||||||
|
panel->add(trackbar);
|
||||||
|
}
|
||||||
|
|
||||||
/* V-Sync checkbox */{
|
/* V-Sync checkbox */{
|
||||||
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f);
|
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f);
|
||||||
checkpanel->color(vec4(0.0f));
|
checkpanel->color(vec4(0.0f));
|
||||||
|
|||||||
@ -73,7 +73,7 @@ void MenuScreen::draw(float delta) {
|
|||||||
Window::clear();
|
Window::clear();
|
||||||
Window::setBgColor(vec3(0.2f));
|
Window::setBgColor(vec3(0.2f));
|
||||||
|
|
||||||
uicamera->fov = Window::height;
|
uicamera->setFov(Window::height);
|
||||||
Shader* uishader = engine->getAssets()->getShader("ui");
|
Shader* uishader = engine->getAssets()->getShader("ui");
|
||||||
uishader->use();
|
uishader->use();
|
||||||
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
||||||
@ -136,12 +136,15 @@ void LevelScreen::update(float delta) {
|
|||||||
if (!gui->isFocusCaught()) {
|
if (!gui->isFocusCaught()) {
|
||||||
updateHotkeys();
|
updateHotkeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: subscribe for setting change
|
// TODO: subscribe for setting change
|
||||||
EngineSettings& settings = engine->getSettings();
|
EngineSettings& settings = engine->getSettings();
|
||||||
|
level->player->camera->setFov(glm::radians(settings.camera.fov));
|
||||||
if (settings.graphics.backlight != backlight) {
|
if (settings.graphics.backlight != backlight) {
|
||||||
level->chunks->saveAndClear();
|
level->chunks->saveAndClear();
|
||||||
backlight = settings.graphics.backlight;
|
backlight = settings.graphics.backlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hud->isPause()) {
|
if (!hud->isPause()) {
|
||||||
level->world->updateTimers(delta);
|
level->world->updateTimers(delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,8 +41,9 @@ void CameraControl::refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CameraControl::updateMouse(PlayerInput& input) {
|
void CameraControl::updateMouse(PlayerInput& input) {
|
||||||
float rotX = -Events::deltaX / Window::height * 2;
|
float sensitivity = settings.sensitivity;
|
||||||
float rotY = -Events::deltaY / Window::height * 2;
|
float rotX = -Events::deltaX / Window::height * sensitivity;
|
||||||
|
float rotY = -Events::deltaY / Window::height * sensitivity;
|
||||||
|
|
||||||
if (input.zoom){
|
if (input.zoom){
|
||||||
rotX /= 4;
|
rotX /= 4;
|
||||||
|
|||||||
@ -37,6 +37,10 @@ struct CameraSettings {
|
|||||||
bool fovEvents = true;
|
bool fovEvents = true;
|
||||||
/* Camera movement shake */
|
/* Camera movement shake */
|
||||||
bool shaking = true;
|
bool shaking = true;
|
||||||
|
/* Camera field of view */
|
||||||
|
float fov = 90.0f;
|
||||||
|
/* Camera sensitivity */
|
||||||
|
float sensitivity = 2.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GraphicsSettings {
|
struct GraphicsSettings {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using glm::vec3;
|
|||||||
using glm::vec4;
|
using glm::vec4;
|
||||||
using glm::mat4;
|
using glm::mat4;
|
||||||
|
|
||||||
Camera::Camera(vec3 position, float fov) : position(position), fov(fov), zoom(1.0f), rotation(1.0f) {
|
Camera::Camera(vec3 position, float fov) : fov(fov), position(position), zoom(1.0f), rotation(1.0f) {
|
||||||
updateVectors();
|
updateVectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,3 +61,11 @@ mat4 Camera::getView(bool pos){
|
|||||||
mat4 Camera::getProjView(){
|
mat4 Camera::getProjView(){
|
||||||
return getProjection()*getView();
|
return getProjection()*getView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Camera::setFov(float fov) {
|
||||||
|
this->fov = fov;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Camera::getFov() const {
|
||||||
|
return fov;
|
||||||
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
void updateVectors();
|
void updateVectors();
|
||||||
|
float fov;
|
||||||
public:
|
public:
|
||||||
glm::vec3 front;
|
glm::vec3 front;
|
||||||
glm::vec3 up;
|
glm::vec3 up;
|
||||||
@ -12,7 +13,7 @@ public:
|
|||||||
glm::vec3 dir;
|
glm::vec3 dir;
|
||||||
|
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
float fov;
|
|
||||||
float zoom;
|
float zoom;
|
||||||
glm::mat4 rotation;
|
glm::mat4 rotation;
|
||||||
bool perspective = true;
|
bool perspective = true;
|
||||||
@ -25,6 +26,9 @@ public:
|
|||||||
glm::mat4 getProjection();
|
glm::mat4 getProjection();
|
||||||
glm::mat4 getView(bool position=true);
|
glm::mat4 getView(bool position=true);
|
||||||
glm::mat4 getProjView();
|
glm::mat4 getProjView();
|
||||||
|
|
||||||
|
void setFov(float fov);
|
||||||
|
float getFov() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WINDOW_CAMERA_H_ */
|
#endif /* WINDOW_CAMERA_H_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user