| 301 | glDisable(GL_DEPTH_TEST) |
| 302 | |
| 303 | class GridRenderer: |
| 304 | def __init__(self, radius=20, length=1.0, color=np.array(DEFAULT_GRID_RGBA), origin=[0, 0, 0], lineWidth=1) -> None: |
| 305 | self.gridRadius = radius |
| 306 | self.cellLength = length |
| 307 | self.color = color |
| 308 | self.origin = np.array(origin) |
| 309 | self.lineWidth = lineWidth |
| 310 | self.bounds = [-radius * length, radius * length] |
| 311 | |
| 312 | def render(self): |
| 313 | glLineWidth(self.lineWidth) |
| 314 | glEnable(GL_BLEND) |
| 315 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
| 316 | glEnable(GL_LINE_SMOOTH) |
| 317 | glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) |
| 318 | glEnable(GL_DEPTH_TEST) |
| 319 | glBegin(GL_LINES) |
| 320 | glColor4fv(self.color) |
| 321 | |
| 322 | for i in range(-self.gridRadius, self.gridRadius + 1): |
| 323 | x = i * self.cellLength |
| 324 | p0 = np.array([x, self.bounds[0], 0.]) + self.origin |
| 325 | p1 = np.array([x, self.bounds[1], 0.]) + self.origin |
| 326 | glVertex3f(p0[0], p0[1], p0[2]) |
| 327 | glVertex3f(p1[0], p1[1], p1[2]) |
| 328 | |
| 329 | for j in range(-self.gridRadius, self.gridRadius + 1): |
| 330 | y = j * self.cellLength |
| 331 | p0 = np.array([self.bounds[0], y, 0.]) + self.origin |
| 332 | p1 = np.array([self.bounds[1], y, 0.]) + self.origin |
| 333 | glVertex3f(p0[0], p0[1], p0[2]) |
| 334 | glVertex3f(p1[0], p1[1], p1[2]) |
| 335 | |
| 336 | glEnd() |
| 337 | glDisable(GL_BLEND) |
| 338 | glDisable(GL_LINE_SMOOTH) |
| 339 | glDisable(GL_DEPTH_TEST) |
| 340 | |
| 341 | class CameraFrustumRenderer: |
| 342 | def __init__(self, projectionMatrix, color=np.array(DEFAULT_FRUSTUM_RGBA)): |