Browse Source

Add lens and flashlight spotlight

master
C. J. Howard 4 years ago
parent
commit
d6ff0a07fb
10 changed files with 93 additions and 17 deletions
  1. +27
    -10
      src/game/bootloader.cpp
  2. +35
    -0
      src/game/components/render-component.hpp
  3. +11
    -0
      src/game/entity-commands.cpp
  4. +1
    -0
      src/game/entity-commands.hpp
  5. +2
    -1
      src/game/game-context.hpp
  6. +1
    -1
      src/game/states/play-state.cpp
  7. +2
    -2
      src/game/systems/camera-system.cpp
  8. +6
    -0
      src/game/systems/control-system.hpp
  9. +7
    -2
      src/game/systems/render-system.hpp
  10. +1
    -1
      src/renderer/passes/material-pass.cpp

+ 27
- 10
src/game/bootloader.cpp View File

@ -75,6 +75,7 @@
#include "game/systems/tool-system.hpp" #include "game/systems/tool-system.hpp"
#include "game/systems/ui-system.hpp" #include "game/systems/ui-system.hpp"
#include "game/systems/vegetation-system.hpp" #include "game/systems/vegetation-system.hpp"
#include "game/entity-commands.hpp"
#include "utility/paths.hpp" #include "utility/paths.hpp"
#include "event/event-dispatcher.hpp" #include "event/event-dispatcher.hpp"
#include "input/input-event-router.hpp" #include "input/input-event-router.hpp"
@ -607,19 +608,25 @@ void setup_scenes(game_context* ctx)
ctx->subterrain_light->set_attenuation({1.0f, 0.09f, 0.032f}); ctx->subterrain_light->set_attenuation({1.0f, 0.09f, 0.032f});
ctx->subterrain_light->update_tweens(); ctx->subterrain_light->update_tweens();
ctx->spotlight = new spotlight();
ctx->spotlight->set_color({1, 1, 1});
ctx->spotlight->set_intensity(1.0f);
ctx->spotlight->set_attenuation({1.0f, 0.09f, 0.032f});
ctx->spotlight->set_cutoff({math::radians(15.0f), math::radians(30.0f)});
ctx->spotlight->update_tweens();
ctx->spotlight->set_active(false);
ctx->underworld_ambient_light = new ambient_light(); ctx->underworld_ambient_light = new ambient_light();
ctx->underworld_ambient_light->set_color({1, 1, 1}); ctx->underworld_ambient_light->set_color({1, 1, 1});
ctx->underworld_ambient_light->set_intensity(0.1f); ctx->underworld_ambient_light->set_intensity(0.1f);
ctx->underworld_ambient_light->update_tweens(); ctx->underworld_ambient_light->update_tweens();
ctx->lens_spotlight = new spotlight();
ctx->lens_spotlight->set_color({1, 1, 1});
ctx->lens_spotlight->set_intensity(20.0f);
ctx->lens_spotlight->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->lens_spotlight->set_cutoff({math::radians(1.25f), math::radians(1.8f)});
ctx->flashlight_spotlight = new spotlight();
ctx->flashlight_spotlight->set_color({1, 1, 1});
ctx->flashlight_spotlight->set_intensity(1.0f);
ctx->flashlight_spotlight->set_attenuation({1.0f, 0.0f, 0.0f});
ctx->flashlight_spotlight->set_cutoff({math::radians(10.0f), math::radians(19.0f)});
const texture_2d* splash_texture = ctx->resource_manager->load<texture_2d>("splash.png"); const texture_2d* splash_texture = ctx->resource_manager->load<texture_2d>("splash.png");
auto splash_dimensions = splash_texture->get_dimensions(); auto splash_dimensions = splash_texture->get_dimensions();
ctx->splash_billboard_material = new material(); ctx->splash_billboard_material = new material();
@ -695,6 +702,9 @@ void setup_scenes(game_context* ctx)
ctx->ui_scene = new scene(); ctx->ui_scene = new scene();
ctx->ui_scene->add_object(ctx->ui_camera); ctx->ui_scene->add_object(ctx->ui_camera);
ctx->overworld_scene->add_object(ctx->lens_spotlight);
ctx->underworld_scene->add_object(ctx->flashlight_spotlight);
// Set overworld as active scene // Set overworld as active scene
ctx->active_scene = ctx->overworld_scene; ctx->active_scene = ctx->overworld_scene;
@ -893,12 +903,12 @@ void setup_controls(game_context* ctx)
ctx->rotate_ccw_control = new control(); ctx->rotate_ccw_control = new control();
ctx->rotate_ccw_control->set_activated_callback ctx->rotate_ccw_control->set_activated_callback
( (
std::bind(&camera_system::pan, ctx->camera_system, math::radians(-90.0f))
std::bind(&camera_system::pan, ctx->camera_system, math::radians(90.0f))
); );
ctx->rotate_cw_control = new control(); ctx->rotate_cw_control = new control();
ctx->rotate_cw_control->set_activated_callback ctx->rotate_cw_control->set_activated_callback
( (
std::bind(&camera_system::pan, ctx->camera_system, math::radians(90.0f))
std::bind(&camera_system::pan, ctx->camera_system, math::radians(-90.0f))
); );
// Create menu back control // Create menu back control
@ -1058,6 +1068,13 @@ void setup_callbacks(game_context* ctx)
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point(); //(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();
auto xf = ec::get_transform(*ctx->ecs_registry, ctx->lens_entity);
ctx->lens_spotlight->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0});
xf = ec::get_transform(*ctx->ecs_registry, ctx->flashlight_entity);
//ctx->flashlight_spotlight->set_transform(xf);
ctx->flashlight_spotlight->look_at(xf.translation, xf.translation + xf.rotation * float3{0, 0, 1}, {0, 0, -1});
ctx->ui_system->update(dt); ctx->ui_system->update(dt);
ctx->render_system->update(t, dt); ctx->render_system->update(t, dt);
ctx->animator->animate(dt); ctx->animator->animate(dt);

