Browse Source

Rename scene class to collection and move all scene-related classes into the scene namespace

master
C. J. Howard 4 years ago
parent
commit
978ad7add6
58 changed files with 474 additions and 375 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +1
    -2
      src/animation/camera-rig.cpp
  3. +5
    -5
      src/animation/camera-rig.hpp
  4. +2
    -2
      src/animation/screen-transition.cpp
  5. +3
    -3
      src/animation/screen-transition.hpp
  6. +17
    -22
      src/game/bootloader.cpp
  7. +17
    -23
      src/game/game-context.hpp
  8. +0
    -1
      src/game/states/map-state.cpp
  9. +2
    -2
      src/game/states/play-state.cpp
  10. +1
    -1
      src/game/states/splash-state.cpp
  11. +1
    -3
      src/game/systems/camera-system.cpp
  12. +3
    -3
      src/game/systems/camera-system.hpp
  13. +2
    -3
      src/game/systems/control-system.cpp
  14. +5
    -5
      src/game/systems/control-system.hpp
  15. +5
    -7
      src/game/systems/painting-system.cpp
  16. +5
    -5
      src/game/systems/painting-system.hpp
  17. +6
    -6
      src/game/systems/render-system.cpp
  18. +5
    -5
      src/game/systems/render-system.hpp
  19. +4
    -6
      src/game/systems/subterrain-system.cpp
  20. +5
    -5
      src/game/systems/subterrain-system.hpp
  21. +1
    -2
      src/game/systems/tool-system.cpp
  22. +3
    -3
      src/game/systems/tool-system.hpp
  23. +6
    -6
      src/game/systems/tracking-system.cpp
  24. +9
    -5
      src/game/systems/tracking-system.hpp
  25. +10
    -10
      src/game/systems/ui-system.cpp
  26. +11
    -12
      src/game/systems/ui-system.hpp
  27. +8
    -8
      src/game/systems/vegetation-system.cpp
  28. +7
    -3
      src/game/systems/vegetation-system.hpp
  29. +11
    -12
      src/renderer/passes/material-pass.cpp
  30. +2
    -4
      src/renderer/passes/shadow-map-pass.cpp
  31. +3
    -4
      src/renderer/passes/shadow-map-pass.hpp
  32. +1
    -3
      src/renderer/passes/sky-pass.cpp
  33. +2
    -3
      src/renderer/passes/ui-pass.cpp
  34. +4
    -5
      src/renderer/render-context.hpp
  35. +26
    -26
      src/renderer/renderer.cpp
  36. +16
    -12
      src/renderer/renderer.hpp
  37. +7
    -3
      src/scene/ambient-light.hpp
  38. +5
    -1
      src/scene/billboard.cpp
  39. +9
    -5
      src/scene/billboard.hpp
  40. +4
    -1
      src/scene/camera.cpp
  41. +10
    -6
      src/scene/camera.hpp
  42. +11
    -10
      src/scene/collection.cpp
  43. +84
    -0
      src/scene/collection.hpp
  44. +3
    -0
      src/scene/directional-light.cpp
  45. +8
    -4
      src/scene/directional-light.hpp
  46. +5
    -1
      src/scene/light.cpp
  47. +10
    -6
      src/scene/light.hpp
  48. +7
    -3
      src/scene/lod-group.cpp
  49. +15
    -11
      src/scene/lod-group.hpp
  50. +5
    -1
      src/scene/model-instance.cpp
  51. +9
    -5
      src/scene/model-instance.hpp
  52. +12
    -8
      src/scene/object.cpp
  53. +23
    -19
      src/scene/object.hpp
  54. +4
    -0
      src/scene/point-light.cpp
  55. +8
    -4
      src/scene/point-light.hpp
  56. +14
    -56
      src/scene/scene.hpp
  57. +3
    -0
      src/scene/spotlight.cpp
  58. +8
    -4
      src/scene/spotlight.hpp

+ 1
- 0
CMakeLists.txt View File

@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies
set(STATIC_LIBS
dr_wav

+ 1
- 2
src/animation/camera-rig.cpp View File

@ -18,7 +18,6 @@
*/
#include "animation/camera-rig.hpp"
#include "scene/camera.hpp"
#include "math/constants.hpp"
#include "configuration.hpp"
#include <algorithm>
@ -32,7 +31,7 @@ camera_rig::camera_rig():
up(global_up)
{}
void camera_rig::attach(::camera* camera)
void camera_rig::attach(scene::camera* camera)
{
this->camera = camera;
if (camera != nullptr)

+ 5
- 5
src/animation/camera-rig.hpp View File

@ -22,9 +22,9 @@
#include "math/quaternion-type.hpp"
#include "math/transform-type.hpp"
#include "scene/camera.hpp"
#include "utility/fundamental-types.hpp"
class camera;
/**
* Abstract base class for camera rigs which control the movement of cameras.
@ -49,7 +49,7 @@ public:
*
* @param camera Camera to attach.
*/
void attach(::camera* camera);
void attach(scene::camera* camera);
/**
* Detaches the camera from the rig.
@ -61,7 +61,7 @@ public:
/**
* Returns the attached camera.
*/
const ::camera* get_camera() const;
const scene::camera* get_camera() const;
const float3& get_translation() const;
const quaternion_type& get_rotation() const;
@ -79,14 +79,14 @@ protected:
void update_projection(float clip_left, float clip_right, float clip_bottom, float clip_top, float clip_near, float clip_far);
private:
camera* camera;
scene::camera* camera;
transform_type transform;
float3 forward;
float3 right;
float3 up;
};
inline const camera* camera_rig::get_camera() const
inline const scene::camera* camera_rig::get_camera() const
{
return camera;
}

+ 2
- 2
src/animation/screen-transition.cpp View File

@ -37,13 +37,13 @@ screen_transition::screen_transition()
// Setup animation start callback to show transition billboard
animation.set_start_callback
(
std::bind(&scene_object_base::set_active, &billboard, true)
std::bind(&scene::object_base::set_active, &billboard, true)
);
// Setup animation end callback to hide transition billboard
animation.set_end_callback
(
std::bind(&scene_object_base::set_active, &billboard, false)
std::bind(&scene::object_base::set_active, &billboard, false)
);
// Setup animation frame callback to update transition progress material property

+ 3
- 3
src/animation/screen-transition.hpp View File

@ -35,19 +35,19 @@ public:
void transition(float duration, bool reverse, animation<float>::interpolator_type interpolator);
::billboard* get_billboard();
scene::billboard* get_billboard();
::material* get_material();
::animation<float>* get_animation();
private:
::billboard billboard;
scene::billboard billboard;
::material material;
material_property<float>* progress;
::animation<float> animation;
::animation<float>::channel* channel;
};
inline billboard* screen_transition::get_billboard()
inline scene::billboard* screen_transition::get_billboard()
{
return &billboard;
}

+ 17
- 22
src/game/bootloader.cpp View File

