ShowBase: Minor fixes over aspect ratio and size calculations

- Do not take into accound SBS if it is not enabled
        - Always return value for getSize()
        - Properly handle SBS for window-events
        - Redo positioning of aspect2d(p) markers exactly as
        they are created when adjusting aspect ratio

Signed-off-by: deflected <deflected@users.noreply.github.com>
This commit is contained in:
deflected 2017-11-28 19:22:13 +02:00 committed by rdb
parent 2e20a0f16e
commit 7a46b2ca60

View File

@ -1258,9 +1258,9 @@ class ShowBase(DirectObject.DirectObject):
if win == None: if win == None:
win = self.win win = self.win
if win != None and win.hasSize() and win.getSbsLeftYSize() != 0: if win != None and win.getSideBySideStereo() and \
win.hasSize() and win.getSbsLeftYSize() != 0:
aspectRatio = float(win.getSbsLeftXSize()) / float(win.getSbsLeftYSize()) aspectRatio = float(win.getSbsLeftXSize()) / float(win.getSbsLeftYSize())
else: else:
if win == None or not hasattr(win, "getRequestedProperties"): if win == None or not hasattr(win, "getRequestedProperties"):
props = WindowProperties.getDefault() props = WindowProperties.getDefault()
@ -1295,7 +1295,6 @@ class ShowBase(DirectObject.DirectObject):
if not props.hasSize(): if not props.hasSize():
props = WindowProperties.getDefault() props = WindowProperties.getDefault()
if props.hasSize():
return props.getXSize(), props.getYSize() return props.getXSize(), props.getYSize()
def makeCamera(self, win, sort = 0, scene = None, def makeCamera(self, win, sort = 0, scene = None,
@ -2723,13 +2722,14 @@ class ShowBase(DirectObject.DirectObject):
# changed and update the camera lenses and aspect2d parameters # changed and update the camera lenses and aspect2d parameters
self.adjustWindowAspectRatio(self.getAspectRatio()) self.adjustWindowAspectRatio(self.getAspectRatio())
# Temporary hasattr for old Pandas if win.getSideBySideStereo() and win.hasSize() and win.getSbsLeftYSize() != 0:
if not hasattr(win, 'getSbsLeftXSize'):
self.pixel2d.setScale(2.0 / win.getXSize(), 1.0, 2.0 / win.getYSize())
self.pixel2dp.setScale(2.0 / win.getXSize(), 1.0, 2.0 / win.getYSize())
else:
self.pixel2d.setScale(2.0 / win.getSbsLeftXSize(), 1.0, 2.0 / win.getSbsLeftYSize()) self.pixel2d.setScale(2.0 / win.getSbsLeftXSize(), 1.0, 2.0 / win.getSbsLeftYSize())
self.pixel2dp.setScale(2.0 / win.getSbsLeftXSize(), 1.0, 2.0 / win.getSbsLeftYSize()) self.pixel2dp.setScale(2.0 / win.getSbsLeftXSize(), 1.0, 2.0 / win.getSbsLeftYSize())
else:
xsize, ysize = self.getSize()
if xsize > 0 and ysize > 0:
self.pixel2d.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
def adjustWindowAspectRatio(self, aspectRatio): def adjustWindowAspectRatio(self, aspectRatio):
""" This function is normally called internally by """ This function is normally called internally by
@ -2774,34 +2774,34 @@ class ShowBase(DirectObject.DirectObject):
self.a2dpRight = aspectRatio self.a2dpRight = aspectRatio
# Reposition the aspect2d marker nodes # Reposition the aspect2d marker nodes
self.a2dTopCenter.setPos(0, self.a2dTop, self.a2dTop) self.a2dTopCenter.setPos(0, 0, self.a2dTop)
self.a2dBottomCenter.setPos(0, self.a2dBottom, self.a2dBottom) self.a2dTopCenterNs.setPos(0, 0, self.a2dTop)
self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
self.a2dBottomCenterNs.setPos(0, 0, self.a2dBottom)
self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0) self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
self.a2dTopLeft.setPos(self.a2dLeft, self.a2dTop, self.a2dTop)
self.a2dTopRight.setPos(self.a2dRight, self.a2dTop, self.a2dTop)
self.a2dBottomLeft.setPos(self.a2dLeft, self.a2dBottom, self.a2dBottom)
self.a2dBottomRight.setPos(self.a2dRight, self.a2dBottom, self.a2dBottom)
# Reposition the aspect2d marker nodes
self.a2dTopCenterNs.setPos(0, self.a2dTop, self.a2dTop)
self.a2dBottomCenterNs.setPos(0, self.a2dBottom, self.a2dBottom)
self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0) self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0) self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0)
self.a2dTopLeftNs.setPos(self.a2dLeft, self.a2dTop, self.a2dTop)
self.a2dTopRightNs.setPos(self.a2dRight, self.a2dTop, self.a2dTop) self.a2dTopLeft.setPos(self.a2dLeft, 0, self.a2dTop)
self.a2dBottomLeftNs.setPos(self.a2dLeft, self.a2dBottom, self.a2dBottom) self.a2dTopLeftNs.setPos(self.a2dLeft, 0, self.a2dTop)
self.a2dBottomRightNs.setPos(self.a2dRight, self.a2dBottom, self.a2dBottom) self.a2dTopRight.setPos(self.a2dRight, 0, self.a2dTop)
self.a2dTopRightNs.setPos(self.a2dRight, 0, self.a2dTop)
self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
self.a2dBottomLeftNs.setPos(self.a2dLeft, 0, self.a2dBottom)
self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom)
# Reposition the aspect2dp marker nodes # Reposition the aspect2dp marker nodes
self.a2dpTopCenter.setPos(0, self.a2dpTop, self.a2dpTop) self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
self.a2dpBottomCenter.setPos(0, self.a2dpBottom, self.a2dpBottom) self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0) self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0)
self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0) self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0)
self.a2dpTopLeft.setPos(self.a2dpLeft, self.a2dpTop, self.a2dpTop)
self.a2dpTopRight.setPos(self.a2dpRight, self.a2dpTop, self.a2dpTop) self.a2dpTopLeft.setPos(self.a2dpLeft, 0, self.a2dpTop)
self.a2dpBottomLeft.setPos(self.a2dpLeft, self.a2dpBottom, self.a2dpBottom) self.a2dpTopRight.setPos(self.a2dpRight, 0, self.a2dpTop)
self.a2dpBottomRight.setPos(self.a2dpRight, self.a2dpBottom, self.a2dpBottom) self.a2dpBottomLeft.setPos(self.a2dpLeft, 0, self.a2dpBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, 0, self.a2dpBottom)
# If anybody needs to update their GUI, put a callback on this event # If anybody needs to update their GUI, put a callback on this event
messenger.send("aspectRatioChanged") messenger.send("aspectRatioChanged")