Browse Source

Rename configuration.hpp to config.hpp and move more constants into config.hpp

master
C. J. Howard 2 years ago
parent
commit
595990a6f8
17 changed files with 142 additions and 117 deletions
  1. +2
    -2
      CMakeLists.txt
  2. +77
    -0
      src/config.hpp.in
  3. +0
    -42
      src/configuration.hpp.in
  4. +18
    -10
      src/game/menu.cpp
  5. +0
    -21
      src/game/menu.hpp
  6. +4
    -4
      src/game/state/boot.cpp
  7. +6
    -5
      src/game/state/main-menu.cpp
  8. +2
    -1
      src/game/state/nuptial-flight.cpp
  9. +3
    -2
      src/game/state/pause-menu.cpp
  10. +1
    -1
      src/game/world.cpp
  11. +4
    -4
      src/render/passes/material-pass.cpp
  12. +3
    -3
      src/render/passes/shadow-map-pass.cpp
  13. +3
    -3
      src/render/renderer.cpp
  14. +2
    -2
      src/scene/billboard.cpp
  15. +5
    -5
      src/scene/camera.cpp
  16. +6
    -6
      src/scene/directional-light.cpp
  17. +6
    -6
      src/scene/spot-light.cpp

+ 2
- 2
CMakeLists.txt View File

