(self, cameraPose, width, height, image=None, colorFormat=None)
| 322 | pygame.quit() |
| 323 | |
| 324 | def __render(self, cameraPose, width, height, image=None, colorFormat=None): |
| 325 | import spectacularAI |
| 326 | |
| 327 | if not self.displayInitialized: |
| 328 | targetWidth = self.targetResolution[0] |
| 329 | targetHeight = self.targetResolution[1] |
| 330 | self.scale = min(targetWidth / width, targetHeight / height) |
| 331 | self.adjustedResolution = [int(self.scale * width), int(self.scale * height)] |
| 332 | self.aspectRatio = targetWidth / targetHeight |
| 333 | self.cameraFrustumRenderer = CameraFrustumRenderer(cameraPose.camera.getProjectionMatrixOpenGL(self.args.frustumNear, self.args.frustumFar)) |
| 334 | self.recorder = Recorder(self.args.recordPath, self.adjustedResolution) if self.args.recordPath else None |
| 335 | self.__initDisplay() |
| 336 | |
| 337 | glPixelZoom(self.scale, self.scale) |
| 338 | glClearColor(*self.args.backGroundColor, 1.0) |
| 339 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) |
| 340 | |
| 341 | if self.args.cameraFollow: |
| 342 | cameraToWorld = cameraPose.getCameraToWorldMatrix() |
| 343 | else: |
| 344 | cameraToWorld = np.array([ |
| 345 | [0, 0, 1, 0 ], |
| 346 | [-1, 0, 0, 0 ], |
| 347 | [ 0, -1, 0, 0], |
| 348 | [0, 0, 0, 1]] |
| 349 | ) |
| 350 | |
| 351 | near, far = self.args.cameraNear, self.args.cameraFar |
| 352 | if self.cameraMode == CameraMode.AR: |
| 353 | if image is not None: |
| 354 | # draw AR background |
| 355 | glDrawPixels( |
| 356 | width, |
| 357 | height, |
| 358 | GL_LUMINANCE if colorFormat == spectacularAI.ColorFormat.GRAY else GL_RGB, |
| 359 | GL_UNSIGNED_BYTE, |
| 360 | np.frombuffer(image.data, dtype=np.uint8)) |
| 361 | viewMatrix = cameraPose.getWorldToCameraMatrix() |
| 362 | projectionMatrix = cameraPose.camera.getProjectionMatrixOpenGL(near, far) |
| 363 | if self.args.flip: projectionMatrix = np.array([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) @ projectionMatrix |
| 364 | elif self.cameraMode == CameraMode.THIRD_PERSON: |
| 365 | up = np.array([0.0, 0.0, 1.0]) |
| 366 | forward = cameraToWorld[0:3, 2] |
| 367 | eye = cameraToWorld[0:3, 3] - 10.0 * forward + 5.0 * up |
| 368 | target = cameraToWorld[0:3, 3] |
| 369 | if self.cameraSmooth: eye, target = self.cameraSmooth.update(eye, target, self.shouldPause) |
| 370 | viewMatrix = self.cameraControls3D.transformViewMatrix(lookAt(eye, target, up)) |
| 371 | projectionMatrix = getPerspectiveProjectionMatrixOpenGL(60.0, self.aspectRatio, near, far) |
| 372 | elif self.cameraMode == CameraMode.TOP_VIEW: |
| 373 | eye = cameraToWorld[0:3, 3] + np.array([0, 0, 15]) |
| 374 | target = cameraToWorld[0:3, 3] |
| 375 | up = np.array([-1.0, 0.0, 0.0]) |
| 376 | viewMatrix = self.cameraControls2D.transformViewMatrix(lookAt(eye, target, up)) |
| 377 | left = -25.0 * self.cameraControls2D.zoom |
| 378 | right = 25.0 * self.cameraControls2D.zoom |
| 379 | bottom = -25.0 * self.cameraControls2D.zoom / self.aspectRatio # divide by aspect ratio to avoid strecthing (i.e. x and y directions have equal scale) |
| 380 | top = 25.0 * self.cameraControls2D.zoom / self.aspectRatio |
| 381 | projectionMatrix = getOrthographicProjectionMatrixOpenGL(left, right, bottom, top, -1000.0, 1000.0) |
no test coverage detected