@ -53,12 +53,7 @@
#include "resources/config-file.hpp"
#include "resources/resource-manager.hpp"
#include "resources/resource-manager.hpp"
#include "scene/billboard.hpp"
#include "scene/model-instance.hpp"
#include "scene/point-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
#include "scene/spotlight.hpp"
#include "scene/scene.hpp"
#include "game/states/game-states.hpp"
#include "game/systems/behavior-system.hpp"
#include "game/systems/camera-system.hpp"
@ -625,14 +620,14 @@ void setup_scenes(game_context* ctx)
ctx->no_cull = {{-inf, -inf, -inf}, {inf, inf, inf}};
// Setup overworld camera
ctx->overworld_camera = new camera();
ctx->overworld_camera = new scene::camera();
ctx->overworld_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->overworld_camera->set_compositor(ctx->overworld_compositor);
ctx->overworld_camera->set_composite_index(0);
ctx->overworld_camera->set_active(true);
// Setup underworld camera
ctx->underworld_camera = new camera();
ctx->underworld_camera = new scene::camera();
ctx->underworld_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
ctx->underworld_camera->look_at({0, 50, 0}, {0, 0, 0}, {0, 0, -1});
ctx->underworld_camera->set_compositor(ctx->underworld_compositor);
@ -640,40 +635,40 @@ void setup_scenes(game_context* ctx)
ctx->underworld_camera->set_active(false);
// Setup UI camera
ctx->ui_camera = new camera();
ctx->ui_camera = new scene::camera();
ctx->ui_camera->set_compositor(ctx->ui_compositor);
// Setup lights
ctx->sun_indirect = new ambient_light();
ctx->sun_indirect = new scene::ambient_light();
ctx->sun_indirect->set_intensity(0.0f);
ctx->sun_indirect->update_tweens();
ctx->sun_direct = new directional_light();
ctx->sun_direct = new scene::directional_light();
ctx->sun_direct->set_intensity(0.0f);
ctx->sun_direct->update_tweens();
ctx->moon_light = new directional_light();
ctx->moon_light = new scene::directional_light();
ctx->moon_light->set_intensity(0.0f);
ctx->moon_light->update_tweens();
ctx->subterrain_light = new point_light();
ctx->subterrain_light = new scene::point_light();
ctx->subterrain_light->set_color({1, 1, 1});
ctx->subterrain_light->set_intensity(1.0f);
ctx->subterrain_light->set_attenuation({1.0f, 0.09f, 0.032f});
ctx->subterrain_light->update_tweens();
ctx->underworld_ambient_light = new ambient_light();
ctx->underworld_ambient_light = new scene::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 = new scene::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 = new scene::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});
@ -688,7 +683,7 @@ void setup_scenes(game_context* ctx)
ctx->splash_billboard_material->add_property<const texture_2d*>("background")->set_value(splash_texture);
ctx->splash_billboard_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
ctx->splash_billboard_material->update_tweens();
ctx->splash_billboard = new billboard();
ctx->splash_billboard = new scene::billboard();
ctx->splash_billboard->set_material(ctx->splash_billboard_material);
ctx->splash_billboard->set_scale({(float)std::get<0>(splash_dimensions) * 0.5f, (float)std::get<1>(splash_dimensions) * 0.5f, 1.0f});
ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f});
@ -710,7 +705,7 @@ void setup_scenes(game_context* ctx)
*/
// Setup overworld scene
ctx->overworld_scene = new scene();
ctx->overworld_scene = new scene::collection();
ctx->overworld_scene->add_object(ctx->overworld_camera);
ctx->overworld_scene->add_object(ctx->sun_indirect);
ctx->overworld_scene->add_object(ctx->sun_direct);
@ -718,17 +713,17 @@ void setup_scenes(game_context* ctx)
//ctx->overworld_scene->add_object(ctx->spotlight);
// Setup underworld scene
ctx->underworld_scene = new scene();
ctx->underworld_scene = new scene::collection();
ctx->underworld_scene->add_object(ctx->underworld_camera);
ctx->underworld_scene->add_object(ctx->underworld_ambient_light);
//ctx->underworld_scene->add_object(ctx->lantern);
//ctx->underworld_scene->add_object(ctx->subterrain_light);
//ctx->underworld_scene->add_object(ctx->portal_billboard);
//model_instance* larva = new model_instance(ctx->resource_manager->load<model>("larva.mdl"));
//model_instance* larva = new scene::model_instance(ctx->resource_manager->load<model>("larva.mdl"));
//ctx->underworld_scene->add_object(larva);
// Setup UI scene
ctx->ui_scene = new scene();
ctx->ui_scene = new scene::collection();
ctx->ui_scene->add_object(ctx->ui_camera);
ctx->overworld_scene->add_object(ctx->lens_spotlight);
@ -1232,7 +1227,7 @@ void setup_controls(game_context* ctx)
);
// Make lens tool's model instance unculled, so its shadow is always visible.
model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
if (lens_model_instance)
{
lens_model_instance->set_culling_mask(&ctx->no_cull);

+ 17
- 23
src/game/game-context.hpp View File

@ -29,13 +29,10 @@
#include <string>
// Forward declarations
class ambient_light;
class animator;
class application;
class behavior_system;
class billboard;
class bloom_pass;
class camera;
class camera_system;
class clear_pass;
class collision_system;
@ -45,7 +42,6 @@ class constraint_system;
class control;
class control_set;
class control_system;
class directional_light;
class final_pass;
class framebuffer;
class locomotion_system;
@ -56,17 +52,14 @@ class nest_system;
class orbit_cam;
class pheromone_matrix;
class snapping_system;
class point_light;
class rasterizer;
class render_system;
class resource_manager;
class samara_system;
class scene;
class screen_transition;
class shadow_map_pass;
class simple_render_pass;
class sky_pass;
class spotlight;
class subterrain_system;
class terrain_system;
class texture_2d;
@ -78,7 +71,6 @@ class vegetation_system;
class vertex_array;
class vertex_buffer;
class renderer;
class model_instance;
class input_event_router;
class input_mapper;
class outline_pass;
@ -98,6 +90,8 @@ namespace debug
class logger;
}
#include "scene/scene.hpp"
/**
*
*/
@ -177,22 +171,22 @@ struct game_context
compositor* ui_compositor;
// Scene
scene* active_scene;
scene* overworld_scene;
scene* underworld_scene;
scene* ui_scene;
camera* overworld_camera;
camera* underworld_camera;
camera* ui_camera;
ambient_light* sun_indirect;
directional_light* sun_direct;
directional_light* moon_light;
point_light* subterrain_light;
ambient_light* underworld_ambient_light;
billboard* splash_billboard;
scene::collection* active_scene;
scene::collection* overworld_scene;
scene::collection* underworld_scene;
scene::collection* ui_scene;
scene::camera* overworld_camera;
scene::camera* underworld_camera;
scene::camera* ui_camera;
scene::ambient_light* sun_indirect;
scene::directional_light* sun_direct;
scene::directional_light* moon_light;
scene::point_light* subterrain_light;
scene::ambient_light* underworld_ambient_light;
scene::billboard* splash_billboard;
scene::spotlight* lens_spotlight;
scene::spotlight* flashlight_spotlight;
aabb<float> no_cull;
spotlight* lens_spotlight;
spotlight* flashlight_spotlight;
// Animation
timeline* timeline;

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

@ -29,7 +29,6 @@
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp"
#include <functional>
void map_state_enter(game_context* ctx)

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

@ -46,7 +46,7 @@
#include "renderer/passes/sky-pass.hpp"
#include "resources/resource-manager.hpp"
#include "scene/model-instance.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
@ -200,7 +200,7 @@ void play_state_enter(game_context* ctx)
ec::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
// Make lens tool's model instance unculled, so its shadow is always visible.
model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
if (lens_model_instance)
{
lens_model_instance->set_culling_mask(&ctx->no_cull);

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

@ -29,7 +29,7 @@
#include "game/states/game-states.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include <functional>
void splash_state_enter(game_context* ctx)

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

@ -20,11 +20,9 @@
#include "camera-system.hpp"
#include "game/components/camera-follow-component.hpp"
#include "game/components/transform-component.hpp"
#include "scene/camera.hpp"
#include "math/math.hpp"
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace ecs;
@ -96,7 +94,7 @@ void camera_system::zoom(float factor)
orbit_cam.zoom(factor);
}
void camera_system::set_camera(::camera* camera)
void camera_system::set_camera(scene::camera* camera)
{
this->camera = camera;
if (camera)

+ 3
- 3
src/game/systems/camera-system.hpp View File

@ -28,8 +28,8 @@
#include "math/quaternion-type.hpp"
#include "math/transform-type.hpp"
#include "animation/orbit-cam.hpp"
#include "scene/camera.hpp"
class camera;
class orbit_cam;
class camera_system:
@ -48,7 +48,7 @@ public:
void tilt(float angle);
void zoom(float factor);
void set_camera(::camera* camera);
void set_camera(scene::camera* camera);
void set_viewport(const float4& viewport);
const orbit_cam* get_orbit_cam() const;
@ -58,7 +58,7 @@ private:
virtual void handle_event(const mouse_moved_event& event);
virtual void handle_event(const window_resized_event& event);
camera* camera;
scene::camera* camera;
float4 viewport;
float2 mouse_position;

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

@ -19,7 +19,6 @@
#include "control-system.hpp"
#include "input/control.hpp"
#include "scene/camera.hpp"
#include "geometry/intersection.hpp"
#include "animation/ease.hpp"
#include "nest.hpp"
@ -182,7 +181,7 @@ void control_system::set_nest(::nest* nest)
this->nest = nest;
}
void control_system::set_tool(model_instance* tool)
void control_system::set_tool(scene::model_instance* tool)
{
this->tool = tool;
}
@ -202,7 +201,7 @@ void control_system::set_viewport(const float4& viewport)
this->viewport = viewport;
}
void control_system::set_underworld_camera(::camera* camera)
void control_system::set_underworld_camera(scene::camera* camera)
{
this->underworld_camera = camera;
}

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

@ -28,9 +28,9 @@
#include "input/control-set.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/camera.hpp"
class nest;
class camera;
class camera_system;
class control_system:
@ -48,12 +48,12 @@ public:
void set_camera_system(camera_system* camera_system);
void set_nest(::nest* nest);
void set_tool(model_instance* tool);
void set_tool(scene::model_instance* tool);
void set_flashlight(entt::entity eid);
void set_camera_subject(entt::entity eid);
void set_viewport(const float4& viewport);
void set_underworld_camera(::camera* camera);
void set_underworld_camera(scene::camera* camera);
control_set* get_control_set();
control* get_move_forward_control();
@ -133,13 +133,13 @@ private:
float zoom;
camera_system* camera_system;
::nest* nest;
model_instance* tool;
scene::model_instance* tool;
float2 mouse_position;
float4 viewport;
entt::entity flashlight_eid;
entt::entity camera_subject_eid;
camera* underworld_camera;
scene::camera* underworld_camera;
float mouse_angle;
float old_mouse_angle;

+ 5
- 7
src/game/systems/painting-system.cpp View File