@ -31,8 +31,8 @@ set(SHARED_LIBS
${OPENGL_gl_LIBRARY}) ${OPENGL_gl_LIBRARY})
# Generate configuration header file # Generate configuration header file
configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in
${PROJECT_BINARY_DIR}/src/configuration.hpp)
configure_file(${PROJECT_SOURCE_DIR}/src/config.hpp.in
${PROJECT_BINARY_DIR}/src/config.hpp)
# Collect source files # Collect source files
file(GLOB_RECURSE SOURCE_FILES file(GLOB_RECURSE SOURCE_FILES

+ 77
- 0
src/config.hpp.in View File

@ -0,0 +1,77 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CONFIG_HPP
#define ANTKEEPER_CONFIG_HPP
#include "math/vector-type.hpp"
/// Global configuration constants.
namespace config {
constexpr int version_major = @PROJECT_VERSION_MAJOR@;
constexpr int version_minor = @PROJECT_VERSION_MINOR@;
constexpr int version_patch = @PROJECT_VERSION_PATCH@;
constexpr char* version_string = "@PROJECT_VERSION@";
constexpr math::vector<float, 3> global_forward = {0.0f, 0.0f, -1.0f};
constexpr math::vector<float, 3> global_up = {0.0f, 1.0f, 0.0f};
constexpr math::vector<float, 3> global_right = {1.0f, 0.0f, 0.0f};
/// Duration of the menu fade in animation, in seconds.
constexpr float menu_fade_in_duration = 0.25f;
/// Duration of the menu fade out animation, in seconds.
constexpr float menu_fade_out_duration = 0.125f;
/// Padding of the a menu item mouseover bounds, as a percentage of the font size.
constexpr float menu_mouseover_padding = 0.1f;
/// Opacity of the menu background.
constexpr float menu_bg_opacity = 0.5f;
/// RGBA color of active menu items.
constexpr float4 menu_active_color{1.0f, 1.0f, 1.0f, 1.0f};
/// RGBA color of inactive menu items.
constexpr float4 menu_inactive_color{1.0f, 1.0f, 1.0f, 0.5f};
/// Duration of the title screen fade in, in seconds.
constexpr float title_fade_in_duration = 1.0f;
/// Duration of the fade out when quitting the game or returning to the main menu, in seconds.
constexpr float quit_fade_out_duration = 1.0f;
/// Duration of the fade out when a new colony is started, in seconds.
constexpr float new_colony_fade_out_duration = 1.0f;
/// Duration of the nuptial flight fade in, in seconds.
constexpr float nuptial_flight_fade_in_duration = 5.0f;
#define MATERIAL_PASS_MAX_AMBIENT_LIGHT_COUNT 1
#define MATERIAL_PASS_MAX_POINT_LIGHT_COUNT 1
#define MATERIAL_PASS_MAX_DIRECTIONAL_LIGHT_COUNT 2
#define MATERIAL_PASS_MAX_SPOTLIGHT_COUNT 1
#define TERRAIN_PATCH_SIZE 200.0f
#define TERRAIN_PATCH_RESOLUTION 4
#define VEGETATION_PATCH_RESOLUTION 1
} // namespace config
#endif // ANTKEEPER_CONFIG_HPP

+ 0
- 42
src/configuration.hpp.in View File

@ -1,42 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CONFIGURATION_HPP
#define ANTKEEPER_CONFIGURATION_HPP
#include "math/vector-type.hpp"
#define ANTKEEPER_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define ANTKEEPER_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define ANTKEEPER_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define ANTKEEPER_VERSION_STRING "@PROJECT_VERSION@"
constexpr math::vector<float, 3> global_forward = {0.0f, 0.0f, -1.0f};
constexpr math::vector<float, 3> global_up = {0.0f, 1.0f, 0.0f};
constexpr math::vector<float, 3> global_right = {1.0f, 0.0f, 0.0f};
#define MATERIAL_PASS_MAX_AMBIENT_LIGHT_COUNT 1
#define MATERIAL_PASS_MAX_POINT_LIGHT_COUNT 1
#define MATERIAL_PASS_MAX_DIRECTIONAL_LIGHT_COUNT 2
#define MATERIAL_PASS_MAX_SPOTLIGHT_COUNT 1
#define TERRAIN_PATCH_SIZE 200.0f
#define TERRAIN_PATCH_RESOLUTION 4
#define VEGETATION_PATCH_RESOLUTION 1
#endif // ANTKEEPER_CONFIGURATION_HPP

+ 18
- 10
src/game/menu.cpp View File

@ -23,6 +23,7 @@
#include "animation/animation.hpp" #include "animation/animation.hpp"
#include "animation/animator.hpp" #include "animation/animator.hpp"
#include "animation/ease.hpp" #include "animation/ease.hpp"
#include "config.hpp"
#include <algorithm> #include <algorithm>
namespace game { namespace game {
@ -62,7 +63,7 @@ void update_text_color(game::context& ctx)
{ {
auto [name, value] = ctx.menu_item_texts[i]; auto [name, value] = ctx.menu_item_texts[i];
const float4& color = (i == *ctx.menu_item_index) ? active_color : inactive_color;
const float4& color = (i == *ctx.menu_item_index) ? config::menu_active_color : config::menu_inactive_color;
name->set_color(color); name->set_color(color);
if (value) if (value)
@ -220,7 +221,7 @@ void setup_animations(game::context& ctx)
{ {
auto [name, value] = ctx.menu_item_texts[i]; auto [name, value] = ctx.menu_item_texts[i];
float4 color = (i == *ctx.menu_item_index) ? active_color : inactive_color;
float4 color = (i == *ctx.menu_item_index) ? config::menu_active_color : config::menu_inactive_color;
color[3] = color[3] * opacity; color[3] = color[3] * opacity;
if (name) if (name)
@ -240,14 +241,14 @@ void fade_in(game::context& ctx, const std::function& end_callback)
animation_channel<float>* opacity_channel = ctx.menu_fade_animation->get_channel(0); animation_channel<float>* opacity_channel = ctx.menu_fade_animation->get_channel(0);
opacity_channel->remove_keyframes(); opacity_channel->remove_keyframes();
opacity_channel->insert_keyframe({0.0, 0.0f}); opacity_channel->insert_keyframe({0.0, 0.0f});
opacity_channel->insert_keyframe({game::menu::fade_in_duration, 1.0f});
opacity_channel->insert_keyframe({config::menu_fade_in_duration, 1.0f});
ctx.menu_fade_animation->set_end_callback(end_callback); ctx.menu_fade_animation->set_end_callback(end_callback);
for (std::size_t i = 0; i < ctx.menu_item_texts.size(); ++i) for (std::size_t i = 0; i < ctx.menu_item_texts.size(); ++i)
{ {
auto [name, value] = ctx.menu_item_texts[i]; auto [name, value] = ctx.menu_item_texts[i];
float4 color = (i == *ctx.menu_item_index) ? active_color : inactive_color;
float4 color = (i == *ctx.menu_item_index) ? config::menu_active_color : config::menu_inactive_color;
color[3] = 0.0f; color[3] = 0.0f;
if (name) if (name)
@ -272,7 +273,7 @@ void fade_out(game::context& ctx, const std::function& end_callback)
animation_channel<float>* opacity_channel = ctx.menu_fade_animation->get_channel(0); animation_channel<float>* opacity_channel = ctx.menu_fade_animation->get_channel(0);
opacity_channel->remove_keyframes(); opacity_channel->remove_keyframes();
opacity_channel->insert_keyframe({0.0, 1.0f}); opacity_channel->insert_keyframe({0.0, 1.0f});
opacity_channel->insert_keyframe({game::menu::fade_out_duration, 0.0f});
opacity_channel->insert_keyframe({config::menu_fade_out_duration, 0.0f});
ctx.menu_fade_animation->set_end_callback(end_callback); ctx.menu_fade_animation->set_end_callback(end_callback);
ctx.menu_fade_animation->stop(); ctx.menu_fade_animation->stop();
@ -357,7 +358,7 @@ void setup_controls(game::context& ctx)
( (
[&ctx](const mouse_moved_event& event) [&ctx](const mouse_moved_event& event)
{ {
const float padding = game::menu::mouseover_padding * ctx.menu_font.get_font_metrics().size;
const float padding = config::menu_mouseover_padding * ctx.menu_font.get_font_metrics().size;
for (std::size_t i = 0; i < ctx.menu_item_texts.size(); ++i) for (std::size_t i = 0; i < ctx.menu_item_texts.size(); ++i)
{ {
@ -377,15 +378,15 @@ void setup_controls(game::context& ctx)
max_y = std::max<float>(max_y, value_bounds.max_point.y); max_y = std::max<float>(max_y, value_bounds.max_point.y);
} }
const auto& viewport = ctx.app->get_viewport_dimensions();
const float x = static_cast<float>(event.x - viewport[0] / 2);
const float y = static_cast<float>((viewport[1] - event.y + 1) - viewport[1] / 2);
min_x -= padding; min_x -= padding;
min_y -= padding; min_y -= padding;
max_x += padding; max_x += padding;
max_y += padding; max_y += padding;
const auto& viewport = ctx.app->get_viewport_dimensions();
const float x = static_cast<float>(event.x - viewport[0] / 2);
const float y = static_cast<float>((viewport[1] - event.y + 1) - viewport[1] / 2);
if (x >= min_x && x <= max_x) if (x >= min_x && x <= max_x)
{ {
if (y >= min_y && y <= max_y) if (y >= min_y && y <= max_y)
@ -403,6 +404,8 @@ void setup_controls(game::context& ctx)
( (
[&ctx](const mouse_button_pressed_event& event) [&ctx](const mouse_button_pressed_event& event)
{ {
const float padding = config::menu_mouseover_padding * ctx.menu_font.get_font_metrics().size;
for (std::size_t i = 0; i < ctx.menu_item_texts.size(); ++i) for (std::size_t i = 0; i < ctx.menu_item_texts.size(); ++i)
{ {
auto [name, value] = ctx.menu_item_texts[i]; auto [name, value] = ctx.menu_item_texts[i];
@ -421,6 +424,11 @@ void setup_controls(game::context& ctx)
max_y = std::max<float>(max_y, value_bounds.max_point.y); max_y = std::max<float>(max_y, value_bounds.max_point.y);
} }
min_x -= padding;
min_y -= padding;
max_x += padding;
max_y += padding;
const auto& viewport = ctx.app->get_viewport_dimensions(); const auto& viewport = ctx.app->get_viewport_dimensions();
const float x = static_cast<float>(event.x - viewport[0] / 2); const float x = static_cast<float>(event.x - viewport[0] / 2);
const float y = static_cast<float>((viewport[1] - event.y + 1) - viewport[1] / 2); const float y = static_cast<float>((viewport[1] - event.y + 1) - viewport[1] / 2);

+ 0
- 21
src/game/menu.hpp View File

@ -25,27 +25,6 @@
namespace game { namespace game {
namespace menu { namespace menu {
/// Delay, in seconds, to when menu input should be activated.
static constexpr float input_delay = 0.025f;
/// RGBA color of active menu items.
static constexpr float4 active_color{1.0f, 1.0f, 1.0f, 1.0f};
/// RGBA color of inactive menu items.
static constexpr float4 inactive_color{1.0f, 1.0f, 1.0f, 0.5f};
/// Opacity of the menu background.
static constexpr float bg_opacity = 2.0f / 4.0f;
/// Padding of the mouseover bounds, as a percentage of the font size.
static constexpr float mouseover_padding = 0.1f;
/// Duration of the menu fade in animation
static constexpr float fade_in_duration = 0.25f;
/// Duration of the menu fade out animation
static constexpr float fade_out_duration = 0.125f;
void init_menu_item_index(game::context& ctx, const std::string& menu_name); void init_menu_item_index(game::context& ctx, const std::string& menu_name);
void setup_controls(game::context& ctx); void setup_controls(game::context& ctx);
void setup_animations(game::context& ctx); void setup_animations(game::context& ctx);

+ 4
- 4
src/game/state/boot.cpp View File

@ -82,7 +82,7 @@
#include "input/gamepad.hpp" #include "input/gamepad.hpp"
#include "input/mouse.hpp" #include "input/mouse.hpp"
#include "input/keyboard.hpp" #include "input/keyboard.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include "input/scancode.hpp" #include "input/scancode.hpp"
#include "game/fonts.hpp" #include "game/fonts.hpp"
#include "game/controls.hpp" #include "game/controls.hpp"
@ -788,7 +788,7 @@ void boot::setup_animation()
ctx.menu_bg_fade_in_animation->set_interpolator(ease<float>::out_cubic); ctx.menu_bg_fade_in_animation->set_interpolator(ease<float>::out_cubic);
animation_channel<float>* channel = ctx.menu_bg_fade_in_animation->add_channel(0); animation_channel<float>* channel = ctx.menu_bg_fade_in_animation->add_channel(0);
channel->insert_keyframe({0.0f, 0.0f}); channel->insert_keyframe({0.0f, 0.0f});
channel->insert_keyframe({game::menu::fade_in_duration, game::menu::bg_opacity});
channel->insert_keyframe({config::menu_fade_in_duration, config::menu_bg_opacity});
ctx.menu_bg_fade_in_animation->set_frame_callback(menu_bg_frame_callback); ctx.menu_bg_fade_in_animation->set_frame_callback(menu_bg_frame_callback);
ctx.menu_bg_fade_in_animation->set_start_callback ctx.menu_bg_fade_in_animation->set_start_callback
( (
@ -808,8 +808,8 @@ void boot::setup_animation()
{ {
ctx.menu_bg_fade_out_animation->set_interpolator(ease<float>::out_cubic); ctx.menu_bg_fade_out_animation->set_interpolator(ease<float>::out_cubic);
animation_channel<float>* channel = ctx.menu_bg_fade_out_animation->add_channel(0); animation_channel<float>* channel = ctx.menu_bg_fade_out_animation->add_channel(0);
channel->insert_keyframe({0.0f, game::menu::bg_opacity});
channel->insert_keyframe({game::menu::fade_out_duration, 0.0f});
channel->insert_keyframe({0.0f, config::menu_bg_opacity});
channel->insert_keyframe({config::menu_fade_out_duration, 0.0f});
ctx.menu_bg_fade_out_animation->set_frame_callback(menu_bg_frame_callback); ctx.menu_bg_fade_out_animation->set_frame_callback(menu_bg_frame_callback);
ctx.menu_bg_fade_out_animation->set_end_callback ctx.menu_bg_fade_out_animation->set_end_callback
( (

+ 6
- 5
src/game/state/main-menu.cpp View File

@ -31,6 +31,7 @@
#include "animation/screen-transition.hpp" #include "animation/screen-transition.hpp"
#include "animation/ease.hpp" #include "animation/ease.hpp"
#include "application.hpp" #include "application.hpp"
#include "config.hpp"
#include <limits> #include <limits>
namespace game { namespace game {
@ -129,7 +130,7 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
// Start fade out to white // Start fade out to white
ctx.fade_transition_color->set_value({1, 1, 1}); ctx.fade_transition_color->set_value({1, 1, 1});
ctx.fade_transition->transition(1.0f, false, ease<float>::out_cubic, false, change_state_nuptial_flight);
ctx.fade_transition->transition(config::new_colony_fade_out_duration, false, ease<float>::out_cubic, false, change_state_nuptial_flight);
}; };
auto select_options_callback = [this, &ctx]() auto select_options_callback = [this, &ctx]()
{ {
@ -194,7 +195,7 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
game::menu::fade_out(ctx, nullptr); game::menu::fade_out(ctx, nullptr);
// Fade to black then quit // Fade to black then quit
ctx.fade_transition->transition(0.5f, false, ease<float>::out_cubic, false, std::bind(&application::close, ctx.app));
ctx.fade_transition->transition(config::quit_fade_out_duration, false, ease<float>::out_cubic, false, std::bind(&application::close, ctx.app));
}; };
// Build list of menu select callbacks // Build list of menu select callbacks
@ -224,7 +225,7 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
if (fade_in) if (fade_in)
{ {
// Fade in from black // Fade in from black
ctx.fade_transition->transition(1.0f, true, ease<float>::out_cubic);
ctx.fade_transition->transition(config::title_fade_in_duration, true, ease<float>::out_cubic);
} }
else else
{ {
@ -261,7 +262,7 @@ void main_menu::fade_in_title()
animation_channel<float>* opacity_channel = title_fade_animation.get_channel(0); animation_channel<float>* opacity_channel = title_fade_animation.get_channel(0);
opacity_channel->remove_keyframes(); opacity_channel->remove_keyframes();
opacity_channel->insert_keyframe({0.0, 0.0f}); opacity_channel->insert_keyframe({0.0, 0.0f});
opacity_channel->insert_keyframe({game::menu::fade_in_duration, 1.0f});
opacity_channel->insert_keyframe({config::menu_fade_in_duration, 1.0f});
title_fade_animation.stop(); title_fade_animation.stop();
title_fade_animation.play(); title_fade_animation.play();
} }
@ -271,7 +272,7 @@ void main_menu::fade_out_title()
animation_channel<float>* opacity_channel = title_fade_animation.get_channel(0); animation_channel<float>* opacity_channel = title_fade_animation.get_channel(0);
opacity_channel->remove_keyframes(); opacity_channel->remove_keyframes();
opacity_channel->insert_keyframe({0.0, 1.0f}); opacity_channel->insert_keyframe({0.0, 1.0f});
opacity_channel->insert_keyframe({game::menu::fade_out_duration, 0.0f});
opacity_channel->insert_keyframe({config::menu_fade_out_duration, 0.0f});
title_fade_animation.stop(); title_fade_animation.stop();
title_fade_animation.play(); title_fade_animation.play();
} }

+ 2
- 1
src/game/state/nuptial-flight.cpp View File

@ -40,6 +40,7 @@
#include <memory> #include <memory>
#include <iostream> #include <iostream>
#include "state-machine.hpp" #include "state-machine.hpp"
#include "config.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -115,7 +116,7 @@ nuptial_flight::nuptial_flight(game::context& ctx):
// Queue fade in // Queue fade in
ctx.fade_transition_color->set_value({1, 1, 1}); ctx.fade_transition_color->set_value({1, 1, 1});
ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, 5.0f, true, ease<float>::out_sine, true, nullptr));
ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, config::nuptial_flight_fade_in_duration, true, ease<float>::out_sine, true, nullptr));
// Queue control setup // Queue control setup
ctx.function_queue.push(std::bind(&nuptial_flight::enable_controls, this)); ctx.function_queue.push(std::bind(&nuptial_flight::enable_controls, this));

+ 3
- 2
src/game/state/pause-menu.cpp View File

@ -29,6 +29,7 @@
#include "scene/text.hpp" #include "scene/text.hpp"
#include "debug/logger.hpp" #include "debug/logger.hpp"
#include "animation/screen-transition.hpp" #include "animation/screen-transition.hpp"
#include "config.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -147,7 +148,7 @@ pause_menu::pause_menu(game::context& ctx):
// Fade out to black then return to main menu // Fade out to black then return to main menu
ctx.fade_transition_color->set_value({0, 0, 0}); ctx.fade_transition_color->set_value({0, 0, 0});
ctx.fade_transition->transition(1.0f, false, ease<float>::out_cubic, false, fade_out_callback);
ctx.fade_transition->transition(config::quit_fade_out_duration, false, ease<float>::out_cubic, false, fade_out_callback);
}; };
auto select_quit_callback = [&ctx]() auto select_quit_callback = [&ctx]()
{ {
@ -165,7 +166,7 @@ pause_menu::pause_menu(game::context& ctx):
// Fade out to black then quit // Fade out to black then quit
ctx.fade_transition_color->set_value({0, 0, 0}); ctx.fade_transition_color->set_value({0, 0, 0});
ctx.fade_transition->transition(1.0f, false, ease<float>::out_cubic, false, std::bind(&application::close, ctx.app));
ctx.fade_transition->transition(config::quit_fade_out_duration, false, ease<float>::out_cubic, false, std::bind(&application::close, ctx.app));
}; };
// Build list of menu select callbacks // Build list of menu select callbacks

+ 1
- 1
src/game/world.cpp View File

@ -48,7 +48,7 @@
#include "gl/texture-wrapping.hpp" #include "gl/texture-wrapping.hpp"
#include "gl/texture-filter.hpp" #include "gl/texture-filter.hpp"
#include "render/material-flags.hpp" #include "render/material-flags.hpp"
#include "configuration.hpp"
#include "config.hpp"
namespace game { namespace game {
namespace world { namespace world {

+ 4
- 4
src/render/passes/material-pass.cpp View File

@ -18,7 +18,7 @@
*/ */
#include "render/passes/material-pass.hpp" #include "render/passes/material-pass.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp"
#include "gl/rasterizer.hpp" #include "gl/rasterizer.hpp"
#include "gl/framebuffer.hpp" #include "gl/framebuffer.hpp"
@ -41,7 +41,7 @@
#include "scene/directional-light.hpp" #include "scene/directional-light.hpp"
#include "scene/point-light.hpp" #include "scene/point-light.hpp"
#include "scene/spot-light.hpp" #include "scene/spot-light.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include <cmath> #include <cmath>
#include <glad/glad.h> #include <glad/glad.h>
@ -208,8 +208,8 @@ void material_pass::render(const render::context& ctx, render::queue& queue) con
directional_light_texture_opacities[directional_light_count] = directional_light->get_light_texture_opacity_tween().interpolate(ctx.alpha); directional_light_texture_opacities[directional_light_count] = directional_light->get_light_texture_opacity_tween().interpolate(ctx.alpha);
math::transform<float> light_transform = light->get_transform_tween().interpolate(ctx.alpha); math::transform<float> light_transform = light->get_transform_tween().interpolate(ctx.alpha);
float3 forward = light_transform.rotation * global_forward;
float3 up = light_transform.rotation * global_up;
float3 forward = light_transform.rotation * config::global_forward;
float3 up = light_transform.rotation * config::global_up;
float4x4 light_view = math::look_at(light_transform.translation, light_transform.translation + forward, up); float4x4 light_view = math::look_at(light_transform.translation, light_transform.translation + forward, up);
float2 scale = directional_light->get_light_texture_scale_tween().interpolate(ctx.alpha); float2 scale = directional_light->get_light_texture_scale_tween().interpolate(ctx.alpha);

+ 3
- 3
src/render/passes/shadow-map-pass.cpp View File

@ -31,7 +31,7 @@
#include "scene/light.hpp" #include "scene/light.hpp"
#include "geom/view-frustum.hpp" #include "geom/view-frustum.hpp"
#include "geom/aabb.hpp" #include "geom/aabb.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include <cmath> #include <cmath>
#include <glad/glad.h> #include <glad/glad.h>
@ -138,8 +138,8 @@ void shadow_map_pass::render(const render::context& ctx, render::queue& queue) c
// Calculate a view-projection matrix from the directional light's transform // Calculate a view-projection matrix from the directional light's transform
math::transform<float> light_transform = light->get_transform_tween().interpolate(ctx.alpha); math::transform<float> light_transform = light->get_transform_tween().interpolate(ctx.alpha);
float3 forward = light_transform.rotation * global_forward;
float3 up = light_transform.rotation * global_up;
float3 forward = light_transform.rotation * config::global_forward;
float3 up = light_transform.rotation * config::global_up;
float4x4 light_view = math::look_at(light_transform.translation, light_transform.translation + forward, up); float4x4 light_view = math::look_at(light_transform.translation, light_transform.translation + forward, up);
float4x4 light_projection = math::ortho_half_z(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); float4x4 light_projection = math::ortho_half_z(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
float4x4 light_view_projection = light_projection * light_view; float4x4 light_view_projection = light_projection * light_view;

+ 3
- 3
src/render/renderer.cpp View File

@ -30,7 +30,7 @@
#include "gl/drawing-mode.hpp" #include "gl/drawing-mode.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "geom/projection.hpp" #include "geom/projection.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include <functional> #include <functional>
#include <set> #include <set>
@ -95,8 +95,8 @@ void renderer::render(float t, float dt, float alpha, const scene::collection& c
// Update render context with camera parameters // Update render context with camera parameters
ctx.camera = camera; ctx.camera = camera;
ctx.camera_transform = camera->get_transform_tween().interpolate(alpha); ctx.camera_transform = camera->get_transform_tween().interpolate(alpha);
ctx.camera_forward = ctx.camera_transform.rotation * global_forward;
ctx.camera_up = ctx.camera_transform.rotation * global_up;
ctx.camera_forward = ctx.camera_transform.rotation * config::global_forward;
ctx.camera_up = ctx.camera_transform.rotation * config::global_up;
ctx.clip_near = camera->get_view_frustum().get_near(); ///< TODO: tween this ctx.clip_near = camera->get_view_frustum().get_near(); ///< TODO: tween this
// Create render queue // Create render queue

+ 2
- 2
src/scene/billboard.cpp View File

@ -18,7 +18,7 @@
*/ */
#include "scene/billboard.hpp" #include "scene/billboard.hpp"
#include "configuration.hpp"
#include "config.hpp"
namespace scene { namespace scene {
@ -28,7 +28,7 @@ billboard::billboard():
world_bounds(local_bounds), world_bounds(local_bounds),
material(nullptr), material(nullptr),
type(billboard_type::flat), type(billboard_type::flat),
alignment_axis(global_up)
alignment_axis(config::global_up)
{} {}
billboard::billboard(const billboard& other) billboard::billboard(const billboard& other)

+ 5
- 5
src/scene/camera.cpp View File

@ -18,7 +18,7 @@
*/ */
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include "animation/ease.hpp" #include "animation/ease.hpp"
#include "math/constants.hpp" #include "math/constants.hpp"
#include "math/interpolation.hpp" #include "math/interpolation.hpp"
@ -28,8 +28,8 @@ namespace scene {
static float4x4 interpolate_view(const camera* camera, const float4x4& x, const float4x4& y, float a) static float4x4 interpolate_view(const camera* camera, const float4x4& x, const float4x4& y, float a)
{ {
math::transform<float> transform = camera->get_transform_tween().interpolate(a); math::transform<float> transform = camera->get_transform_tween().interpolate(a);
float3 forward = transform.rotation * global_forward;
float3 up = transform.rotation * global_up;
float3 forward = transform.rotation * config::global_forward;
float3 up = transform.rotation * config::global_up;
return math::look_at(transform.translation, transform.translation + forward, up); return math::look_at(transform.translation, transform.translation + forward, up);
} }
@ -184,8 +184,8 @@ void camera::update_tweens()
void camera::transformed() void camera::transformed()
{ {
// Recalculate view and view-projection matrices // Recalculate view and view-projection matrices
float3 forward = get_rotation() * global_forward;
float3 up = get_rotation() * global_up;
float3 forward = get_rotation() * config::global_forward;
float3 up = get_rotation() * config::global_up;
view[1] = math::look_at(get_translation(), get_translation() + forward, up); view[1] = math::look_at(get_translation(), get_translation() + forward, up);
view_projection[1] = projection[1] * view[1]; view_projection[1] = projection[1] * view[1];

+ 6
- 6
src/scene/directional-light.cpp View File

@ -18,20 +18,20 @@
*/ */
#include "directional-light.hpp" #include "directional-light.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include "math/math.hpp" #include "math/math.hpp"
namespace scene { namespace scene {
static float3 interpolate_direction(const float3& x, const float3& y, float a) static float3 interpolate_direction(const float3& x, const float3& y, float a)
{ {
math::quaternion<float> q0 = math::rotation(global_forward, x);
math::quaternion<float> q1 = math::rotation(global_forward, y);
return math::normalize(math::slerp(q0, q1, a) * global_forward);
math::quaternion<float> q0 = math::rotation(config::global_forward, x);
math::quaternion<float> q1 = math::rotation(config::global_forward, y);
return math::normalize(math::slerp(q0, q1, a) * config::global_forward);
} }
directional_light::directional_light(): directional_light::directional_light():
direction(global_forward, interpolate_direction),
direction(config::global_forward, interpolate_direction),
light_texture(nullptr), light_texture(nullptr),
light_texture_opacity(1.0f, math::lerp<float, float>), light_texture_opacity(1.0f, math::lerp<float, float>),
light_texture_scale({1.0f, 1.0f}, math::lerp<float2, float>) light_texture_scale({1.0f, 1.0f}, math::lerp<float2, float>)
@ -66,7 +66,7 @@ void directional_light::update_tweens()
void directional_light::transformed() void directional_light::transformed()
{ {
direction[1] = math::normalize(get_transform().rotation * global_forward);
direction[1] = math::normalize(get_transform().rotation * config::global_forward);
} }
} // namespace scene } // namespace scene

+ 6
- 6
src/scene/spot-light.cpp View File

@ -18,7 +18,7 @@
*/ */
#include "spot-light.hpp" #include "spot-light.hpp"
#include "configuration.hpp"
#include "config.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include <cmath> #include <cmath>
@ -26,13 +26,13 @@ namespace scene {
static float3 interpolate_direction(const float3& x, const float3& y, float a) static float3 interpolate_direction(const float3& x, const float3& y, float a)
{ {
math::quaternion<float> q0 = math::rotation(global_forward, x);
math::quaternion<float> q1 = math::rotation(global_forward, y);
return math::normalize(math::slerp(q0, q1, a) * global_forward);
math::quaternion<float> q0 = math::rotation(config::global_forward, x);
math::quaternion<float> q1 = math::rotation(config::global_forward, y);
return math::normalize(math::slerp(q0, q1, a) * config::global_forward);
} }
spot_light::spot_light(): spot_light::spot_light():
direction(global_forward, interpolate_direction),
direction(config::global_forward, interpolate_direction),
attenuation(float3{1, 0, 0}, math::lerp<float3, float>), attenuation(float3{1, 0, 0}, math::lerp<float3, float>),
cutoff(float2{math::pi<float>, math::pi<float>}, math::lerp<float2, float>), cutoff(float2{math::pi<float>, math::pi<float>}, math::lerp<float2, float>),
cosine_cutoff(float2{std::cos(math::pi<float>), std::cos(math::pi<float>)}, math::lerp<float2, float>) cosine_cutoff(float2{std::cos(math::pi<float>), std::cos(math::pi<float>)}, math::lerp<float2, float>)
@ -60,7 +60,7 @@ void spot_light::update_tweens()
void spot_light::transformed() void spot_light::transformed()
{ {
direction[1] = math::normalize(get_transform().rotation * global_forward);
direction[1] = math::normalize(get_transform().rotation * config::global_forward);
} }
} // namespace scene } // namespace scene

Loading…
Cancel
Save