]> git.localhorst.tv Git - blank.git/blobdiff - src/graphics/viewport.cpp
combine text handling stuff into a class
[blank.git] / src / graphics / viewport.cpp
index 060738016233d00e197190106d907fe1db750eeb..e6ac76810b1c39a33c0008e9a2434621a3f93c0d 100644 (file)
@@ -76,7 +76,7 @@ void Canvas::UpdateProjection() noexcept {
 Viewport::Viewport()
 : cam()
 , canv()
-, center(1.0f)
+, cursor(1.0f)
 , chunk_prog()
 , entity_prog()
 , sprite_prog()
@@ -128,8 +128,6 @@ void Viewport::Resize(int w, int h) noexcept {
        cam.Aspect(fw, fh);
        canv.Resize(fw, fh);
 
-       center = glm::translate(glm::vec3(fw * 0.5f, fh * 0.5f, 0.0f));
-
        chunk_prog.SetProjection(Perspective());
        if (active_prog == HUD) {
                entity_prog.SetProjection(Ortho());
@@ -148,6 +146,26 @@ void Viewport::ClearDepth() noexcept {
 }
 
 
+void Viewport::SetCursor(const glm::vec3 &pos) {
+       cursor[3].x = pos.x;
+       cursor[3].y = pos.y;
+       cursor[3].z = pos.z;
+}
+
+void Viewport::SetCursor(const glm::vec3 &pos, Gravity grav) {
+       glm::vec2 p(align(grav, canv.Size(), glm::vec2(pos) + canv.Offset()));
+       cursor[3].x = p.x;
+       cursor[3].y = p.y;
+       cursor[3].z = pos.z;
+}
+
+void Viewport::MoveCursor(const glm::vec3 &d) {
+       cursor[3].x += d.x;
+       cursor[3].y += d.y;
+       cursor[3].z += d.z;
+}
+
+
 BlockLighting &Viewport::ChunkProgram() noexcept {
        if (active_prog != CHUNK) {
                chunk_prog.Activate();