Easy way to convert Panda3D python into C++ equivalent ?


Just a quick share of experience from a new comer into Panda3D C++ coding.

I’ve been trying to find out a quick “rule of thumb” way to translate Panda python scripts into their C++ equivalent, after getting my python prototype working properly.

Although the core logic is quite simple, I’ve to say that what I found the most frustrating is to dig into the doc or the forum and try to find (to guess) equivalent function calls.

For instance, here is a short list of Panda python statements that should be straightforward to get converted into equivalent C++ calls…

Well in fact I’m losing valuable time trying (guessing) to figure out the right way to translate.
After a lot of trial and error, it sometimes works but this dumb approach is far from being satisfactory

Width = base.win.getXSize()

Axecam.setEffect(CompassEffect.make(render, CompassEffect.PScale)) 

focal= base.camLens.getFocalLength()
dr = base.camNode.getDisplayRegion(0)
Buffer = base.win.makeTextureBuffer('rightBuffer', Width, Height) 
cam = base.makeCamera(Buffer,sort=-200,scene=render)
lensL = cam.node().getLens()

TextureA = loader.loadTexture("whatever.bmp")  
manager = FilterManager(base.win, base.cam)  
quad = manager.renderSceneInto(colortex=tex)  
loadPrcFileData('', 'win-size 1024 768')

base.accept("escape", sys.exit)

and so on... 

So my questions are :

(1) is there somewhere a short reference on how to help such manual translation ?

especially the base.xxx stuff seems a recurring question mark
then all the black magic to find out when : PT(xxx) whatever = DCAST(xxx, AAA); are actually needed…

(2) BTW. could a charitable soul already provide some answers on the above list ?

Many thanks


As a rule of thumb you can say the following about translating Panda’s Python function calls into C++ ones:

NodePath.setPos(x, y, z)

C++ equivalent:
NodePath::set_pos(x, y, z)

Or Python:

C++ equivalent:

Notice, however, that not all classes (and globals like base) that exist in Python exist in the C++ version as well.


Obviously the immediate translations :

(1) such as in name upperscale to _
such as exampleTry() to example_try()

(2) and python object.xxx to C++ object::xxx

are part of what I call ‘on the spot easy translations’, but the issue I was mentioning is more related to accessing internal structures I guess.

For instance the cameragroup stuff is an example of confusing access, ie after a while dealing with the nodes, the cam, the lenses pointers and appropriate DCASTing… are quickly becoming a nightmare.


some of the base things like base.win are accessed through WindowFramework.

PandaFramework framework;
framework.open_framework(argc, argv);
WindowFramework *window = framework.open_window();

NodePath camera = window->get_camera_group();

DisplayRegion dr = window->get_display_region_3d();
int width = dr.get_pixel_width();

Thanks again Tah,

Well this is the path I’ve been using so far: trying to grab (and infer) some infos looking at the code and looking for instance at WindowFramework.

I have to tell that it’s a real pain in the neck…

base is an instance of ShowBase. No idea if that class is available in C++ too.
It’s a kind of glue between the most needed things (like window, main rendering loop, camera, scene graph roots). Dig into the Python file and try to track down the classes base gives easy access to.

Hi Nemesis, thanks,

Digging into the .py file indeed provides a lot of insight, however to be honest any time I’m entering into this journey I feel like trying to solve a riddle !