+ 35
- 0
src/game/components/render-component.hpp View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2020 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_ECS_RENDER_COMPONENT_HPP
#define ANTKEEPER_ECS_RENDER_COMPONENT_HPP
class scene_object_base;
namespace ecs {
struct render_component
{
scene_object_base* object;
unsigned int layers;
};
} // namespace ecs
#endif // ANTKEEPER_ECS_RENDER_COMPONENT_HPP

+ 11
- 0
src/game/entity-commands.cpp View File

@ -92,4 +92,15 @@ void bind_transform(entt::registry& registry, entt::entity source_eid, entt::ent
registry.assign_or_replace<copy_transform_component>(source_eid, copy_transform); registry.assign_or_replace<copy_transform_component>(source_eid, copy_transform);
} }
math::transform<float> get_transform(entt::registry& registry, entt::entity eid)
{
if (registry.has<transform_component>(eid))
{
const transform_component& component = registry.get<transform_component>(eid);
return component.transform;
}
return math::identity_transform<float>;
}
} // namespace ec } // namespace ec

+ 1
- 0
src/game/entity-commands.hpp View File

@ -33,6 +33,7 @@ void set_transform(entt::registry& registry, entt::entity eid, const math::trans
void place(entt::registry& registry, entt::entity eid, const float2& translation); void place(entt::registry& registry, entt::entity eid, const float2& translation);
void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers); void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers);
void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid); void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid);
math::transform<float> get_transform(entt::registry& registry, entt::entity eid);
} // namespace ec } // namespace ec

+ 2
- 1
src/game/game-context.hpp View File

@ -174,9 +174,10 @@ struct game_context
directional_light* sun_direct; directional_light* sun_direct;
point_light* subterrain_light; point_light* subterrain_light;
ambient_light* underworld_ambient_light; ambient_light* underworld_ambient_light;
spotlight* spotlight;
billboard* splash_billboard; billboard* splash_billboard;
aabb<float> no_cull; aabb<float> no_cull;
spotlight* lens_spotlight;
spotlight* flashlight_spotlight;
// Animation // Animation
timeline* timeline; timeline* timeline;

+ 1
- 1
src/game/states/play-state.cpp View File

