FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_view.hpp
1/*
2 * Copyright 2025 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_GRAPHIC_C_VIEW_HPP_INCLUDED
18#define _FGE_GRAPHIC_C_VIEW_HPP_INCLUDED
19
20/*
21 * Original from : https://github.com/SFML/SFML
22 * Copyright (C) 2007-2022 Laurent Gomila
23 *
24 * Altered/Modified by Guillaume Guillet
25 */
26
27#include "FastEngine/fge_extern.hpp"
28#include "FastEngine/C_rect.hpp"
29#include "FastEngine/C_vector.hpp"
30#include "FastEngine/vulkan/C_viewport.hpp"
31#include <memory>
32
33namespace fge
34{
35
36class ObjectData;
37class RenderTarget;
38
39using ObjectDataWeak = std::weak_ptr<fge::ObjectData>;
40
48class FGE_API View
49{
50public:
51 View();
52 explicit View(fge::vulkan::Viewport const& viewport);
53 View(Vector2f const& center, Vector2f const& size);
54
55 void setCenter(Vector2f const& center);
56 Vector2f const& getCenter() const;
57
66 void setSize(Vector2f const& size);
67 Vector2f const& getSize() const;
68
69 void setRotation(float angleDeg);
70 float getRotation() const;
71
83 void setFactorViewport(fge::RectFloat const& factorViewport);
84 fge::RectFloat const& getFactorViewport() const;
85
94 void reset(fge::vulkan::Viewport const& viewport);
100 void move(Vector2f const& offset);
106 void rotate(float angle);
112 void zoom(float factor);
118 void resizeFixCenter(fge::Vector2f const& newSize);
119
127 [[nodiscard]] glm::mat4 const& getTransform() const;
128 [[nodiscard]] glm::mat4 const& getInverseTransform() const;
136 [[nodiscard]] glm::mat4 const& getProjection() const;
137 [[nodiscard]] glm::mat4 const& getInverseProjection() const;
138
139private:
140 fge::Vector2f g_center;
141 fge::Vector2f g_size;
142 float g_rotation;
143 fge::RectFloat g_factorViewport;
144
145 mutable glm::mat4 g_transform;
146 mutable glm::mat4 g_projection;
147 mutable glm::mat4 g_inverseTransform;
148 mutable glm::mat4 g_inverseProjection;
149 mutable bool g_transformUpdated;
150 mutable bool g_projectionUpdated;
151 mutable bool g_invTransformUpdated;
152 mutable bool g_invProjectionUpdated;
153};
154
155class FGE_API OwnView
156{
157public:
158 OwnView() = default;
159 OwnView(OwnView const& r);
160 OwnView(OwnView&& r) noexcept = default;
161 virtual ~OwnView() = default;
162
163 OwnView& operator=(OwnView const& r);
164 OwnView& operator=(OwnView&& r) noexcept = default;
165
166 View& createOwnView();
167 void removeOwnView();
168 [[nodiscard]] bool hasOwnView() const;
169 [[nodiscard]] std::shared_ptr<View> const& getOwnView() const;
170 void setOwnView(std::shared_ptr<View> view);
171
172 void ownViewOverrideParent(bool enable);
173 [[nodiscard]] bool isOwnViewOverridingParent() const;
174 void ownViewExplicitlySetDefaultView(bool enable);
175 [[nodiscard]] bool isOwnViewUsingExplicitDefaultView() const;
176
177 [[nodiscard]] View const& requestView(View const& source, fge::ObjectDataWeak object) const;
178 [[nodiscard]] View const& requestView(View const& source, OwnView const& parent) const;
179 [[nodiscard]] View const& requestView(View const& source) const;
180
181 [[nodiscard]] View const& requestView(fge::RenderTarget const& source, fge::ObjectDataWeak object) const;
182 [[nodiscard]] View const& requestView(fge::RenderTarget const& source, OwnView const& parent) const;
183 [[nodiscard]] View const& requestView(fge::RenderTarget const& source) const;
184
185private:
186 std::shared_ptr<View> g_ownView{nullptr};
187 bool g_overrideParents{false};
188 bool g_explicitDefaultView{false};
189};
190
191} // namespace fge
192
193
194#endif //_FGE_GRAPHIC_C_VIEW_HPP_INCLUDED
Data wrapper representing an Object in a Scene.
Definition C_scene.hpp:170
Definition C_renderTarget.hpp:56
Define a camera in a 2D scene.
Definition C_view.hpp:49
void move(Vector2f const &offset)
Helper function to move the view.
glm::mat4 const & getTransform() const
Get the transform of the view.
void rotate(float angle)
Helper function to rotate the view.
glm::mat4 const & getProjection() const
Get the projection matrix of the view.
void zoom(float factor)
Helper function to zoom the view.
void setSize(Vector2f const &size)
Set the size of the view.
void resizeFixCenter(fge::Vector2f const &newSize)
Resize the view and move it relatively to old center in order to expand it.
void reset(fge::vulkan::Viewport const &viewport)
Reset the view to the given viewport.
void setFactorViewport(fge::RectFloat const &factorViewport)
Set the viewport rectangle of the view.
Definition C_viewport.hpp:27