From 7a0ac7a156e61df5df7188907ee1b28f92151acd Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 5 Feb 2021 09:58:26 +0100 Subject: [PATCH] #2132: Draw a camera-centered grid snapped to multiples of 32 --- radiant/camera/CamWnd.cpp | 45 +++++++++++++++++++++++++++++++++++++++ radiant/camera/CamWnd.h | 1 + 2 files changed, 46 insertions(+) diff --git a/radiant/camera/CamWnd.cpp b/radiant/camera/CamWnd.cpp index 45c64e366a..60754bf538 100644 --- a/radiant/camera/CamWnd.cpp +++ b/radiant/camera/CamWnd.cpp @@ -588,6 +588,47 @@ void CamWnd::ensureFont() } } +void CamWnd::drawGrid() +{ + static double GRID_MAX_DIM = 2048; + static double GRID_STEP = 32.0; + + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_1D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + + glLineWidth(1); + glColor3f(0.5f, 0.5f, 0.5f); + + glPushMatrix(); + + // The grid is following the camera, but will always be in the z = 0 plane + auto origin = _camera->getCameraOrigin().getSnapped(GRID_STEP); + glTranslated(origin.x(), origin.y(), 0); + + glBegin(GL_LINES); + + for (double x = -GRID_MAX_DIM; x <= GRID_MAX_DIM; x += GRID_STEP) + { + Vector3 start(x, -GRID_MAX_DIM, 0); + Vector3 end(x, GRID_MAX_DIM, 0); + + Vector3 start2(GRID_MAX_DIM, x, 0); + Vector3 end2(-GRID_MAX_DIM, x, 0); + + glVertex2dv(start); + glVertex2dv(end); + + glVertex2dv(start2); + glVertex2dv(end2); + } + + glEnd(); + + glPopMatrix(); +} + void CamWnd::Cam_Draw() { wxSize glSize = _wxGLWidget->GetSize(); @@ -659,6 +700,10 @@ void CamWnd::Cam_Draw() glEnable(GL_LIGHT0); } + if (true) + { + drawGrid(); + } // Set the allowed render flags for this view unsigned int allowedRenderFlags = RENDER_DEPTHTEST diff --git a/radiant/camera/CamWnd.h b/radiant/camera/CamWnd.h index 647b1d6134..16bcc48de5 100644 --- a/radiant/camera/CamWnd.h +++ b/radiant/camera/CamWnd.h @@ -219,6 +219,7 @@ class CamWnd : void Cam_Draw(); bool onRender(); void drawTime(); + void drawGrid(); void requestRedraw(bool force); // Motion and ICameraView related