Skip to content

Commit

Permalink
Set default yaw axis Vector3::UNIT_Y (tabletop mode) + Optional X, Z …
Browse files Browse the repository at this point in the history
…and free rotation
  • Loading branch information
sercero authored and paroj committed Apr 20, 2024
1 parent c01afeb commit 0125d1c
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ def preRenderTargetUpdate(self, evt):
if ImGui.MenuItem("Wireframe Mode", "W", app.cam.getPolygonMode() == Ogre.PM_WIREFRAME):
self.app._toggle_wireframe_mode()

if ImGui.BeginMenu("Fixed Camera Yaw"):
if ImGui.MenuItem("Disabled", "", self.app.fixed_yaw_axis == -1):
self.app.fixed_yaw_axis = -1
self.app.set_orientation()
ImGui.Separator()
if ImGui.MenuItem("X Axis", "", self.app.fixed_yaw_axis == 0):
self.app.fixed_yaw_axis = 0
self.app.set_orientation()
if ImGui.MenuItem("Y Axis", "", self.app.fixed_yaw_axis == 1):
self.app.fixed_yaw_axis = 1
self.app.set_orientation()
if ImGui.MenuItem("Z Axis", "", self.app.fixed_yaw_axis == 2):
self.app.fixed_yaw_axis = 2
self.app.set_orientation()
ImGui.EndMenu()

if entity.hasSkeleton() and ImGui.MenuItem("Show Skeleton", None, entity.getDisplaySkeleton()):
entity.setDisplaySkeleton(not entity.getDisplaySkeleton())
ImGui.EndMenu()
Expand Down Expand Up @@ -441,6 +457,9 @@ def __init__(self, infile, rescfg):
self.highlight_mat = None
self.restart = False
self.axes_visible = False
self.fixed_yaw_axes = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
self.fixed_yaw_axis = 1
self.default_tilt = Ogre.Degree(20)

self.active_controllers = {}

Expand Down Expand Up @@ -522,6 +541,23 @@ def _save_screenshot(self):
self.getRenderWindow().writeContentsToTimestampedFile(outpath, ".png")
self.cam.getViewport().setOverlaysEnabled(True)

def set_orientation(self):
camnode = self.camman.getCamera()
diam = camnode.getPosition().length()
camnode.setOrientation(Ogre.Quaternion.IDENTITY)
if self.fixed_yaw_axis >= 0:
camnode.setFixedYawAxis(True, self.fixed_yaw_axes[self.fixed_yaw_axis])
if self.fixed_yaw_axis == 0:
self.camman.setYawPitchDist(0, 0, diam)
camnode.roll(-Ogre.Degree(90))
elif self.fixed_yaw_axis == 1:
self.camman.setYawPitchDist(0, self.default_tilt, diam)
elif self.fixed_yaw_axis == 2:
self.camman.setYawPitchDist(0, self.default_tilt + Ogre.Degree(90), diam)
else:
self.camman.setYawPitchDist(0, self.default_tilt, diam)
self.camman.setFixedYaw(self.fixed_yaw_axis >= 0)

def reload(self):
if app.infile:
app.restart = True
Expand Down Expand Up @@ -655,8 +691,7 @@ def setup(self):

self.camman = OgreBites.CameraMan(camnode)
self.camman.setStyle(OgreBites.CS_ORBIT)
self.camman.setYawPitchDist(0, 0.3, diam)
self.camman.setFixedYaw(False)
self.camman.setYawPitchDist(0, self.default_tilt, diam)

self.input_dispatcher = OgreBites.InputListenerChain([self.getImGuiInputListener(), self.camman, self])
self.addInputListener(self.input_dispatcher)
Expand Down

0 comments on commit 0125d1c

Please sign in to comment.