Default camera vs custom cameras

Hey all,

I’m trying to create a new camera class, however there’s obviously stuff that Panda’s default camera does automatically that you have to write yourself in order to get custom cameras to have the same behavior. The first is that you have to manually change your aspect ratio when the window changes, which I’ve done with the following:

dr = 0 ) float( dr.getPixelWidth() ) / float( dr.getPixelHeight() ) ) 

This is great - but now the stuff parented to pixel2d is squashing and stretching whenever the window is resized. I’m pretty sure that using the default camera doesn’t do this - can anyone tell me what I’m not doing on order for the pixel2d layer to look correct? I expected that this layer would not change considering it is meant to be pixel perfect. :S If I’ve misunderstood how this works please correct me!

In normal usage, the method ShowBase.windowEvent is set up to be called in response to the “window-event” message, which is triggered whenever the window is resized by the user (as well as at other times).

This method is responsible for, among other things, adjusting the scale on pixel2d to compensate for the new window size.

If you do something that causes this method to no longer be called, then pixel2d will start to squash and stretch instead of self-adjusting whenever you resize the window.


Thanks for the response, David. So if I add the line, 'base.accept( ‘window-event’, base.windowResize ) that should fix the issue? I’ll still have to change the cameras aspect ratio with the new window’s dimensions manually, right?

Um, maybe? I don’t know everything you’re doing, so I can’t tell you whether you need to replace any other code that ShowBase would be doing or not. But don’t be afraid to read and figure out what it’s doing too. :slight_smile:


Will do. Thanks David!