fix a2dTop etc. for y-up coordinate systems; add base.setAspectRatio()

This commit is contained in:
David Rose 2012-03-02 04:27:06 +00:00
parent 700c299844
commit 237ae859d4

View File

@ -1189,6 +1189,12 @@ class ShowBase(DirectObject.DirectObject):
if xsize > 0 and ysize > 0: if xsize > 0 and ysize > 0:
self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize) self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
def setAspectRatio(self, aspectRatio):
""" Sets the global aspect ratio of the main window. Set it
to None to restore automatic scaling. """
self.__configAspectRatio = aspectRatio
self.adjustWindowAspectRatio(self.getAspectRatio())
def getAspectRatio(self, win = None): def getAspectRatio(self, win = None):
# Returns the actual aspect ratio of the indicated (or main # Returns the actual aspect ratio of the indicated (or main
# window), or the default aspect ratio if there is not yet a # window), or the default aspect ratio if there is not yet a
@ -2646,71 +2652,73 @@ class ShowBase(DirectObject.DirectObject):
the aspect ratio of the render/render2d DisplayRegion, by a the aspect ratio of the render/render2d DisplayRegion, by a
class that has redefined these. """ class that has redefined these. """
if not self.__configAspectRatio: if self.__configAspectRatio:
if aspectRatio != self.__oldAspectRatio: aspectRatio = self.__configAspectRatio
self.__oldAspectRatio = aspectRatio
# Fix up some anything that depends on the aspectRatio
self.camLens.setAspectRatio(aspectRatio)
if aspectRatio < 1:
# If the window is TALL, lets expand the top and bottom
self.aspect2d.setScale(1.0, 1.0, aspectRatio)
self.a2dTop = 1.0 / aspectRatio
self.a2dBottom = - 1.0 / aspectRatio
self.a2dLeft = -1
self.a2dRight = 1.0
# Don't forget 2dp
self.aspect2dp.setScale(1.0, 1.0, aspectRatio)
self.a2dpTop = 1.0 / aspectRatio
self.a2dpBottom = - 1.0 / aspectRatio
self.a2dpLeft = -1
self.a2dpRight = 1.0
else: if aspectRatio != self.__oldAspectRatio:
# If the window is WIDE, lets expand the left and right self.__oldAspectRatio = aspectRatio
self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0) # Fix up some anything that depends on the aspectRatio
self.a2dTop = 1.0 self.camLens.setAspectRatio(aspectRatio)
self.a2dBottom = -1.0 if aspectRatio < 1:
self.a2dLeft = -aspectRatio # If the window is TALL, lets expand the top and bottom
self.a2dRight = aspectRatio self.aspect2d.setScale(1.0, aspectRatio, aspectRatio)
# Don't forget 2dp self.a2dTop = 1.0 / aspectRatio
self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0) self.a2dBottom = - 1.0 / aspectRatio
self.a2dpTop = 1.0 self.a2dLeft = -1
self.a2dpBottom = -1.0 self.a2dRight = 1.0
self.a2dpLeft = -aspectRatio # Don't forget 2dp
self.a2dpRight = aspectRatio self.aspect2dp.setScale(1.0, aspectRatio, aspectRatio)
self.a2dpTop = 1.0 / aspectRatio
self.a2dpBottom = - 1.0 / aspectRatio
self.a2dpLeft = -1
self.a2dpRight = 1.0
# Reposition the aspect2d marker nodes else:
self.a2dTopCenter.setPos(0, 0, self.a2dTop) # If the window is WIDE, lets expand the left and right
self.a2dBottomCenter.setPos(0, 0, self.a2dBottom) self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0) self.a2dTop = 1.0
self.a2dRightCenter.setPos(self.a2dRight, 0, 0) self.a2dBottom = -1.0
self.a2dTopLeft.setPos(self.a2dLeft, 0, self.a2dTop) self.a2dLeft = -aspectRatio
self.a2dTopRight.setPos(self.a2dRight, 0, self.a2dTop) self.a2dRight = aspectRatio
self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom) # Don't forget 2dp
self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom) self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dpTop = 1.0
self.a2dpBottom = -1.0
self.a2dpLeft = -aspectRatio
self.a2dpRight = aspectRatio
# Reposition the aspect2d marker nodes # Reposition the aspect2d marker nodes
self.a2dTopCenterNs.setPos(0, 0, self.a2dTop) self.a2dTopCenter.setPos(0, self.a2dTop, self.a2dTop)
self.a2dBottomCenterNs.setPos(0, 0, self.a2dBottom) self.a2dBottomCenter.setPos(0, self.a2dBottom, self.a2dBottom)
self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0) self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0) self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
self.a2dTopLeftNs.setPos(self.a2dLeft, 0, self.a2dTop) self.a2dTopLeft.setPos(self.a2dLeft, self.a2dTop, self.a2dTop)
self.a2dTopRightNs.setPos(self.a2dRight, 0, self.a2dTop) self.a2dTopRight.setPos(self.a2dRight, self.a2dTop, self.a2dTop)
self.a2dBottomLeftNs.setPos(self.a2dLeft, 0, self.a2dBottom) self.a2dBottomLeft.setPos(self.a2dLeft, self.a2dBottom, self.a2dBottom)
self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom) self.a2dBottomRight.setPos(self.a2dRight, self.a2dBottom, self.a2dBottom)
# Reposition the aspect2dp marker nodes # Reposition the aspect2d marker nodes
self.a2dpTopCenter.setPos(0, 0, self.a2dpTop) self.a2dTopCenterNs.setPos(0, self.a2dTop, self.a2dTop)
self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom) self.a2dBottomCenterNs.setPos(0, self.a2dBottom, self.a2dBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0) self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0)
self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0) self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0)
self.a2dpTopLeft.setPos(self.a2dpLeft, 0, self.a2dpTop) self.a2dTopLeftNs.setPos(self.a2dLeft, self.a2dTop, self.a2dTop)
self.a2dpTopRight.setPos(self.a2dpRight, 0, self.a2dpTop) self.a2dTopRightNs.setPos(self.a2dRight, self.a2dTop, self.a2dTop)
self.a2dpBottomLeft.setPos(self.a2dpLeft, 0, self.a2dpBottom) self.a2dBottomLeftNs.setPos(self.a2dLeft, self.a2dBottom, self.a2dBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, 0, self.a2dpBottom) self.a2dBottomRightNs.setPos(self.a2dRight, self.a2dBottom, self.a2dBottom)
# If anybody needs to update their GUI, put a callback on this event # Reposition the aspect2dp marker nodes
messenger.send("aspectRatioChanged") self.a2dpTopCenter.setPos(0, self.a2dpTop, self.a2dpTop)
self.a2dpBottomCenter.setPos(0, self.a2dpBottom, self.a2dpBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 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.a2dpBottomLeft.setPos(self.a2dpLeft, self.a2dpBottom, self.a2dpBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, self.a2dpBottom, self.a2dpBottom)
# If anybody needs to update their GUI, put a callback on this event
messenger.send("aspectRatioChanged")
def userExit(self): def userExit(self):
# The user has requested we exit the program. Deal with this. # The user has requested we exit the program. Deal with this.