Skip to content

Commit

Permalink
#2132: Draw a camera-centered grid snapped to multiples of 32
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 5, 2021
1 parent 53d3d9c commit 7a0ac7a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions radiant/camera/CamWnd.h
Expand Up @@ -219,6 +219,7 @@ class CamWnd :
void Cam_Draw();
bool onRender();
void drawTime();
void drawGrid();
void requestRedraw(bool force);

// Motion and ICameraView related
Expand Down

0 comments on commit 7a0ac7a

Please sign in to comment.