@ -147,7 +147,7 @@ void play_state_enter(game_context* ctx)
auto nest_entity = nest_archetype->create(ecs_registry); auto nest_entity = nest_archetype->create(ecs_registry);
// Create terrain // Create terrain
int terrain_radius = 2;
int terrain_radius = 4;
for (int x = -terrain_radius; x <= terrain_radius; ++x) for (int x = -terrain_radius; x <= terrain_radius; ++x)
{ {
for (int z = -terrain_radius; z <= terrain_radius; ++z) for (int z = -terrain_radius; z <= terrain_radius; ++z)

+ 2
- 2
src/game/systems/camera-system.cpp View File

@ -34,8 +34,8 @@ camera_system::camera_system(entt::registry& registry):
viewport{0, 0, 0, 0}, viewport{0, 0, 0, 0},
mouse_position{0, 0} mouse_position{0, 0}
{ {
//orbit_cam.set_elevation_limits({math::radians(5.0f), math::radians(89.0f)});
orbit_cam.set_elevation_limits({math::radians(-89.0f), math::radians(89.0f)});
orbit_cam.set_elevation_limits({math::radians(5.0f), math::radians(89.0f)});
//orbit_cam.set_elevation_limits({math::radians(-89.0f), math::radians(89.0f)});
orbit_cam.set_focal_distance_limits({2.0f, 200.0f}); orbit_cam.set_focal_distance_limits({2.0f, 200.0f});
orbit_cam.set_fov_limits({math::radians(80.0f), math::radians(35.0f)}); orbit_cam.set_fov_limits({math::radians(80.0f), math::radians(35.0f)});
orbit_cam.set_clip_near_limits({0.1f, 5.0f}); orbit_cam.set_clip_near_limits({0.1f, 5.0f});

+ 6
- 0
src/game/systems/control-system.hpp View File

@ -71,6 +71,9 @@ public:
control* get_descend_control(); control* get_descend_control();
control* get_toggle_view_control(); control* get_toggle_view_control();
control* get_tool_menu_control(); control* get_tool_menu_control();
control* get_equip_lens_control();
control* get_equip_brush_control();
control* get_equip_forceps_control();
private: private:
virtual void handle_event(const mouse_moved_event& event); virtual void handle_event(const mouse_moved_event& event);
@ -92,6 +95,9 @@ private:
control descend_control; control descend_control;
control toggle_view_control; control toggle_view_control;
control tool_menu_control; control tool_menu_control;
control equip_lens_control;
control equip_brush_control;
control equip_forceps_control;;
float zoom_speed; float zoom_speed;
float min_elevation; float min_elevation;

+ 7
- 2
src/game/systems/render-system.hpp View File

@ -24,6 +24,7 @@
#include "scene/scene.hpp" #include "scene/scene.hpp"
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"
#include "game/components/model-component.hpp" #include "game/components/model-component.hpp"
#include "game/components/render-component.hpp"
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -47,11 +48,15 @@ public:
private: private:
void update_model_and_materials(entt::entity entity, ecs::model_component& model); void update_model_and_materials(entt::entity entity, ecs::model_component& model);
void on_model_construct(entt::registry& registry, entt::entity entity, ecs::model_component& model); void on_model_construct(entt::registry& registry, entt::entity entity, ecs::model_component& model);
void on_model_replace(entt::registry& registry, entt::entity entity, ecs::model_component& model); void on_model_replace(entt::registry& registry, entt::entity entity, ecs::model_component& model);
void on_model_destroy(entt::registry& registry, entt::entity entity); void on_model_destroy(entt::registry& registry, entt::entity entity);
void on_component_construct(entt::registry& registry, entt::entity entity, ecs::render_component& component);
void on_component_replace(entt::registry& registry, entt::entity entity, ecs::render_component& component);
void on_component_destroy(entt::registry& registry, entt::entity entity);
renderer* renderer; renderer* renderer;
std::vector<scene*> layers; std::vector<scene*> layers;
std::unordered_map<entt::entity, model_instance*> model_instances; std::unordered_map<entt::entity, model_instance*> model_instances;

+ 1
- 1
src/renderer/passes/material-pass.cpp View File

@ -215,7 +215,7 @@ void material_pass::render(render_context* context) const
// Transform direction into view-space // Transform direction into view-space
float3 direction = spotlight->get_direction_tween().interpolate(context->alpha); float3 direction = spotlight->get_direction_tween().interpolate(context->alpha);
float3 view_space_direction = math::normalize(math::resize<3>(view * math::resize<4>(-direction)));
float3 view_space_direction = math::normalize(math::resize<3>(view * float4{-direction.x, -direction.y, -direction.z, 0.0f}));
spotlight_directions[spotlight_count] = view_space_direction; spotlight_directions[spotlight_count] = view_space_direction;
spotlight_attenuations[spotlight_count] = spotlight->get_attenuation_tween().interpolate(context->alpha); spotlight_attenuations[spotlight_count] = spotlight->get_attenuation_tween().interpolate(context->alpha);

Loading…
Cancel
Save