Files
dusk/tools/editortool/map/grid.py
Dominic Masters cf59989167
All checks were successful
Build Dusk / build-linux (push) Successful in 50s
Build Dusk / build-psp (push) Successful in 59s
Closer to actually editing
2025-11-16 10:40:20 -06:00

46 lines
1.5 KiB
Python

from OpenGL.GL import *
from dusk.defs import defs
class Grid:
def __init__(self, lines=1000):
self.cellWidth = float(defs.get('TILE_WIDTH'))
self.cellHeight = float(defs.get('TILE_HEIGHT'))
self.lines = lines
self.enabled = True
def draw(self):
if not self.enabled:
return
center = [0, 0, 0]
halfWidth = self.cellWidth * self.lines // 2
halfHeight = self.cellHeight * self.lines // 2
# Draw origin axes
glBegin(GL_LINES)
# X axis - RED
glColor3f(1.0, 0.0, 0.0)
glVertex3f(center[0] - halfWidth, center[1], center[2])
glVertex3f(center[0] + halfWidth, center[1], center[2])
# Y axis - GREEN
glColor3f(0.0, 1.0, 0.0)
glVertex3f(center[0], center[1] - halfHeight, center[2])
glVertex3f(center[0], center[1] + halfHeight, center[2])
# Z axis - BLUE
glColor3f(0.0, 0.0, 1.0)
glVertex3f(center[0], center[1], center[2] - halfWidth)
glVertex3f(center[0], center[1], center[2] + halfWidth)
glEnd()
# Draw grid
glColor3f(0.8, 0.8, 0.8)
glBegin(GL_LINES)
for i in range(-self.lines // 2, self.lines // 2 + 1):
# Vertical lines
glVertex3f(center[0] + i * self.cellWidth, center[1] - halfHeight, center[2])
glVertex3f(center[0] + i * self.cellWidth, center[1] + halfHeight, center[2])
# Horizontal lines
glVertex3f(center[0] - halfWidth, center[1] + i * self.cellHeight, center[2])
glVertex3f(center[0] + halfWidth, center[1] + i * self.cellHeight, center[2])
glEnd()