@ -23,8 +23,6 @@
#include "game/components/tool-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "scene/model-instance.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
@ -44,7 +42,7 @@ painting_system::painting_system(entt::registry& registry, ::event_dispatcher* e
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene(nullptr),
scene_collection(nullptr),
painting(false)
{
event_dispatcher->subscribe<tool_pressed_event>(this);
@ -75,7 +73,7 @@ painting_system::painting_system(entt::registry& registry, ::event_dispatcher* e
stroke_model->get_vertex_array()->bind_attribute(VERTEX_TANGENT_LOCATION, *stroke_vbo, 4, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * 9);
// Create stroke model instance
stroke_model_instance = new model_instance();
stroke_model_instance = new scene::model_instance();
stroke_model_instance->set_model(stroke_model);
stroke_model_instance->update_tweens();
@ -267,10 +265,10 @@ void painting_system::update(double t, double dt)
}
}
void painting_system::set_scene(::scene* scene)
void painting_system::set_scene(scene::collection* collection)
{
this->scene = scene;
scene->add_object(stroke_model_instance);
this->scene_collection = collection;
scene_collection->add_object(stroke_model_instance);
}
void painting_system::handle_event(const tool_pressed_event& event)

+ 5
- 5
src/game/systems/painting-system.hpp View File

@ -24,15 +24,15 @@
#include "event/event-handler.hpp"
#include "game/events/tool-events.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include <vector>
#include <optional>
class material;
class event_dispatcher;
class resource_manager;
class scene;
class model;
class model_instance;
class model_group;
class vertex_buffer;
@ -45,7 +45,7 @@ public:
virtual ~painting_system();
virtual void update(double t, double dt);
void set_scene(scene* scene);
void set_scene(scene::collection* collection);
private:
virtual void handle_event(const tool_pressed_event& event);
@ -55,7 +55,7 @@ private:
event_dispatcher* event_dispatcher;
resource_manager* resource_manager;
scene* scene;
scene::collection* scene_collection;
bool painting;
entt::entity brush_entity;
@ -83,7 +83,7 @@ private:
vertex_buffer* stroke_vbo;
bool midstroke;
model_instance* stroke_model_instance;
scene::model_instance* stroke_model_instance;
};
#endif // ANTKEEPER_PAINTING_SYSTEM_HPP

+ 6
- 6
src/game/systems/render-system.cpp View File

@ -38,7 +38,7 @@ void render_system::update(double t, double dt)
(
[this](auto entity, auto& transform, auto& model)
{
model_instance* instance = model_instances[entity];
scene::model_instance* instance = model_instances[entity];
instance->set_transform(transform.world);
@ -56,14 +56,14 @@ void render_system::render(double alpha)
{
if (renderer)
{
for (const scene* scene: layers)
for (const scene::collection* collection: layers)
{
renderer->render(alpha, *scene);
renderer->render(alpha, *collection);
}
}
}
void render_system::add_layer(::scene* layer)
void render_system::add_layer(scene::collection* layer)
{
layers.push_back(layer);
}
@ -78,7 +78,7 @@ void render_system::set_renderer(::renderer* renderer)
this->renderer = renderer;
}
model_instance* render_system::get_model_instance(entt::entity entity)
scene::model_instance* render_system::get_model_instance(entt::entity entity)
{
if (auto it = model_instances.find(entity); it != model_instances.end())
return it->second;
@ -112,7 +112,7 @@ void render_system::update_model_and_materials(entt::entity entity, model_compon
void render_system::on_model_construct(entt::registry& registry, entt::entity entity, model_component& model)
{
::model_instance* model_instance = new ::model_instance();
scene::model_instance* model_instance = new scene::model_instance();
model_instances[entity] = model_instance;
update_model_and_materials(entity, model);
}

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

@ -21,7 +21,7 @@
#define ANTKEEPER_RENDER_SYSTEM_HPP
#include "entity-system.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "game/components/model-component.hpp"
#include "game/components/render-component.hpp"
@ -39,12 +39,12 @@ public:
void render(double alpha);
void add_layer(::scene* layer);
void add_layer(scene::collection* layer);
void remove_layers();
void set_renderer(::renderer* renderer);
model_instance* get_model_instance(entt::entity entity);
scene::model_instance* get_model_instance(entt::entity entity);
private:
void update_model_and_materials(entt::entity entity, ecs::model_component& model);
@ -58,8 +58,8 @@ private:
void on_component_destroy(entt::registry& registry, entt::entity entity);
renderer* renderer;
std::vector<scene*> layers;
std::unordered_map<entt::entity, model_instance*> model_instances;
std::vector<scene::collection*> layers;
std::unordered_map<entt::entity, scene::model_instance*> model_instances;
};
#endif // ANTKEEPER_RENDER_SYSTEM_HPP

+ 4
- 6
src/game/systems/subterrain-system.cpp View File

@ -30,8 +30,6 @@
#include "resources/resource-manager.hpp"
#include "geometry/marching-cubes.hpp"
#include "geometry/intersection.hpp"
#include "scene/scene.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include <array>
#include <limits>
@ -267,8 +265,8 @@ void subterrain_system::update(double t, double dt)
//auto subterrain_entity = registry.create();
//registry.assign<model_component>(subterrain_entity, subterrain_model);
subterrain_model_instance = new model_instance(subterrain_model);
scene->add_object(subterrain_model_instance);
subterrain_model_instance = new scene::model_instance(subterrain_model);
collection->add_object(subterrain_model_instance);
}
bool digging = false;
@ -295,9 +293,9 @@ void subterrain_system::update(double t, double dt)
}
}
void subterrain_system::set_scene(::scene* scene)
void subterrain_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->collection = collection;
}
void subterrain_system::regenerate_subterrain_mesh()

+ 5
- 5
src/game/systems/subterrain-system.hpp View File

@ -23,6 +23,8 @@
#include "entity-system.hpp"
#include "geometry/mesh.hpp"
#include "geometry/aabb.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp"
#include <unordered_map>
@ -31,8 +33,6 @@ class model;
class model_group;
class material;
struct cube_tree;
class scene;
class model_instance;
template <std::int64_t Mantissa, std::int64_t Exponent>
struct epsilon
@ -89,7 +89,7 @@ public:
~subterrain_system();
virtual void update(double t, double dt);
void set_scene(::scene* scene);
void set_scene(scene::collection* collection);
private:
void regenerate_subterrain_mesh();
@ -121,8 +121,8 @@ private:
vector_hasher<epsilon_1en5, float, 3>,
vector_equals<epsilon_1en5, float, 3>> subterrain_vertex_map;
::scene* scene;
model_instance* subterrain_model_instance;
scene::collection* collection;
scene::model_instance* subterrain_model_instance;
};
#endif // ANTKEEPER_SUBTERRAIN_SYSTEM_HPP

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

@ -23,7 +23,6 @@
#include "game/components/transform-component.hpp"
#include "event/event-dispatcher.hpp"
#include "game/events/tool-events.hpp"
#include "scene/camera.hpp"
#include "animation/orbit-cam.hpp"
#include "animation/ease.hpp"
#include "geometry/mesh.hpp"
@ -223,7 +222,7 @@ void tool_system::update(double t, double dt)
was_pick_enabled = pick_enabled;
}
void tool_system::set_camera(const ::camera* camera)
void tool_system::set_camera(const scene::camera* camera)
{
this->camera = camera;
}

+ 3
- 3
src/game/systems/tool-system.hpp View File

@ -27,8 +27,8 @@
#include "utility/fundamental-types.hpp"
#include "animation/spring.hpp"
#include "animation/animation.hpp"
#include "scene/camera.hpp"
class camera;
class orbit_cam;
class event_dispatcher;
@ -42,7 +42,7 @@ public:
virtual ~tool_system();
virtual void update(double t, double dt);
void set_camera(const camera* camera);
void set_camera(const scene::camera* camera);
void set_orbit_cam(const orbit_cam* camera);
void set_viewport(const float4& viewport);
void set_pick(bool enabled);
@ -59,7 +59,7 @@ private:
virtual void handle_event(const window_resized_event& event);
event_dispatcher* event_dispatcher;
const camera* camera;
const scene::camera* camera;
const orbit_cam* orbit_cam;
float4 viewport;
float2 mouse_position;

+ 6
- 6
src/game/systems/tracking-system.cpp View File

@ -22,7 +22,7 @@
#include "game/components/marker-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
@ -36,7 +36,7 @@ tracking_system::tracking_system(entt::registry& registry, ::event_dispatcher* e
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene(nullptr)
scene_collection(nullptr)
{
registry.on_construct<trackable_component>().connect<&tracking_system::on_component_construct>(this);
registry.on_destroy<trackable_component>().connect<&tracking_system::on_component_destroy>(this);
@ -92,9 +92,9 @@ void tracking_system::update(double t, double dt)
}
}
void tracking_system::set_scene(::scene* scene)
void tracking_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->scene_collection = collection;
}
void tracking_system::on_component_construct(entt::registry& registry, entt::entity entity, trackable_component& component)
@ -132,7 +132,7 @@ void tracking_system::handle_event(const tool_pressed_event& event)
const float tracker_scale = 1.0f;
// Create tracker model instance
model_instance* instance = new model_instance();
scene::model_instance* instance = new scene::model_instance();
instance->set_model(tracker_model);
instance->set_translation(transform.translation);
instance->set_scale(float3{tracker_scale, tracker_scale, tracker_scale});
@ -146,7 +146,7 @@ void tracking_system::handle_event(const tool_pressed_event& event)
instance->update_tweens();
scene->add_object(instance);
scene_collection->add_object(instance);
}
}
}

