Files
dusk/tools/editortool/map/grid.py
Dominic Masters c874e6c197
All checks were successful
Build Dusk / build-linux (push) Successful in 47s
Build Dusk / build-psp (push) Successful in 1m6s
Fixed some stuff, procrastinating the real problem
2025-11-16 16:18:01 -06:00

46 lines
1.5 KiB
Python

from OpenGL.GL import *
from editortool.map.mapdefs 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, 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()