diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 2c4b14f..655a7a3 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -75,6 +75,7 @@ #include "game/systems/tool-system.hpp" #include "game/systems/ui-system.hpp" #include "game/systems/vegetation-system.hpp" +#include "game/entity-commands.hpp" #include "utility/paths.hpp" #include "event/event-dispatcher.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->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->set_color({1, 1, 1}); ctx->underworld_ambient_light->set_intensity(0.1f); 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("splash.png"); auto splash_dimensions = splash_texture->get_dimensions(); ctx->splash_billboard_material = new material(); @@ -695,6 +702,9 @@ void setup_scenes(game_context* ctx) ctx->ui_scene = new scene(); 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 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->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->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 @@ -1058,6 +1068,13 @@ void setup_callbacks(game_context* ctx) //(*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->render_system->update(t, dt); ctx->animator->animate(dt); diff --git a/src/game/components/render-component.hpp b/src/game/components/render-component.hpp new file mode 100644 index 0000000..ed42f24 --- /dev/null +++ b/src/game/components/render-component.hpp @@ -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 . + */ + +#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 diff --git a/src/game/entity-commands.cpp b/src/game/entity-commands.cpp index 4d19056..b062a2e 100644 --- a/src/game/entity-commands.cpp +++ b/src/game/entity-commands.cpp @@ -92,4 +92,15 @@ void bind_transform(entt::registry& registry, entt::entity source_eid, entt::ent registry.assign_or_replace(source_eid, copy_transform); } +math::transform get_transform(entt::registry& registry, entt::entity eid) +{ + if (registry.has(eid)) + { + const transform_component& component = registry.get(eid); + return component.transform; + } + + return math::identity_transform; +} + } // namespace ec diff --git a/src/game/entity-commands.hpp b/src/game/entity-commands.hpp index fd5251f..ea9f2c7 100644 --- a/src/game/entity-commands.hpp +++ b/src/game/entity-commands.hpp @@ -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 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); +math::transform get_transform(entt::registry& registry, entt::entity eid); } // namespace ec diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index 5421064..2a3388d 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -174,9 +174,10 @@ struct game_context directional_light* sun_direct; point_light* subterrain_light; ambient_light* underworld_ambient_light; - spotlight* spotlight; billboard* splash_billboard; aabb no_cull; + spotlight* lens_spotlight; + spotlight* flashlight_spotlight; // Animation timeline* timeline; diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 9bc213f..2f3b210 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -147,7 +147,7 @@ void play_state_enter(game_context* ctx) auto nest_entity = nest_archetype->create(ecs_registry); // Create terrain - int terrain_radius = 2; + int terrain_radius = 4; for (int x = -terrain_radius; x <= terrain_radius; ++x) { for (int z = -terrain_radius; z <= terrain_radius; ++z) diff --git a/src/game/systems/camera-system.cpp b/src/game/systems/camera-system.cpp index 56a9861..3421077 100644 --- a/src/game/systems/camera-system.cpp +++ b/src/game/systems/camera-system.cpp @@ -34,8 +34,8 @@ camera_system::camera_system(entt::registry& registry): viewport{0, 0, 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_fov_limits({math::radians(80.0f), math::radians(35.0f)}); orbit_cam.set_clip_near_limits({0.1f, 5.0f}); diff --git a/src/game/systems/control-system.hpp b/src/game/systems/control-system.hpp index 84d270c..a4d5dbf 100644 --- a/src/game/systems/control-system.hpp +++ b/src/game/systems/control-system.hpp @@ -71,6 +71,9 @@ public: control* get_descend_control(); control* get_toggle_view_control(); control* get_tool_menu_control(); + control* get_equip_lens_control(); + control* get_equip_brush_control(); + control* get_equip_forceps_control(); private: virtual void handle_event(const mouse_moved_event& event); @@ -92,6 +95,9 @@ private: control descend_control; control toggle_view_control; control tool_menu_control; + control equip_lens_control; + control equip_brush_control; + control equip_forceps_control;; float zoom_speed; float min_elevation; diff --git a/src/game/systems/render-system.hpp b/src/game/systems/render-system.hpp index f237f3a..2cd9ecb 100644 --- a/src/game/systems/render-system.hpp +++ b/src/game/systems/render-system.hpp @@ -24,6 +24,7 @@ #include "scene/scene.hpp" #include "scene/model-instance.hpp" #include "game/components/model-component.hpp" +#include "game/components/render-component.hpp" #include #include @@ -47,11 +48,15 @@ public: private: 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_replace(entt::registry& registry, entt::entity entity, ecs::model_component& model); 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; std::vector layers; std::unordered_map model_instances; diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index a3196bb..bad3980 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -215,7 +215,7 @@ void material_pass::render(render_context* context) const // Transform direction into view-space 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_attenuations[spotlight_count] = spotlight->get_attenuation_tween().interpolate(context->alpha);