+ 9
- 5
src/game/systems/tracking-system.hpp View File

@ -29,9 +29,13 @@
class material;
class event_dispatcher;
class resource_manager;
class scene;
class model;
class model_instance;
namespace scene
{
class collection;
class model_instance;
}
class tracking_system: public entity_system,
public event_handler<tool_pressed_event>,
@ -42,7 +46,7 @@ public:
virtual ~tracking_system();
virtual void update(double t, double dt);
void set_scene(scene* scene);
void set_scene(scene::collection* collection);
void set_viewport(const float4& viewport);
private:
@ -53,11 +57,11 @@ private:
event_dispatcher* event_dispatcher;
resource_manager* resource_manager;
scene* scene;
scene::collection* scene_collection;
model* tracker_model;
model* paint_ball_model;
material** paint_ball_materials;
std::unordered_map<entt::entity, model_instance*> trackers;
std::unordered_map<entt::entity, scene::model_instance*> trackers;
};
#endif // ANTKEEPER_TRACKING_SYSTEM_HPP

+ 10
- 10
src/game/systems/ui-system.cpp View File

@ -25,7 +25,7 @@ ui_system::ui_system(::resource_manager* resource_manager):
resource_manager(resource_manager),
tool_menu_control(nullptr),
camera(nullptr),
scene(nullptr)
scene_collection(nullptr)
{
// Setup lighting
indirect_light.set_intensity(0.25f);
@ -90,7 +90,7 @@ void ui_system::set_tool_menu_control(control* control)
tool_menu_control->set_deactivated_callback(std::bind(&ui_system::close_tool_menu, this));
}
void ui_system::set_camera(::camera* camera)
void ui_system::set_camera(scene::camera* camera)
{
this->camera = camera;
@ -101,9 +101,9 @@ void ui_system::set_camera(::camera* camera)
}
}
void ui_system::set_scene(::scene* scene)
void ui_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->scene_collection = collection;
}
void ui_system::handle_event(const mouse_moved_event& event)
@ -167,20 +167,20 @@ void ui_system::update_projection()
void ui_system::open_tool_menu()
{
if (scene)
if (scene_collection)
{
scene->add_object(&modal_bg);
scene->add_object(&tool_selector_bg);
scene_collection->add_object(&modal_bg);
scene_collection->add_object(&tool_selector_bg);
}
tool_selection_vector = {0, 0};
}
void ui_system::close_tool_menu()
{
if (scene)
if (scene_collection)
{
scene->remove_object(&modal_bg);
scene->remove_object(&tool_selector_bg);
scene_collection->remove_object(&modal_bg);
scene_collection->remove_object(&tool_selector_bg);
}
}

+ 11
- 12
src/game/systems/ui-system.hpp View File

@ -23,7 +23,7 @@
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "event/window-events.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
@ -33,7 +33,6 @@
#include "math/math.hpp"
class control;
class scene;
class resource_manager;
class ui_system:
@ -48,8 +47,8 @@ public:
void set_viewport(const float4& viewport);
void set_tool_menu_control(control* control);
void set_camera(::camera* camera);
void set_scene(::scene* scene);
void set_camera(scene::camera* camera);
void set_scene(scene::collection* collection);
private:
virtual void handle_event(const mouse_moved_event& event);
@ -64,17 +63,17 @@ private:
void close_elevator_menu();
resource_manager* resource_manager;
scene* scene;
camera* camera;
ambient_light indirect_light;
directional_light direct_light;
billboard tool_selector_bg;
scene::collection* scene_collection;
scene::camera* camera;
scene::ambient_light indirect_light;
scene::directional_light direct_light;
scene::billboard tool_selector_bg;
material modal_bg_material;
billboard modal_bg;
scene::billboard modal_bg;
billboard underground_bg;
scene::billboard underground_bg;
model_instance energy_symbol;
scene::model_instance energy_symbol;
float2 mouse_position;
float4 viewport;

+ 8
- 8
src/game/systems/vegetation-system.cpp View File

@ -22,7 +22,7 @@
#include "game/components/transform-component.hpp"
#include "scene/model-instance.hpp"
#include "scene/lod-group.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "renderer/material.hpp"
#include "geometry/aabb.hpp"
#include "utility/fundamental-types.hpp"
@ -73,9 +73,9 @@ void vegetation_system::set_vegetation_model(::model* model)
vegetation_model = model;
}
void vegetation_system::set_scene(::scene* scene)
void vegetation_system::set_scene(scene::collection* collection)
{
this->scene = scene;
this->scene_collection = collection;
}
void vegetation_system::on_terrain_construct(entt::registry& registry, entt::entity entity, terrain_component& component)
@ -132,7 +132,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
static_cast<material_property<int>*>(lod2_material->get_property("instance_multiplier"))->set_value(4);
// Create LOD 0
model_instance* patch_lod0 = new model_instance();
scene::model_instance* patch_lod0 = new scene::model_instance();
patch_lod0->set_model(vegetation_model);
patch_lod0->set_translation(translation);
patch_lod0->set_instanced(true, instance_count_lod0);
@ -140,7 +140,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
patch_lod0->update_tweens();
// Create LOD 1
model_instance* patch_lod1 = new model_instance();
scene::model_instance* patch_lod1 = new scene::model_instance();
patch_lod1->set_model(vegetation_model);
patch_lod1->set_material(0, lod1_material);
patch_lod1->set_translation(translation);
@ -149,7 +149,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
patch_lod1->update_tweens();
// Create LOD 2
model_instance* patch_lod2 = new model_instance();
scene::model_instance* patch_lod2 = new scene::model_instance();
patch_lod2->set_model(vegetation_model);
patch_lod2->set_material(0, lod2_material);
patch_lod2->set_translation(translation);
@ -158,7 +158,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
patch_lod2->update_tweens();
// Create LOD group
::lod_group* lod_group = new ::lod_group(lod_count);
scene::lod_group* lod_group = new scene::lod_group(lod_count);
lod_group->add_object(0, patch_lod0);
lod_group->add_object(1, patch_lod1);
lod_group->add_object(2, patch_lod2);
@ -166,7 +166,7 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent
lod_group->update_tweens();
// Add LOD group to scene
scene->add_object(lod_group);
scene_collection->add_object(lod_group);
}
}
}

+ 7
- 3
src/game/systems/vegetation-system.hpp View File

