I was looking inside the code that setups aspect2d in the ShowBase.py file (this is the function setupRender2d) and i have some sugestions to improve this.
aspectRatio = self.getAspectRatio() self.aspect2d = self.render2d.attachNewNode(PGTop("aspect2d")) self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)
Why don’t you add some options to define a “virtual” resolution and and coordinate system to the gui scene? This would simplify things a lot when building guis.
This options could be, for example:
The code above would then consult these parameters and use the appropriate transform.
w = virtual_gui_width h = virtual_gui_height aspectRatio = self.getAspectRatio() (w,h) = adjust_aspect_ration(w,h,aspectRatio) self.aspect2d = self.render2d.attachNewNode(PGTop("aspect2d")) if virtual_gui_coord_sys = TOP_LEFT: self.aspect2d.setScale(w, 1.0, -h) self.aspect2d.setX(-w/2.0) self.aspect2d.setY(h/2.0)
If i didn’t made a mistake with the math (probably did) this would make a a gui screen with a familiar 800.0 x 600.0 and place the origin at the top left as it is natural.
Also i have a question about the gui classes. This classes are binds to C++ classes or are pure Python implementations and would the trick above mess up with their working?