-
Notifications
You must be signed in to change notification settings - Fork 0
/
glviewer.h
65 lines (45 loc) · 2.08 KB
/
glviewer.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* GLViewer is a simple interface for opengl by handling the GLCore library
*
*/
#pragma once
#include "glviewer_common.h"
#include "buffers.h"
namespace GLViewer {
/*
TODO:
Viewer Dynamic GeometryBuffer:
The raw value Viewer needs is a Vertex (glm::vec3 position; glm::vec3 colour; )
currently we are using a Vertices (std::vector<glm::vec3> positions; glm::vec3 colour; )
We want to tell the dynamic buffer, this is where the data is.. e.g:
- allow a custom vector as a parameter like imgui does
- AddVertexPtr() Callback function to show where the point is to render and how to render it. emplace_back(glm::vec3 pos, glm::vec3 colour)
- maybe a template so you can pass anything?
// TODO: Callback to create vertices directly in place, also needs colour
*/
class Viewer
{
public:
Viewer();
Camera_CentreObject camera;
Buffers buffers;
float ScaleToPx(float size) { return size * (camera.GetZoom() / Window::GetHeight()); }
glm::vec2 ScaleToPx(const glm::vec2& p) { return { ScaleToPx(p.x), ScaleToPx(p.y) }; }
glm::vec3 ScreenToWorldCoords(const glm::vec2& p, bool invertY = true)
{
glm::vec2 screenCoords = invertY ? Window::InvertYCoord(p) : p;// + glm::vec2(0.0f, 1.0f); // TODO DO WE NEED TO OFFSET ???
return camera.GetWorldPosition(screenCoords);
};
std::optional<glm::vec2> WorldToScreenCoords(const glm::vec3& p, bool invertY = true) {
auto [success, position] = camera.GetScreenCoords(glm::vec3({ p.x, p.y, p.z }));
if (!success) { return std::nullopt; }
return std::optional<glm::vec2>{ invertY ? Window::InvertYCoord(position) : position };
};
void Render();
void RenderLoop(GLSystem& glsys, std::function<void()> cb_Configure, std::function<void()> cb_Draw_ImGui, std::function<void()> cb_Set_DynamicBuffers, std::function<void()> cb_Finalise = nullptr);
private:
// Projection / View matrices
glm::mat4 m_Proj;
glm::mat4 m_View;
};
} // End namespace GLViewer