@ -24,7 +24,11 @@
#include "game/components/terrain-component.hpp"
class model;
class scene;
namespace scene
{
class collection;
}
/**
* Places vegetation patches on terrain.
@ -54,7 +58,7 @@ public:
void set_vegetation_model(::model* model);
void set_scene(::scene* scene);
void set_scene(scene::collection* collection);
private:
void on_terrain_construct(entt::registry& registry, entt::entity entity, ecs::terrain_component& component);
@ -66,7 +70,7 @@ private:
int vegetation_patch_rows;
float vegetation_density;
model* vegetation_model;
::scene* scene;
scene::collection* scene_collection;
};
#endif // ANTKEEPER_VEGETATION_SYSTEM_HPP

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

@ -38,12 +38,11 @@
#include "renderer/model.hpp"
#include "renderer/render-context.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/point-light.hpp"
#include "scene/spotlight.hpp"
#include "scene/scene.hpp"
#include "configuration.hpp"
#include "math/math.hpp"
#include <cmath>
@ -148,18 +147,18 @@ void material_pass::render(render_context* context) const
spotlight_count = 0;
// Collect lights
const std::list<scene_object_base*>* lights = context->scene->get_objects(light::object_type_id);
for (const scene_object_base* object: *lights)
const std::list<scene::object_base*>* lights = context->collection->get_objects(scene::light::object_type_id);
for (const scene::object_base* object: *lights)
{
// Skip inactive lights
if (!object->is_active())
continue;
const ::light* light = static_cast<const ::light*>(object);
const scene::light* light = static_cast<const scene::light*>(object);
switch (light->get_light_type())
{
// Add ambient light
case light_type::ambient:
case scene::light_type::ambient:
{
if (ambient_light_count < max_ambient_light_count)
{
@ -170,7 +169,7 @@ void material_pass::render(render_context* context) const
}
// Add point light
case light_type::point:
case scene::light_type::point:
{
if (point_light_count < max_point_light_count)
{
@ -181,21 +180,21 @@ void material_pass::render(render_context* context) const
float3 view_space_position = math::resize<3>(view * float4{position.x, position.y, position.z, 1.0f});
point_light_positions[point_light_count] = view_space_position;
point_light_attenuations[point_light_count] = static_cast<const point_light*>(light)->get_attenuation_tween().interpolate(context->alpha);
point_light_attenuations[point_light_count] = static_cast<const scene::point_light*>(light)->get_attenuation_tween().interpolate(context->alpha);
++point_light_count;
}
break;
}
// Add directional light
case light_type::directional:
case scene::light_type::directional:
{
if (directional_light_count < max_directional_light_count)
{
directional_light_colors[directional_light_count] = light->get_scaled_color_tween().interpolate(context->alpha);
// Transform direction into view-space
float3 direction = static_cast<const directional_light*>(light)->get_direction_tween().interpolate(context->alpha);
float3 direction = static_cast<const scene::directional_light*>(light)->get_direction_tween().interpolate(context->alpha);
float3 view_space_direction = math::normalize(math::resize<3>(view * math::resize<4>(-direction)));
directional_light_directions[directional_light_count] = view_space_direction;
@ -205,7 +204,7 @@ void material_pass::render(render_context* context) const
}
// Add spotlight
case light_type::spot:
case scene::light_type::spot:
{
if (spotlight_count < max_spotlight_count)
{
@ -216,7 +215,7 @@ void material_pass::render(render_context* context) const
float3 view_space_position = math::resize<3>(view * float4{position.x, position.y, position.z, 1.0f});
spotlight_positions[spotlight_count] = view_space_position;
const ::spotlight* spotlight = static_cast<const ::spotlight*>(light);
const scene::spotlight* spotlight = static_cast<const scene::spotlight*>(light);
// Transform direction into view-space
float3 direction = spotlight->get_direction_tween().interpolate(context->alpha);

+ 2
- 4
src/renderer/passes/shadow-map-pass.cpp View File

@ -28,9 +28,7 @@
#include "renderer/material.hpp"
#include "renderer/material-flags.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/light.hpp"
#include "scene/directional-light.hpp"
#include "geometry/view-frustum.hpp"
#include "geometry/aabb.hpp"
#include "configuration.hpp"
@ -111,7 +109,7 @@ void shadow_map_pass::render(render_context* context) const
//glDepthRange(-1.0f, 1.0f);
// Get camera
const ::camera& camera = *context->camera;
const scene::camera& camera = *context->camera;
// Calculate distances to the depth clipping planes of each frustum split
float clip_near = camera.get_clip_near_tween().interpolate(context->alpha);
@ -256,7 +254,7 @@ void shadow_map_pass::set_split_scheme_weight(float weight)
split_scheme_weight = weight;
}
void shadow_map_pass::set_light(const directional_light* light)
void shadow_map_pass::set_light(const scene::directional_light* light)
{
this->light = light;
}

+ 3
- 4
src/renderer/passes/shadow-map-pass.hpp View File

@ -22,12 +22,11 @@
#include "renderer/render-pass.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/directional-light.hpp"
class shader_program;
class shader_input;
class camera;
class resource_manager;
class directional_light;
/**
*
@ -46,7 +45,7 @@ public:
*/
void set_split_scheme_weight(float weight);
void set_light(const directional_light* light);
void set_light(const scene::directional_light* light);
const float4x4* get_shadow_matrices() const;
const float* get_split_distances() const;
@ -73,7 +72,7 @@ private:
mutable float4x4 shadow_matrices[4];
float4x4 bias_tile_matrices[4];
float split_scheme_weight;
const directional_light* light;
const scene::directional_light* light;
};
inline const float4x4* shadow_map_pass::get_shadow_matrices() const

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

@ -35,8 +35,6 @@
#include "renderer/model.hpp"
#include "renderer/material.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/scene.hpp"
#include "utility/fundamental-types.hpp"
#include <cmath>
#include <glad/glad.h>
@ -76,7 +74,7 @@ void sky_pass::render(render_context* context) const
float time = (time_tween) ? time_tween->interpolate(context->alpha) : 0.0f;
float2 resolution = {static_cast<float>(std::get<0>(viewport)), static_cast<float>(std::get<1>(viewport))};
const ::camera& camera = *context->camera;
const scene::camera& camera = *context->camera;
float clip_near = camera.get_clip_near_tween().interpolate(context->alpha);
float clip_far = camera.get_clip_far_tween().interpolate(context->alpha);
float3 model_scale = float3{1.0f, 1.0f, 1.0f} * (clip_near + clip_far) * 0.5f;

+ 2
- 3
src/renderer/passes/ui-pass.cpp View File

@ -36,10 +36,9 @@
#include "renderer/material-flags.hpp"
#include "renderer/render-context.hpp"
#include "scene/camera.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/scene.hpp"
#include "scene/billboard.hpp"
#include "math/math.hpp"
#include <cmath>
@ -69,7 +68,7 @@ void ui_pass::render(render_context* context) const
float4x4 model_view_projection;
// Collect billboards
std::list<scene_object_base*> billboards = *context->scene->get_objects(billboard::object_type_id);
std::list<scene::object_base*> billboards = *context->collection->get_objects(scene::billboard::object_type_id);
// Sort billboards

+ 4
- 5
src/renderer/render-context.hpp View File

@ -24,21 +24,20 @@
#include "geometry/plane.hpp"
#include "geometry/bounding-volume.hpp"
#include "utility/fundamental-types.hpp"
#include "scene/camera.hpp"
#include "scene/collection.hpp"
#include <list>
class camera;
class scene;
struct render_context
{
const camera* camera;
const scene::camera* camera;
math::transform<float> camera_transform;
float3 camera_forward;
float3 camera_up;
const bounding_volume<float>* camera_culling_volume;
plane<float> clip_near;
const scene* scene;
const scene::collection* collection;
std::list<render_operation> operations;
float alpha;
};

+ 26
- 26
src/renderer/renderer.cpp View File

