Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to switch between Orthographic and Perspective projection #38

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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