-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathviewport.cpp
More file actions
47 lines (39 loc) · 1.17 KB
/
viewport.cpp
File metadata and controls
47 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <fea/rendering/viewport.hpp>
#include <fea/assert.hpp>
#include <string>
namespace fea
{
Viewport::Viewport()
{
}
Viewport::Viewport(const glm::uvec2& s, const glm::ivec2& pos, const Camera& cam) : mPosition(pos), mSize(s), mCamera(cam)
{
FEA_ASSERT(s.x > 0 && s.y > 0, "Viewport size cannot be zero or negative in any dimension! " + std::to_string(s.x) + " " + std::to_string(s.y) + " provided.");
}
const glm::ivec2& Viewport::getPosition() const
{
return mPosition;
}
const glm::uvec2& Viewport::getSize() const
{
return mSize;
}
void Viewport::setCamera(const Camera& cam)
{
mCamera = cam;
}
Camera& Viewport::getCamera()
{
return mCamera;
}
glm::vec2 Viewport::transformPoint(const glm::vec2 point) const
{
glm::vec2 halfViewSize = ((glm::vec2) mSize) * 0.5f;
return mCamera.transformPoint(point) + halfViewSize;
}
glm::vec2 Viewport::untransformPoint(const glm::vec2 point) const
{
glm::vec2 halfViewSize = ((glm::vec2) mSize) * 0.5f;
return mCamera.untransformPoint(point - halfViewSize);
}
}