Files
dusk/tools/editortool/map/grid.py
Dominic Masters b01c0d37b0
Some checks failed
Build Dusk / build-linux (push) Failing after 51s
Build Dusk / build-psp (push) Failing after 55s
Region editor
2025-11-28 08:48:42 -06:00

46 lines
1.5 KiB
Python

from OpenGL.GL import *
from dusk.defs import TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH
class Grid:
def __init__(self, lines=1000):
self.cellWidth = TILE_WIDTH
self.cellHeight = TILE_HEIGHT
self.lines = lines
self.enabled = True
def draw(self):
if not self.enabled:
return
center = [0.01,0.01,0.01]
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()