78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
#include "grid.h"
|
|
#include <SDL2/SDL_opengl.h>
|
|
|
|
//#include "viewport.h"
|
|
#include "renderer.h"
|
|
|
|
namespace Grid
|
|
{
|
|
bool visible = true;
|
|
|
|
void Toggle()
|
|
{
|
|
visible = not visible;
|
|
}
|
|
|
|
void Draw(const char viewport, int size)
|
|
{
|
|
if (not visible) return;
|
|
|
|
int planeOffset = 0;
|
|
char axis = 1; //AXIS_Y;
|
|
/* Viewport::Viewport v = Viewport::GetViewport(viewport);
|
|
if (v.perspective == Viewport::Perspective::Ortho) {
|
|
if (v.yaw == 0 and v.pitch == 90) {
|
|
planeOffset = 999;
|
|
axis = AXIS_Y;
|
|
} else if (v.yaw == 0 and v.pitch == -90) {
|
|
planeOffset = -999;
|
|
axis = AXIS_Y;
|
|
} else if (v.yaw == 90 and v.pitch == 0) {
|
|
planeOffset = -999;
|
|
axis = AXIS_X;
|
|
} else if (v.yaw == -90 and v.pitch == 0) {
|
|
planeOffset = 999;
|
|
axis = AXIS_X;
|
|
} else if (v.yaw == 0 and v.pitch == 0) {
|
|
planeOffset = 999;
|
|
axis = AXIS_Z;
|
|
} else if (v.yaw == 180 and v.pitch == 0) {
|
|
planeOffset = -999;
|
|
axis = AXIS_Z;
|
|
}
|
|
}
|
|
*/
|
|
const char axis_x = 0; //axis == AXIS_Z ? AXIS_X : axis == AXIS_X ? AXIS_Z : AXIS_X;
|
|
const char axis_y = 1; //axis == AXIS_Z ? AXIS_Y : axis == AXIS_X ? AXIS_Y : AXIS_Z;
|
|
|
|
|
|
Renderer::Push();
|
|
Renderer::Light(OFF);
|
|
Renderer::Depth(OFF);
|
|
if (size == 0) size = planeOffset == 0 ? 20 : 30;
|
|
glBegin(GL_LINES);
|
|
for (int i = -size; i <= size; i++) {
|
|
if (i == 0) {
|
|
glColor4f(0.5f, 0.5f, 0.5f, 1);
|
|
} else {
|
|
glColor4f(0.25f, 0.25f, 0.25f, 1);
|
|
}
|
|
char pos[2][3] {{0,0,0}, {0,0,0}};
|
|
pos[0][axis_x] = -size;
|
|
pos[1][axis_x] = size;
|
|
pos[0][axis_y] = pos[1][axis_y] = i;
|
|
pos[0][axis] = pos[1][axis] = planeOffset;
|
|
glVertex3f(pos[0][0], pos[0][1], pos[0][2]);
|
|
glVertex3f(pos[1][0], pos[1][1], pos[1][2]);
|
|
pos[0][axis_y] = -size;
|
|
pos[1][axis_y] = size;
|
|
pos[0][axis_x] = pos[1][axis_x] = i;
|
|
pos[0][axis] = pos[1][axis] = planeOffset;
|
|
glVertex3f(pos[0][0], pos[0][1], pos[0][2]);
|
|
glVertex3f(pos[1][0], pos[1][1], pos[1][2]);
|
|
}
|
|
glEnd();
|
|
Renderer::Pop();
|
|
}
|
|
}
|