// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "scene/SceneItem.hpp" #include "display/RenderTarget.hpp" namespace Dawn { enum class CameraType { PERSPECTIVE, ORTHOGONAL }; class Camera final : public SceneComponent { private: std::shared_ptr renderTarget; std::function onResizeListener; public: Event, float_t, float_t> onResize; float_t clipNear = 0.01f; float_t clipFar = 1000.0f; enum CameraType type = CameraType::PERSPECTIVE; float_t fov = 0.785398f; float_t orthoLeft = -1.0f; float_t orthoRight = 1.0f; float_t orthoBottom = -1.0f; float_t orthoTop = 1.0f; void onInit() override; void onDispose() override; void load(const SceneComponentLoadContext &ctx) override; /** * Returns the aspect ratio that the camera is using. In future I may * allow you to specify a custom ratio for stylistic reasons but for now I * just take the ratio of the specific frame buffer. * * @return The aspect ratio as a ratio of w/h. */ float_t getAspect(); /** * Returns the render target for this camera. * * @return Render target. */ std::shared_ptr getRenderTarget(); /** * Returns the projection matrix for this camera. * * @return Projection matrix. */ glm::mat4 getProjection(); /** * Shorthand for getItem()->lookAtPixelPerfect() * * @param position Position to look from. * @param look Position to look at. * @param scale Scale to use. At scale 1 then the centerest pixel is 1:1. * @return The Z distance that was calculated. */ float_t lookAtPixelPerfect( const glm::vec3 &position, const glm::vec3 &look, const float_t &scale = 1.0f ); /** * Sets the render target for this camera. * * @param renderTarget The render target to set. */ void setRenderTarget(const std::shared_ptr renderTarget); }; }