Scale & aspect & window size

I find that when I resize my Panda window, everything on the screen (parented to render) gets larger by exactly the amount of resizing. What I’d prefer is for more to show up…so if an image was say 50% of the window height before the resize, it should be shorter after the resize.

I wonder if this is unavoidable due to the location of the camera staying fixed during a resize. Hopefully someone can explain that that’s wrong though and there is a way to get the desired behaviour?

Cheers

In order to see more you will have to either move the camera farther away from what you are looking at or increase the FOV on the camera.

Set the film size on your lens to be proportional to the window size. In a DirectObject subclass, receive window events via:

self.accept(base.win.getWindowEvent(), self.onWindowEvent)

Then write the event handler:

def onWindowEvent(self, window):
    width = base.win.getProperties().getXSize()
    height = base.win.getProperties().getYSize()
    base.cam.node().getLens().setFilmSize(width, height)
    base.cam.node().getLens().setFocalLength(FOCAL_LENGTH)

Set FOCAL_LENGTH to some constant. I think something around 200 should work, but you can play with it until it looks good to you.

teedee is correct. It sounds like you want to model the window as a porthole into a virtual world, so that increasing the window size will also increase FOV correspondingly. (Do you also want to model the change in the part of the scene that you can observe as you move the window around on the desktop?) To make this model accurately, of course, you need to know something about where your virtual eyepoint rests in relation to the window.

In any case, you can achieve this in Panda by assigning a callback to the window-event message, or by simply overloading ShowBase.windowEvent(), to do the intended thing. (The default ShowBase.windowEvent() is written to adjust the camera to compensate for aspect ratio changes, but not for size or placement changes.)

David

You guys are brilliant :smiley: Thank you for giving me the correct terminology and a working solution!

NB to anyone using the code above: it works until you try to change the camera’s orientation (HPR), at which point you’ll notice objects being twisted into some very strange proportions. It works perfectly otherwise, though. I suppose simply moving the camera forwards or backwards when changing the window size would work too. I’ll probably give that a try this week or the next.

Enjoy!