46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import OpenGL.GL as gl
|
|
from dusk.defs import defs
|
|
import colorsys
|
|
from editortool.map.map import map
|
|
|
|
hue = [0.0] # Mutable container for static hue
|
|
|
|
def drawSelectBox():
|
|
w = float(defs.get('TILE_WIDTH'))
|
|
h = float(defs.get('TILE_HEIGHT'))
|
|
d = float(defs.get('TILE_DEPTH'))
|
|
position = [
|
|
map.position[0] * w - (w / 2.0),
|
|
map.position[1] * h - (h / 2.0),
|
|
map.position[2] * d - (d / 2.0)
|
|
]
|
|
|
|
# Define the 8 vertices of the cube with w=h=d=1
|
|
vertices = [
|
|
(position[0], position[1], position[2]), # 0: min corner
|
|
(position[0]+w, position[1], position[2]), # 1
|
|
(position[0]+w, position[1]+h, position[2]), # 2
|
|
(position[0], position[1]+h, position[2]), # 3
|
|
(position[0], position[1], position[2]+d), # 4
|
|
(position[0]+w, position[1], position[2]+d), # 5
|
|
(position[0]+w, position[1]+h, position[2]+d), # 6
|
|
(position[0], position[1]+h, position[2]+d) # 7
|
|
]
|
|
# List of edges as pairs of vertex indices
|
|
edges = [
|
|
(0, 1), (1, 2), (2, 3), (3, 0), # bottom face
|
|
(4, 5), (5, 6), (6, 7), (7, 4), # top face
|
|
(4, 5), (5, 6), (6, 7), (7, 4), # top face
|
|
(0, 4), (1, 5), (2, 6), (3, 7) # vertical edges
|
|
]
|
|
|
|
# Cycle hue
|
|
hue[0] = (hue[0] + 0.01) % 1.0
|
|
r, g, b = colorsys.hsv_to_rgb(hue[0], 1.0, 1.0)
|
|
gl.glColor3f(r, g, b)
|
|
gl.glLineWidth(2.0)
|
|
gl.glBegin(gl.GL_LINES)
|
|
for edge in edges:
|
|
for vertex in edge:
|
|
gl.glVertex3f(*vertices[vertex])
|
|
gl.glEnd() |