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>
19using namespace Core::Utils;
20using namespace Core::Asset;
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.";
56 Core::Transform globalFrame = camComp->getEntity()->getTransform() * localFrame;
65 for (
size_t i = 0; i <
m_data->size(); ++i ) {
66 if ( cam == ( *
m_data )[i] )
return i;
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;
102 for (
const auto& data : cameraData ) {
105 *( comp->getCamera() ) = *data;
109 LOG( logINFO ) <<
"CameraManager : loaded " << cpt <<
" Cameras. (now manager has " <<
count()
131 if ( comp.first == entity ) {
Camera class storing the Camera frame and the projection properties The view direction is -z in camer...
void setViewport(Scalar width, Scalar height)
Change the viewport size. Also compute aspectRatio.
void updateProjMatrix()
Update the projection matrix according to the current parameters.
Scalar getWidth() const
Return the width of the viewport.
Scalar getHeight() const
Return the height of the viewport.
void setZNear(Scalar zNear)
Set the Z Near plane distance to zNear.
void setZFar(Scalar zFar)
Set the Z Far plane distance to zFar.
void setFrame(const Core::Transform &frame)
Set the frame of the camera to frame.
Core::Transform getFrame() const
This class allows tasks to be registered and then executed in parallel on separate threads.
TaskId registerTask(std::unique_ptr< Task > task)
void notify(Args... p) const
Notify (i.e. call) each attached observer with argument p.
Core::Utils::Index m_activeIndex
active camera index
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...
Core::Utils::Observable< Core::Utils::Index > m_activeCameraObservers
Observers on active camera changes.
Ra::Core::Asset::Camera m_activeCamera
active camera data, active camera hasn't any component just pure data.
virtual void initialize()
Add a default camera.
CameraManager()
Constructor.
std::unique_ptr< CameraStorage > m_data
Stores the object that stores the Cameras...
virtual const CameraComponent * getCamera(size_t i) const =0
Get a pointer to the i-th Camera.
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
std::vector< std::pair< const Entity *, Component * > > m_components
List of active components.
virtual void unregisterAllComponents(const Entity *entity)
virtual void registerComponent(const Entity *entity, Component *component)
virtual void unregisterComponent(const Entity *entity, Component *component)
hepler function to manage enum as underlying types in VariableSet
Structure passed to each system before they fill the task queue.