accessing render, base.camera, base.win from c++?

Hi,

I’ve recently written some C++ extensions for Pada3D, and in my C++ code I need access to the following “python” variables: render, base.camera and base.win

So my application is not a pure C++ application but rather a Python app, and the python app then constructs my new C++ types (which I’ve exposed using interrogate), and as a part of construction it passes in the NodePaths for render, base.camera and the GraphicsWindow base.win.

This works all fine, but it feels kind of stupid to me, since these variables should all be “well known” on the C++ side already.

Is there a way I can get access to render, the current camera and the current graphicsWindow in C++?

Thanks,

Erik

Those things are handled by the Python class ShowBase. PandaFramework and WindowFramework is the C++ equivalent.

This page will probably be of interest to you:
panda3d.org/manual/index.php/T … _Framework

There’s no clean way to access the “base” variable besides through Python’s C API, I’m afraid.

Hi pro-rsoft,

Yes, I’ve looked into the WindowFramework myself…
And when writting a C++ app from scratch that clearly is the way to go.
But I’m in the situation, that the window was opened using the python ShowBase.

So in my C++ code, I don’t want to execute anything like

framework.open_framework(argc, argv);
framework.set_window_title("Hello World!");
// Open it!
WindowFramework *window = framework.open_window();

because that’s already been done for me. (by python)

Is there a way I can get to the WindowFramework pointer showbase construced?
Or some other way I can access the WindowFramework without constructing it myself?

Thanks,

Erik

Oh, I see what you mean now.

Because “render” and “camera” are concepts that are only defined at rendering time there is no way to get a ‘global render’ or ‘global camera’. You will either need to prompt the user to pass those to your class (but I advise against that, unless your class operates strictly per-camera), or use draw callbacks to do whatever you need to do through a callback function from the GSG, when it’s rendering a certain scene using a certain camera.

Maybe if you gave some more specific information what you are trying to do we might be able to give you some specific advice how to tackle that.

ShowBase does not use the WindowFramework interface (as it isn’t even exposed to Python), but instead, it creates a single camera and window by itself, and puts those in the “render” and “camera” variables. I don’t like the design of ShowBase myself because of this reason too.
I think reading ShowBase.py will make you understand more of it.

Hi pro-rsoft.

For the background, here’s what I’m working on:

I’ve integrated an ingame advertisment sdk into panda. The thing basically replaces textures on defined “ad spaces” in the game, and then calculates whether an ad is visible or not.
To do that I need to call an update function each frame, and as a part of that update I need the camera pos, look at, up dir, and the window resolution.

and right now, I pass the base.camera, and base.window into the update function.

I guess thats ok, I just wanted to know if there’s a better way of doing this. it seems not.

Thanks,

Erik

If you are just writing a C++ extension function, you can either write it so it receives a PyObject * parameter, and pass in the Python object of your choice (such as render) to that parameter from the Python side; or you can use the Python/C API callbacks to query the builtin module and pull “render” from that.

Edit: yep, that’s a perfectly good way to do it.

David