Skip to content

Commit

Permalink
Add option to switch between Orthographic and Perspective projection
Browse files Browse the repository at this point in the history
  • Loading branch information
sercero authored and paroj committed Apr 27, 2024
1 parent 1010192 commit 76ebe7c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ def preRenderTargetUpdate(self, evt):
self.app.fixed_yaw_axis = 2
self.app.update_fixed_camera_yaw()
ImGui.EndMenu()
if ImGui.MenuItem("Switch Camera Projection", "KP5"):
self.app._toggle_projection()
ImGui.Separator()
if ImGui.MenuItem("Show Axes", "A", self.app.axes_visible):
self.app._toggle_axes()
Expand Down Expand Up @@ -521,6 +523,8 @@ def __init__(self, infile, rescfg):
def keyPressed(self, evt):
if evt.keysym.sym == OgreBites.SDLK_ESCAPE:
self.getRoot().queueEndRendering()
if evt.keysym.sym == OgreBites.SDLK_KP_5:
self._toggle_projection()
elif evt.keysym.sym == ord("b"):
self._toggle_bbox()
elif evt.keysym.sym == ord("n"):
Expand Down Expand Up @@ -558,8 +562,16 @@ def mousePressed(self, evt):

self.entity = new_entity
self.entity.getParentSceneNode().showBoundingBox(True)

break

return True

def mouseWheelRolled(self, evt):
if self.cam.getProjectionType() == Ogre.PT_ORTHOGRAPHIC:
camnode = self.camman.getCamera()
diam = camnode.getPosition().length()
self.cam.setOrthoWindowHeight(diam)

return True

def _toggle_bbox(self):
Expand Down Expand Up @@ -590,6 +602,15 @@ def _toggle_grid(self):
else:
self.grid_floor.show_plane(-1)

def _toggle_projection(self):
if self.cam.getProjectionType() == Ogre.PT_PERSPECTIVE:
self.cam.setProjectionType(Ogre.PT_ORTHOGRAPHIC)
camnode = self.camman.getCamera()
diam = camnode.getPosition().length()
self.cam.setOrthoWindowHeight(diam)
else:
self.cam.setProjectionType(Ogre.PT_PERSPECTIVE)

def _save_screenshot(self):
name = os.path.splitext(self.filename)[0]
outpath = os.path.join(self.filedir, f"screenshot_{name}_")
Expand Down

0 comments on commit 76ebe7c

Please sign in to comment.