1 #include <Engine/Scene/CameraManager.hpp>
3 #include <Core/Asset/Camera.hpp>
4 #include <Core/Asset/FileData.hpp>
5 #include <Core/Tasks/Task.hpp>
6 #include <Core/Tasks/TaskQueue.hpp>
7 #include <Engine/FrameInfo.hpp>
8 #include <Engine/RadiumEngine.hpp>
9 #include <Engine/Rendering/RenderObject.hpp>
10 #include <Engine/Scene/CameraComponent.hpp>
11 #include <Engine/Scene/ComponentMessenger.hpp>
12 #include <Engine/Scene/Entity.hpp>
13 #include <Engine/Scene/SystemDisplay.hpp>
19 using namespace Core::Utils;
20 using namespace Core::Asset;
25 defaultCamera.setFOV( 60.0_ra * Core::Math::toRad );
26 defaultCamera.setZNear( 0.1_ra );
27 defaultCamera.setZFar( 1000.0_ra );
28 m_activeCamera = defaultCamera;
34 LOG( logDEBUG ) <<
"CameraManager seems to be already initialized, do nothing.";
41 if ( index.isInvalid() || index > count() ) {
42 LOG( logDEBUG ) <<
"Try to activate camera with an invalid/out of bound index. Ignored.";
45 m_activeIndex = index;
46 updateActiveCameraData();
51 auto width = m_activeCamera.getWidth();
52 auto height = m_activeCamera.getHeight();
53 auto camComp = getCamera( m_activeIndex );
54 m_activeCamera = *camComp->getCamera();
55 Core::Transform localFrame = m_activeCamera.getFrame();
56 Core::Transform globalFrame = camComp->getEntity()->getTransform() * localFrame;
57 m_activeCamera.setFrame( globalFrame );
58 m_activeCamera.setViewport( width, height );
59 m_activeCamera.updateProjMatrix();
61 m_activeCameraObservers.notify( m_activeIndex );
65 for (
size_t i = 0; i < m_data->size(); ++i ) {
66 if ( cam == ( *m_data )[i] )
return i;
72 return m_data->size();
81 void process()
override { m_camera->updateTransform(); }
82 std::string getName()
const override {
return "camera updater"; }
87 for (
size_t i = 0; i < m_data->size(); ++i ) {
88 auto comp = ( *m_data )[i];
89 auto ro = comp->getRenderObject();
90 if ( ro->isVisible() ) {
91 auto updater = std::make_unique<RoUpdater>();
92 updater->m_camera = comp;
99 std::vector<Camera*> cameraData = filedata->getCameraData();
102 for (
const auto& data : cameraData ) {
103 std::string componentName =
"CAMERA_" + entity->getName() + std::to_string(
id++ );
105 *( comp->getCamera() ) = *data;
107 registerComponent( entity, comp );
109 LOG( logINFO ) <<
"CameraManager : loaded " << cpt <<
" Cameras. (now manager has " << count()
118 auto idx = getCameraIndex(
reinterpret_cast<CameraComponent*
>( component ) );
120 if ( idx == m_activeIndex ) { updateActiveCameraData(); }
130 for (
const auto& comp : this->m_components ) {
131 if ( comp.first == entity ) {
Camera class storing the Camera frame and the projection properties The view direction is -z in camer...
TaskId registerTask(std::unique_ptr< Task > task)
void unregisterComponent(const Entity *entity, Component *component) final
void activate(Core::Utils::Index index)
void generateTasks(Core::TaskQueue *taskQueue, const Engine::FrameInfo &frameInfo) override
Pure virtual method to be overridden by any system. Must register in taskQueue the operations that mu...
virtual void initialize()
Add a default camera.
CameraManager()
Constructor.
void handleAssetLoading(Entity *entity, const Core::Asset::FileData *data) override
virtual Core::Utils::Index getCameraIndex(const CameraComponent *cam)
virtual size_t count() const
Number of managed Cameras.
void registerComponent(const Entity *entity, Component *component) final
void unregisterAllComponents(const Entity *entity) final
void updateActiveCameraData()
update the active camera data
static Ra::Core::Asset::Camera defaultCamera
A component is an element that can be updated by a system. It is also linked to some other components...
An entity is an scene element. It ties together components with a transform.
Core::Utils::Observable< const Entity * > & transformationObservers() const
get a ref to transformation observers to add/remove an observer
virtual void unregisterAllComponents(const Entity *entity)
virtual void registerComponent(const Entity *entity, Component *component)
virtual void unregisterComponent(const Entity *entity, Component *component)
Structure passed to each system before they fill the task queue.