Skip to content

Commit

Permalink
Use default projection matrix in visualizer third person mode (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaatrasa authored Feb 14, 2024
1 parent 9f04dfe commit 4f99fd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/cli/visualization/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame

from .visualizer_renderers.util import lookAt, getOrthographicProjectionMatrixOpenGL
from .visualizer_renderers.util import lookAt, getPerspectiveProjectionMatrixOpenGL, getOrthographicProjectionMatrixOpenGL
from .visualizer_renderers.renderers import *

class CameraMode(Enum):
Expand Down Expand Up @@ -363,7 +363,7 @@ def __render(self, cameraPose, width, height, image=None, colorFormat=None):
target = cameraToWorld[0:3, 3]
if self.cameraSmooth: eye, target = self.cameraSmooth.update(eye, target, self.shouldPause)
viewMatrix = self.cameraControls3D.transformViewMatrix(lookAt(eye, target, up))
projectionMatrix = cameraPose.camera.getProjectionMatrixOpenGL(near, far)
projectionMatrix = getPerspectiveProjectionMatrixOpenGL(60.0, self.aspectRatio, near, far)
elif self.cameraMode == CameraMode.TOP_VIEW:
eye = cameraToWorld[0:3, 3] + np.array([0, 0, 15])
target = cameraToWorld[0:3, 3]
Expand Down
9 changes: 9 additions & 0 deletions python/cli/visualization/visualizer_renderers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ def getOrthographicProjectionMatrixOpenGL(left, right, bottom, top, near, far):
[0, 0, 2 / (far - near), -(far + near) / (far - near)],
[0, 0, 0, 1]
], dtype=np.float32)

def getPerspectiveProjectionMatrixOpenGL(fovy, aspect, near, far):
f = 1.0 / np.tan(np.radians(fovy) / 2.0)
return np.array([
[f / aspect, 0, 0, 0],
[0, -f, 0, 0],
[0, 0, (far + near) / (far - near), -2.0 * far * near / (far - near)],
[0, 0, 1, 0]
], dtype=np.float32)

0 comments on commit 4f99fd7

Please sign in to comment.