@ -20,7 +20,7 @@
#include "renderer/renderer.hpp"
#include "renderer/render-context.hpp"
#include "renderer/compositor.hpp"
#include "scene/scene.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/model-instance.hpp"
#include "scene/billboard.hpp"
@ -44,30 +44,30 @@ renderer::renderer()
billboard_op.instance_count = 0;
}
void renderer::render(float alpha, const scene& scene) const
void renderer::render(float alpha, const scene::collection& collection) const
{
// Get list of all objects in the scene
const std::list<scene_object_base*>* objects = scene.get_objects();
// Get list of all objects in the collection
const std::list<scene::object_base*>* objects = collection.get_objects();
// Build list of cameras to be sorted
const std::list<scene_object_base*>* cameras = scene.get_objects(camera::object_type_id);
std::list<camera*> sorted_cameras;
for (scene_object_base* object: *cameras)
const std::list<scene::object_base*>* cameras = collection.get_objects(scene::camera::object_type_id);
std::list<scene::camera*> sorted_cameras;
for (scene::object_base* object: *cameras)
{
sorted_cameras.push_back(static_cast<camera*>(object));
sorted_cameras.push_back(static_cast<scene::camera*>(object));
}
// Sort cameras according to their respective compositing indices
sorted_cameras.sort
(
[](const camera* a, const camera* b) -> bool
[](const scene::camera* a, const scene::camera* b) -> bool
{
return a->get_composite_index() < b->get_composite_index();
}
);
// Process cameras in order
for (const camera* camera: sorted_cameras)
for (const scene::camera* camera: sorted_cameras)
{
// Skip inactive cameras
if (!camera->is_active())
@ -89,7 +89,7 @@ void renderer::render(float alpha, const scene& scene) const
context.camera_forward = context.camera_transform.rotation * global_forward;
context.camera_up = context.camera_transform.rotation * global_up;
context.clip_near = camera->get_view_frustum().get_near(); ///< TODO: tween this
context.scene = &scene;
context.collection = &collection;
context.alpha = alpha;
// Get camera culling volume
@ -98,7 +98,7 @@ void renderer::render(float alpha, const scene& scene) const
context.camera_culling_volume = &camera->get_bounds();
// Generate render operations for each visible scene object
for (const scene_object_base* object: *objects)
for (const scene::object_base* object: *objects)
{
// Skip inactive objects
if (!object->is_active())
@ -118,19 +118,19 @@ void renderer::set_billboard_vao(vertex_array* vao)
billboard_op.vertex_array = vao;
}
void renderer::process_object(render_context& context, const scene_object_base* object) const
void renderer::process_object(render_context& context, const scene::object_base* object) const
{
std::size_t type = object->get_object_type_id();
if (type == model_instance::object_type_id)
process_model_instance(context, static_cast<const model_instance*>(object));
else if (type == billboard::object_type_id)
process_billboard(context, static_cast<const billboard*>(object));
else if (type == lod_group::object_type_id)
process_lod_group(context, static_cast<const lod_group*>(object));
if (type == scene::model_instance::object_type_id)
process_model_instance(context, static_cast<const scene::model_instance*>(object));
else if (type == scene::billboard::object_type_id)
process_billboard(context, static_cast<const scene::billboard*>(object));
else if (type == scene::lod_group::object_type_id)
process_lod_group(context, static_cast<const scene::lod_group*>(object));
}
void renderer::process_model_instance(render_context& context, const ::model_instance* model_instance) const
void renderer::process_model_instance(render_context& context, const scene::model_instance* model_instance) const
{
const model* model = model_instance->get_model();
if (!model)
@ -173,7 +173,7 @@ void renderer::process_model_instance(render_context& context, const ::model_ins
}
}
void renderer::process_billboard(render_context& context, const ::billboard* billboard) const
void renderer::process_billboard(render_context& context, const scene::billboard* billboard) const
{
// Get object culling volume
const bounding_volume<float>* object_culling_volume = billboard->get_culling_mask();
@ -189,11 +189,11 @@ void renderer::process_billboard(render_context& context, const ::billboard* bil
billboard_op.depth = context.clip_near.signed_distance(math::resize<3>(billboard_transform.translation));
// Align billboard
if (billboard->get_billboard_type() == billboard_type::spherical)
if (billboard->get_billboard_type() == scene::billboard_type::spherical)
{
billboard_transform.rotation = math::normalize(math::look_rotation(context.camera_forward, context.camera_up) * billboard_transform.rotation);
}
else if (billboard->get_billboard_type() == billboard_type::cylindrical)
else if (billboard->get_billboard_type() == scene::billboard_type::cylindrical)
{
const float3& alignment_axis = billboard->get_alignment_axis();
float3 look = math::normalize(project_on_plane(billboard_transform.translation - context.camera_transform.translation, {0.0f, 0.0f, 0.0f}, alignment_axis));
@ -208,14 +208,14 @@ void renderer::process_billboard(render_context& context, const ::billboard* bil
context.operations.push_back(billboard_op);
}
void renderer::process_lod_group(render_context& context, const ::lod_group* lod_group) const
void renderer::process_lod_group(render_context& context, const scene::lod_group* lod_group) const
{
// Select level of detail
std::size_t level = lod_group->select_lod(*context.camera);
// Process all objects in the group with the selected level of detail
const std::list<scene_object_base*>& objects = lod_group->get_objects(level);
for (const scene_object_base* object: objects)
const std::list<scene::object_base*>& objects = lod_group->get_objects(level);
for (const scene::object_base* object: objects)
{
process_object(context, object);
}

+ 16
- 12
src/renderer/renderer.hpp View File

@ -23,12 +23,16 @@
#include "render-operation.hpp"
struct render_context;
class scene;
class scene_object_base;
class vertex_array;
class model_instance;
class billboard;
class lod_group;
namespace scene
{
class collection;
class object_base;
class model_instance;
class billboard;
class lod_group;
}
/*
# Pipeline
@ -50,12 +54,12 @@ public:
renderer();
/**
* Renders a scene.
* Renders a collection of scene objects.
*
* @param alpha Subframe interpolation factor.
* @parma scene Scene to render.
* @parma collection Collection of scene objects to render.
*/
void render(float alpha, const scene& scene) const;
void render(float alpha, const scene::collection& collection) const;
/**
* Sets the VAO to be used when generating render operations for billboards.
@ -63,10 +67,10 @@ public:
void set_billboard_vao(vertex_array* vao);
private:
void process_object(render_context& context, const scene_object_base* object) const;
void process_model_instance(render_context& context, const ::model_instance* model_instance) const;
void process_billboard(render_context& context, const ::billboard* billboard) const;
void process_lod_group(render_context& context, const ::lod_group* lod_group) const;
void process_object(render_context& context, const scene::object_base* object) const;
void process_model_instance(render_context& context, const scene::model_instance* model_instance) const;
void process_billboard(render_context& context, const scene::billboard* billboard) const;
void process_lod_group(render_context& context, const scene::lod_group* lod_group) const;
mutable render_operation billboard_op;
};

+ 7
- 3
src/scene/ambient-light.hpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_AMBIENT_LIGHT_HPP
#define ANTKEEPER_AMBIENT_LIGHT_HPP
#ifndef ANTKEEPER_SCENE_AMBIENT_LIGHT_HPP
#define ANTKEEPER_SCENE_AMBIENT_LIGHT_HPP
#include "scene/light.hpp"
namespace scene {
class ambient_light: public light
{
public:
@ -34,5 +36,7 @@ inline light_type ambient_light::get_light_type() const
return light_type::ambient;
}
#endif // ANTKEEPER_AMBIENT_LIGHT_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_AMBIENT_LIGHT_HPP

+ 5
- 1
src/scene/billboard.cpp View File

@ -21,6 +21,8 @@
#include "renderer/material.hpp"
#include "configuration.hpp"
namespace scene {
const aabb<float> billboard::untransformed_bounds = {{-1, -1, -1}, {1, 1, 1}};
billboard::billboard():
@ -66,9 +68,11 @@ void billboard::transformed()
void billboard::update_tweens()
{
scene_object_base::update_tweens();
object_base::update_tweens();
if (material)
{
material->update_tweens();
}
}
} // namespace scene

+ 9
- 5
src/scene/billboard.hpp View File

@ -17,15 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_BILLBOARD_HPP
#define ANTKEEPER_BILLBOARD_HPP
#ifndef ANTKEEPER_SCENE_BILLBOARD_HPP
#define ANTKEEPER_SCENE_BILLBOARD_HPP
#include "scene/scene-object.hpp"
#include "scene/object.hpp"
#include "geometry/aabb.hpp"
#include "utility/fundamental-types.hpp"
class material;
namespace scene {
/// Enumerates billboard types.
enum class billboard_type
{
@ -42,7 +44,7 @@ enum class billboard_type
/**
* A 2D unit quad with one material.
*/
class billboard: public scene_object<billboard>
class billboard: public object<billboard>
{
public:
billboard();
@ -97,5 +99,7 @@ inline const float3& billboard::get_alignment_axis() const
return alignment_axis;
}
#endif // ANTKEEPER_BILLBOARD_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_BILLBOARD_HPP

+ 4
- 1
src/scene/camera.cpp View File

@ -23,6 +23,8 @@
#include "math/constants.hpp"
#include "math/interpolation.hpp"
namespace scene {
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);
@ -153,7 +155,7 @@ void camera::set_composite_index(int index)
void camera::update_tweens()
{
scene_object_base::update_tweens();
object_base::update_tweens();
clip_left.update();
clip_right.update();
clip_bottom.update();
@ -179,3 +181,4 @@ void camera::transformed()
view_frustum.set_matrix(view_projection[1]);
}
} // namespace scene

+ 10
- 6
src/scene/camera.hpp View File

@ -17,19 +17,21 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CAMERA_HPP
#define ANTKEEPER_CAMERA_HPP
#ifndef ANTKEEPER_SCENE_CAMERA_HPP
#define ANTKEEPER_SCENE_CAMERA_HPP
#include "scene/scene-object.hpp"
#include "scene/object.hpp"
#include "geometry/view-frustum.hpp"
#include "utility/fundamental-types.hpp"
class compositor;
namespace scene {
/**
*
*/
class camera: public scene_object<camera>
class camera: public object<camera>
{
public:
camera();
@ -117,7 +119,7 @@ public:
const tween<float4x4>& get_projection_tween() const;
const tween<float4x4>& get_view_projection_tween() const;
/// @copydoc scene_object_base::update_tweens();
/// @copydoc object_base::update_tweens();
virtual void update_tweens();
private:
@ -280,5 +282,7 @@ inline const tween& camera::get_view_projection_tween() const
return view_projection;
}
#endif // ANTKEEPER_CAMERA_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_CAMERA_HPP

src/scene/scene.cpp → src/scene/collection.cpp View File

@ -17,34 +17,35 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "scene/scene.hpp"
#include "scene/scene-object.hpp"
#include "scene/light.hpp"
#include "scene/camera.hpp"
#include "scene/model-instance.hpp"
#include "scene/collection.hpp"
#include "scene/object.hpp"
void scene::add_object(scene_object_base* object)
namespace scene {
void collection::add_object(object_base* object)
{
objects.push_back(object);
object_map[object->get_object_type_id()].push_back(object);
}
void scene::remove_object(scene_object_base* object)
void collection::remove_object(object_base* object)
{
objects.remove(object);
object_map[object->get_object_type_id()].remove(object);
}
void scene::remove_objects()
void collection::remove_objects()
{
objects.clear();
object_map.clear();
}
void scene::update_tweens()
void collection::update_tweens()
{
for (scene_object_base* object: objects)
for (object_base* object: objects)
{
object->update_tweens();
}
}
} // namespace scene

+ 84
- 0
src/scene/collection.hpp View File

@ -0,0 +1,84 @@
/*
* 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_SCENE_COLLECTION_HPP
#define ANTKEEPER_SCENE_COLLECTION_HPP
#include <list>
#include <unordered_map>
namespace scene {
class object_base;
/**
* Collection of scene objects.
*/
class collection
{
public:
/**
* Adds an object to the collection.
*
* @param object Object to add.
*/
void add_object(object_base* object);
/**
* Removes an object from the collection.
*
* @param object Object to remove.
*/
void remove_object(object_base* object);
/// Removes all objects from the collection.
void remove_objects();
/// Updates the tweens of all objects in the collection.
void update_tweens();
/// Returns a list of all objects in the collection.
const std::list<object_base*>* get_objects() const;
/**
* Returns a list of all objects in the collection with the specified type ID.
*
* @param type_id Scene object type ID.
* @return List of scene objects with the specified type ID.
*/
const std::list<object_base*>* get_objects(std::size_t type_id) const;
private:
std::list<object_base*> objects;
mutable std::unordered_map<std::size_t, std::list<object_base*>> object_map;
};
inline const std::list<object_base*>* collection::get_objects() const
{
return &objects;
}
inline const std::list<object_base*>* collection::get_objects(std::size_t type_id) const
{
return &object_map[type_id];
}
} // namespace scene
#endif // ANTKEEPER_SCENE_COLLECTION_HPP

+ 3
- 0
src/scene/directional-light.cpp View File

@ -21,6 +21,8 @@
#include "configuration.hpp"
#include "math/math.hpp"
namespace scene {
static float3 interpolate_direction(const float3& x, const float3& y, float a)
{
math::quaternion<float> q0 = math::rotation(global_forward, x);
@ -43,3 +45,4 @@ void directional_light::transformed()
direction[1] = math::normalize(get_transform().rotation * global_forward);
}
} // namespace scene

+ 8
- 4
src/scene/directional-light.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_DIRECTIONAL_LIGHT_HPP
#define ANTKEEPER_DIRECTIONAL_LIGHT_HPP
#ifndef ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP
#define ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP
#include "scene/light.hpp"
#include "utility/fundamental-types.hpp"
namespace scene {
class directional_light: public light
{
public:
@ -35,7 +37,7 @@ public:
const tween<float3>& get_direction_tween() const;
/// @copydoc scene_object_base::update_tweens();
/// @copydoc object_base::update_tweens();
virtual void update_tweens();
private:
@ -59,5 +61,7 @@ inline const tween& directional_light::get_direction_tween() const
return direction;
}
#endif // ANTKEEPER_DIRECTIONAL_LIGHT_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP

+ 5
- 1
src/scene/light.cpp View File

@ -21,6 +21,8 @@
#include "animation/ease.hpp"
#include "math/interpolation.hpp"
namespace scene {
light::light():
bounds(get_translation(), 0.0f),
color(float3{1.0f, 1.0f, 1.0f}, math::lerp<float3, float>),
@ -42,7 +44,7 @@ void light::set_intensity(float intensity)
void light::update_tweens()
{
scene_object_base::update_tweens();
object_base::update_tweens();
color.update();
intensity.update();
scaled_color.update();
@ -52,3 +54,5 @@ void light::transformed()
{
bounds = sphere<float>(get_translation(), 0.0f);
}
} // namespace scene

+ 10
- 6
src/scene/light.hpp View File

@ -17,13 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_LIGHT_HPP
#define ANTKEEPER_LIGHT_HPP
#ifndef ANTKEEPER_SCENE_LIGHT_HPP
#define ANTKEEPER_SCENE_LIGHT_HPP
#include "scene/scene-object.hpp"
#include "scene/object.hpp"
#include "geometry/sphere.hpp"
#include "utility/fundamental-types.hpp"
namespace scene {
enum class light_type
{
ambient,
@ -32,7 +34,7 @@ enum class light_type
spot
};
class light: public scene_object<light>
class light: public object<light>
{
public:
light();
@ -52,7 +54,7 @@ public:
const tween<float>& get_intensity_tween() const;
const tween<float3>& get_scaled_color_tween() const;
/// @copydoc scene_object_base::update_tweens();
/// @copydoc object_base::update_tweens();
virtual void update_tweens();
private:
@ -99,5 +101,7 @@ inline const tween& light::get_scaled_color_tween() const
return scaled_color;
}
#endif // ANTKEEPER_LIGHT_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_LIGHT_HPP

+ 7
- 3
src/scene/lod-group.cpp View File

@ -20,6 +20,8 @@
#include "scene/lod-group.hpp"
#include "scene/camera.hpp"
namespace scene {
lod_group::lod_group(std::size_t level_count):
bounds(get_translation(), get_translation())
{
@ -35,7 +37,7 @@ void lod_group::resize(std::size_t level_count)
levels.resize(level_count);
}
std::size_t lod_group::select_lod(const ::camera& camera) const
std::size_t lod_group::select_lod(const camera& camera) const
{
float distance = camera.get_view_frustum().get_near().signed_distance(get_translation());
@ -49,12 +51,12 @@ std::size_t lod_group::select_lod(const ::camera& camera) const
return 3;
}
void lod_group::add_object(std::size_t level, scene_object_base* object)
void lod_group::add_object(std::size_t level, object_base* object)
{
levels[level].push_back(object);
}
void lod_group::remove_object(std::size_t level, scene_object_base* object)
void lod_group::remove_object(std::size_t level, object_base* object)
{
levels[level].remove(object);
}
@ -73,3 +75,5 @@ void lod_group::transformed()
{
update_bounds();
}
} // namespace scene

+ 15
- 11
src/scene/lod-group.hpp View File

@ -17,17 +17,19 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_LOD_GROUP_HPP
#define ANTKEEPER_LOD_GROUP_HPP
#ifndef ANTKEEPER_SCENE_LOD_GROUP_HPP
#define ANTKEEPER_SCENE_LOD_GROUP_HPP
#include "scene/scene-object.hpp"
#include "scene/object.hpp"
#include "geometry/aabb.hpp"
#include <list>
#include <vector>
namespace scene {
class camera;
class lod_group: public scene_object<lod_group>
class lod_group: public object<lod_group>
{
public:
/**
@ -53,7 +55,7 @@ public:
* @param camera Camera for which the LOD should be selected.
* @return Selected level of detail.
*/
std::size_t select_lod(const ::camera& camera) const;
std::size_t select_lod(const camera& camera) const;
/**
* Adds an object to the LOD group.
@ -61,7 +63,7 @@ public:
* @param level Level of detail of the object to add.
* @param object Object to add.
*/
void add_object(std::size_t level, scene_object_base* object);
void add_object(std::size_t level, object_base* object);
/**
* Removes an object from the LOD group.
@ -69,7 +71,7 @@ public:
* @param level Level of detail of the object to remove.
* @param object Object to remove.
*/
void remove_object(std::size_t level, scene_object_base* object);
void remove_object(std::size_t level, object_base* object);
/**
* Removes all objects with the specified level of detail.
@ -89,14 +91,14 @@ public:
* @param level Level of detail.
* @return List of all objects in the group with the specified detail level.
*/
const std::list<scene_object_base*>& get_objects(std::size_t level) const;
const std::list<object_base*>& get_objects(std::size_t level) const;
private:
void update_bounds();
virtual void transformed();
aabb<float> bounds;
std::vector<std::list<scene_object_base*>> levels;
std::vector<std::list<object_base*>> levels;
};
inline const bounding_volume<float>& lod_group::get_bounds() const
@ -109,10 +111,12 @@ inline std::size_t lod_group::get_level_count() const
return levels.size();
}
inline const std::list<scene_object_base*>& lod_group::get_objects(std::size_t level) const
inline const std::list<object_base*>& lod_group::get_objects(std::size_t level) const
{
return levels[level];
}
#endif // ANTKEEPER_LOD_GROUP_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_LOD_GROUP_HPP

+ 5
- 1
src/scene/model-instance.cpp View File

@ -21,6 +21,8 @@
#include "renderer/model.hpp"
#include "renderer/material.hpp"
namespace scene {
model_instance::model_instance(::model* model):
model(nullptr),
pose(nullptr),
@ -102,7 +104,7 @@ void model_instance::transformed()
void model_instance::update_tweens()
{
scene_object_base::update_tweens();
object_base::update_tweens();
// Update model material tweens
if (model)
@ -126,3 +128,5 @@ void model_instance::update_tweens()
}
}
}
} // namespace scene

+ 9
- 5
src/scene/model-instance.hpp View File

@ -17,10 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MODEL_INSTANCE_HPP
#define ANTKEEPER_MODEL_INSTANCE_HPP
#ifndef ANTKEEPER_SCENE_MODEL_INSTANCE_HPP
#define ANTKEEPER_SCENE_MODEL_INSTANCE_HPP
#include "scene/scene-object.hpp"
#include "scene/object.hpp"
#include "geometry/aabb.hpp"
#include <vector>
@ -28,7 +28,9 @@ class material;
class model;
class pose;
class model_instance: public scene_object<model_instance>
namespace scene {
class model_instance: public object<model_instance>
{
public:
explicit model_instance(model* model);
@ -129,5 +131,7 @@ inline std::size_t model_instance::get_instance_count() const
return instance_count;
}
#endif // ANTKEEPER_MODEL_INSTANCE_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_MODEL_INSTANCE_HPP

src/scene/scene-object.cpp → src/scene/object.cpp View File

@ -17,10 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "scene/scene-object.hpp"
#include "scene/object.hpp"
#include "math/math.hpp"
typename scene_object_base::transform_type scene_object_base::interpolate_transforms(const transform_type& x, const transform_type& y, float a)
namespace scene {
typename object_base::transform_type object_base::interpolate_transforms(const transform_type& x, const transform_type& y, float a)
{
return
{
@ -30,34 +32,36 @@ typename scene_object_base::transform_type scene_object_base::interpolate_transf
};
}
scene_object_base::scene_object_base():
object_base::object_base():
active(true),
transform(math::identity_transform<float>, interpolate_transforms),
culling_mask(nullptr)
{}
void scene_object_base::set_culling_mask(const bounding_volume_type* culling_mask)
void object_base::set_culling_mask(const bounding_volume_type* culling_mask)
{
this->culling_mask = culling_mask;
}
std::size_t scene_object_base::next_object_type_id()
std::size_t object_base::next_object_type_id()
{
static std::atomic<std::size_t> id{0};
return id++;
}
void scene_object_base::update_tweens()
void object_base::update_tweens()
{
transform.update();
}
void scene_object_base::look_at(const vector_type& position, const vector_type& target, const vector_type& up)
void object_base::look_at(const vector_type& position, const vector_type& target, const vector_type& up)
{
transform[1].translation = position;
transform[1].rotation = math::look_rotation(math::normalize(math::sub(target, position)), up);
transformed();
}
void scene_object_base::transformed()
void object_base::transformed()
{}
} // namespace scene

src/scene/scene-object.hpp → src/scene/object.hpp View File

@ -28,10 +28,12 @@
#include <atomic>
#include <cstdlib>
namespace scene {
/**
* Internal base class for scene objects.
*/
class scene_object_base
class object_base
{
public:
typedef math::vector<float, 3> vector_type;
@ -45,12 +47,12 @@ public:
/**
* Creates a scene object base.
*/
scene_object_base();
object_base();
/**
* Destroys a scene object base.
*/
virtual ~scene_object_base() = default;
virtual ~object_base() = default;
/**
* Updates all tweens in the scene object.
@ -148,71 +150,71 @@ private:
const bounding_volume_type* culling_mask;
};
inline void scene_object_base::set_active(bool active)
inline void object_base::set_active(bool active)
{
this->active = active;
}
inline void scene_object_base::set_transform(const transform_type& transform)
inline void object_base::set_transform(const transform_type& transform)
{
this->transform[1] = transform;
transformed();
}
inline void scene_object_base::set_translation(const vector_type& translation)
inline void object_base::set_translation(const vector_type& translation)
{
transform[1].translation = translation;
transformed();
}
inline void scene_object_base::set_rotation(const quaternion_type& rotation)
inline void object_base::set_rotation(const quaternion_type& rotation)
{
transform[1].rotation = rotation;
transformed();
}
inline void scene_object_base::set_scale(const vector_type& scale)
inline void object_base::set_scale(const vector_type& scale)
{
transform[1].scale = scale;
transformed();
}
inline bool scene_object_base::is_active() const
inline bool object_base::is_active() const
{
return active;
}
inline const typename scene_object_base::transform_type& scene_object_base::get_transform() const
inline const typename object_base::transform_type& object_base::get_transform() const
{
return transform[1];
}
inline const typename scene_object_base::vector_type& scene_object_base::get_translation() const
inline const typename object_base::vector_type& object_base::get_translation() const
{
return get_transform().translation;
}
inline const typename scene_object_base::quaternion_type& scene_object_base::get_rotation() const
inline const typename object_base::quaternion_type& object_base::get_rotation() const
{
return get_transform().rotation;
}
inline const typename scene_object_base::vector_type& scene_object_base::get_scale() const
inline const typename object_base::vector_type& object_base::get_scale() const
{
return get_transform().scale;
}
inline const tween<typename scene_object_base::transform_type>& scene_object_base::get_transform_tween() const
inline const tween<typename object_base::transform_type>& object_base::get_transform_tween() const
{
return transform;
}
inline tween<typename scene_object_base::transform_type>& scene_object_base::get_transform_tween()
inline tween<typename object_base::transform_type>& object_base::get_transform_tween()
{
return transform;
}
inline const typename scene_object_base::bounding_volume_type* scene_object_base::get_culling_mask() const
inline const typename object_base::bounding_volume_type* object_base::get_culling_mask() const
{
return culling_mask;
}
@ -223,7 +225,7 @@ inline const typename scene_object_base::bounding_volume_type* scene_object_base
* @tparam T This should be the same class that's inheriting from the scene object, in order to give it a valid type-specific ID.
*/
template <class T>
class scene_object: public scene_object_base
class object: public object_base
{
public:
/// Unique type ID for this scene object type.
@ -233,13 +235,15 @@ public:
};
template <typename T>
const std::atomic<std::size_t> scene_object<T>::object_type_id{scene_object_base::next_object_type_id()};
const std::atomic<std::size_t> object<T>::object_type_id{object_base::next_object_type_id()};
template <typename T>
inline const std::size_t scene_object<T>::get_object_type_id() const
inline const std::size_t object<T>::get_object_type_id() const
{
return object_type_id;
}
} // namespace scene
#endif // ANTKEEPER_SCENE_OBJECT_HPP

+ 4
- 0
src/scene/point-light.cpp View File

@ -20,6 +20,8 @@
#include "point-light.hpp"
#include "math/interpolation.hpp"
namespace scene {
point_light::point_light():
attenuation(float3{1, 0, 0}, math::lerp<float3, float>)
{}
@ -34,3 +36,5 @@ void point_light::update_tweens()
light::update_tweens();
attenuation.update();
}
} // namespace scene

+ 8
- 4
src/scene/point-light.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_POINT_LIGHT_HPP
#define ANTKEEPER_POINT_LIGHT_HPP
#ifndef ANTKEEPER_SCENE_POINT_LIGHT_HPP
#define ANTKEEPER_SCENE_POINT_LIGHT_HPP
#include "scene/light.hpp"
#include "utility/fundamental-types.hpp"
namespace scene {
class point_light: public light
{
public:
@ -44,7 +46,7 @@ public:
/// Returns the attenuation tween.
const tween<float3>& get_attenuation_tween() const;
/// @copydoc scene_object_base::update_tweens();
/// @copydoc object_base::update_tweens();
virtual void update_tweens();
private:
@ -66,5 +68,7 @@ inline const tween& point_light::get_attenuation_tween() const
return attenuation;
}
#endif // ANTKEEPER_POINT_LIGHT_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_POINT_LIGHT_HPP

+ 14
- 56
src/scene/scene.hpp View File

@ -20,61 +20,19 @@
#ifndef ANTKEEPER_SCENE_HPP
#define ANTKEEPER_SCENE_HPP
#include <list>
#include <unordered_map>
class scene_object_base;
/**
* Container for scene objects.
*/
class scene
{
public:
/**
* Adds an object to the scene.
*
* @param object Object to add.
*/
void add_object(scene_object_base* object);
/**
* Removes an object from the scene.
*
* @param object Object to remove.
*/
void remove_object(scene_object_base* object);
/// Removes all objects from the scene.
void remove_objects();
/// Updates the tweens of all objects in the scene.
void update_tweens();
/// Returns a list of all objects in the scene.
const std::list<scene_object_base*>* get_objects() const;
/**
* Returns a list of all objects in the scene with the specified type ID.
*
* @param type_id Scene object type ID.
* @return List of scene ibjects with the specified type ID.
*/
const std::list<scene_object_base*>* get_objects(std::size_t type_id) const;
private:
std::list<scene_object_base*> objects;
mutable std::unordered_map<std::size_t, std::list<scene_object_base*>> object_map;
};
inline const std::list<scene_object_base*>* scene::get_objects() const
{
return &objects;
}
inline const std::list<scene_object_base*>* scene::get_objects(std::size_t type_id) const
{
return &object_map[type_id];
}
/// 3D scene
namespace scene {}
#include "ambient-light.hpp"
#include "billboard.hpp"
#include "camera.hpp"
#include "collection.hpp"
#include "directional-light.hpp"
#include "light.hpp"
#include "lod-group.hpp"
#include "model-instance.hpp"
#include "object.hpp"
#include "point-light.hpp"
#include "spotlight.hpp"
#endif // ANTKEEPER_SCENE_HPP

+ 3
- 0
src/scene/spotlight.cpp View File

@ -22,6 +22,8 @@
#include "math/math.hpp"
#include <cmath>
namespace scene {
static float3 interpolate_direction(const float3& x, const float3& y, float a)
{
math::quaternion<float> q0 = math::rotation(global_forward, x);
@ -61,3 +63,4 @@ void spotlight::transformed()
direction[1] = math::normalize(get_transform().rotation * global_forward);
}
} // namespace scene

+ 8
- 4
src/scene/spotlight.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SPOTLIGHT_HPP
#define ANTKEEPER_SPOTLIGHT_HPP
#ifndef ANTKEEPER_SCENE_SPOTLIGHT_HPP
#define ANTKEEPER_SCENE_SPOTLIGHT_HPP
#include "scene/light.hpp"
#include "utility/fundamental-types.hpp"
namespace scene {
class spotlight: public light
{
public:
@ -69,7 +71,7 @@ public:
/// Returns the cosine cutoff tween.
const tween<float2>& get_cosine_cutoff_tween() const;
/// @copydoc scene_object_base::update_tweens();
/// @copydoc object_base::update_tweens();
virtual void update_tweens();
private:
@ -126,5 +128,7 @@ inline const tween& spotlight::get_cosine_cutoff_tween() const
return cosine_cutoff;
}
#endif // ANTKEEPER_SPOTLIGHT_HPP
} // namespace scene
#endif // ANTKEEPER_SCENE_SPOTLIGHT_HPP

Loading…
Cancel
Save