FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_view.hpp
1/*
2 * Copyright 2024 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
32namespace fge
33{
34
42class FGE_API View
43{
44public:
45 View();
46 explicit View(fge::vulkan::Viewport const& viewport);
47 View(Vector2f const& center, Vector2f const& size);
48
49 void setCenter(Vector2f const& center);
50 Vector2f const& getCenter() const;
51
60 void setSize(Vector2f const& size);
61 Vector2f const& getSize() const;
62
63 void setRotation(float angleDeg);
64 float getRotation() const;
65
77 void setFactorViewport(fge::RectFloat const& factorViewport);
78 fge::RectFloat const& getFactorViewport() const;
79
88 void reset(fge::vulkan::Viewport const& viewport);
94 void move(Vector2f const& offset);
100 void rotate(float angle);
106 void zoom(float factor);
112 void resizeFixCenter(fge::Vector2f const& newSize);
113
121 [[nodiscard]] glm::mat4 const& getTransform() const;
122 [[nodiscard]] glm::mat4 const& getInverseTransform() const;
130 [[nodiscard]] glm::mat4 const& getProjection() const;
131 [[nodiscard]] glm::mat4 const& getInverseProjection() const;
132
133private:
134 fge::Vector2f g_center;
135 fge::Vector2f g_size;
136 float g_rotation;
137 fge::RectFloat g_factorViewport;
138
139 mutable glm::mat4 g_transform;
140 mutable glm::mat4 g_projection;
141 mutable glm::mat4 g_inverseTransform;
142 mutable glm::mat4 g_inverseProjection;
143 mutable bool g_transformUpdated;
144 mutable bool g_projectionUpdated;
145 mutable bool g_invTransformUpdated;
146 mutable bool g_invProjectionUpdated;
147};
148
149} // namespace fge
150
151
152#endif //_FGE_GRAPHIC_C_VIEW_HPP_INCLUDED
Define a camera in a 2D scene.
Definition C_view.hpp:43
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