Problem setting aspect ratio

Hi. I’m trying to set the display region to only occupy a portion of the screen. I can do that fine, but the aspect ratio doesn’t change no matter what I set it to. I’ve looked through the manual and can’t find a different way to do it.

This is the code I’m currently using:

    def clipCameraToBox(self,x0,y0,x1,y1):
        display=base.camNode.getDisplayRegion(0)
        #y is 1-etc to transform coord system to librocket compatible one
        display.setDimensions(x0/screenwidth, x1/screenwidth,
			      1-y1/screenheight, 1-y0/screenheight)
        lens = base.camNode.getLens()
        lens.setAspectRatio((x1-x0)/(y1-y0))

Dividing an integer by an integer yields another integer. Could that be the issue here, that you need to cast some of the variables to float?

I don’t think it’s an integer issue. Printing the aspect ratio reveals it’s a float*, and replacing it with arbitrary values (like 20.0 or 0.1) doesn’t do anything either.

It just stays at the same aspect ratio as the panda3d window when it was created, even if I make the display region very thin.

*edit: I meant to say, querying the lens object for its aspect ratio returns the proper float value, so setAspectRatio is working, but the camera doesn’t appear to be listening to its own values.

Ah, I think ShowBase may be overriding any aspect ratio that you set. Try using base.setAspectRatio instead.

Panda’s saying base.setAspectRatio doesn’t exist. There’s base.adjustWindowAspectRatio but that doesn’t do anything either. Neither does base.camLens.setAspectRatio.

I’m using version 1.80.

Trying to solve this has made me realise that my class structure sucks and makes no sense. I’m going to rewrite it and see if that fixes the issue somehow.

I’m sorry, but… looking in ShowBase.py, there really is a method called setAspectRatio.

Be sure to call base.disableMouse() before any of this, of course.

If it exists in 1.8.0, it’s not in my copy of it and it’s not in the API reference on this website. Perhaps it was added in a newer version?

Rewriting my code made the issue go away. I needed to make a new camera for new scenes so I set its lens’s ratio and then swapped the main display region’s camera for the new one.