Panda and C++

I want to use the Panda3D engine through C++. Where can I find documentation for doing this?

Python is way too slow for my purposes, but C++ would serve me properly. Does anyone know where I could find more information about using C++ and Panda?

You can look at the comments in the source documentation itself; it’s pretty well commented. Especially look at the class comments in the *.h files, and the method comments before each method in the *.cxx and *.I files.

For general philosophy, the manual here will serve you pretty well. You just have to know to rename methods like NodePath.setPos() to something like NodePath::set_pos() in C++.

Look to pview for an example of using the framework library to get started. The framework library is the C++ equivalent to DirectStart.

David

What libraries and headers am I to link to?

I’d assume panda.h and libpanda.lib or something, but I’m not sure.

I just want to know how to create a panda window in C++. I can figure it out from there.

When you download Panda, you will get a directory full of hundreds of *.h files and another directory with several *.lib and *.dll files. (I’m not completely sure that the *.h and *.lib files are installed along with the binary distributions, but I think they are–if you don’t see them, you’ll probably have to go get the source and build that.)

There’s not just one header file to include. The particular header files you need to get depend on exactly what part of Panda you want to use. Panda is not monolithic like windows.h; you need to pick and choose the pieces of Panda you are developing with. Look to pview.cxx for examples to get you started; for the rest of it, you’ll have to learn to read the code, and include the header files that contain the interfaces you want to use.

Panda is not for the beginning C++ programmer. If you are not already a very strong C++ programmer, you might consider using the Python interfaces instead. We’ve found that Python is more than fast enough for driving a high-level game, once you have an engine like Panda doing the hard work of actually pushing vertices to your graphics card.

David

I suppose I’ll try it out in Python first.

I am a proficient C++ programmer (not expert, just proficient). Although I could find my way around, I suppose it would be easier to work through the Python interface.

But starting the game takes forever. However, I suppose that rapid development makes up for this.

Also, how is one supposed to package the final distribution? Is there a tool for doing this? Let’s say I wanted an end user to run the game. Should a python.exe ship with the installer?

The next version of Panda should launch much faster. But the interactive nature of Python is incredibly nice: I usually launch Python once at the beginning of the day, and then I keep the same Python process running, and just paste my new code into it as I’m working. It’s so nice to be able to just type stuff in at the prompt and it runs right away.


Also, how is one supposed to package the final distribution? Is there a tool for doing this? Let's say I wanted an end user to run the game. Should a python.exe ship with the installer?

There are several commercial tools that will package up your various Python files and bundle them into a single .exe (plus a handful of Panda .dll’s) for you. However, it will be a fair amount of work to get one of these tools to integrate nicely with Panda, but it can be done (for instance, at the VR Studio we use a program called py2exe to distribute Toontown).

At some future date, we hope to be able to provide a one-button solution to packaging up your applications, so if you wait long enough you won’t have to deal with it yourself. :slight_smile:

David

Hello ,

How do you do to do this? I’m launching the panda each time i change something in my code.
even if i use dynamic loading for CollisionSystem and EntitySystem…

I use Emacs as my Python editor, and I run Python as an interactive shell within Emacs.

Emacs can be burdensome to learn, but it’s immensely powerful. There is a standard Python mode for Emacs, but we customized it a bit–if you copy direct/src/directscripts/python-mode.el into your Emacs site-customize directory, you will gain access to our customizations, which include the ability to put your cursor within a class and hit control-C, control-V, and it will repaste the new class definition into your running Python process, as well as rebinding any currently active objects to use your new class definition.

It doesn’t always get it right; there are some subtle things that you still have to do by hand (like when you change the set of imports at the top of a file, for instance). But even if you never use Emacs or the c-c c-v command, in any good Python IDE you can copy your new class definition into the Python shell and execute it, and then recreate any instances of this class definition to ensure that the currently active objects have the new definition.

David

Actually i do use Idle… and its happen that i write class in it to test them before incorporation in my code.
However i have no clue how to force the replace in current shell…

I’ll have a look at emac…

Do you use Emacs on a *NIX or Windows platform?

Both, it works equally well on Linux as on Windows.

David

Ok i manage to type my first C script in emacs.

I’ve put python-mode in site-lisp folder (right under emacs-21.3).

could you explain me how to have emac use this mode and also how to launch panda3D from emac… :slight_smile:

(sorry to be so bad at emacs… but having the possibility to cut and paste my class in interactive mode is a kind of graal for me…).

Of course if you see tutorial that i should use before trying to use it, please be welcome

In your ~/.emacs file, put the line:


(load "python-mode")

You might also need this (but try it first without it):

(setq auto-mode-alist
      (append
       '(("\\.py$"   . python-mode)
         ) auto-mode-alist))

This should enable python-mode whenever you open a file named *.py.

To start Panda from emacs, run the command M-x ppy-shell. That is, hit Alt-X (or press ESC, then X) and type the command “ppy-shell” and press enter. It should launch ppython, and you can then type whatever import command you need to get started. Don’t put a run() command in your program, instead type run() at the prompt (or press control-D to type it as a macro). Press Enter to break back to a prompt from a running program.

David

So instead of working with a file, you keep all the commands under one instance of the Python shell? That is interesting.

I should reconfigure emacs. I have not used it in a while.

Ok, i’ve got the python mode (nice) , i’m able to get the ppython shell from emacs and also to load panda3d and make simple run…

now i guess that if i want to be able to get my framework works,
(like doing from ArkheniaFramework import * ) it should be packages
as a python module?

also its location should be on my path ( currently Panda is in E:\Panda3d, the framework is in E:\WG\ArkheniaFramework and emacs is in E:\Emacs210.3)

Am i right ?

You don’t necessarily need to set up a python module, or put your *.py files in any special directory on your PYTHONPATH, if you haven’t done this before. You can specify the directory your py-shell will run in.

By default, this is whatever the current directory was when you first typed the command py-shell in a particular Emacs, so one easy way is to “open” one of the files in your directory and have that as the current buffer when you type ppy-shell the first time.

If you want to change the current directory after you have already started a ppy-shell, you can stop the current Python process (ctrl-C, ctrl-D), then type M-x cd (this is Emacs-speak for pressing Alt-X, then typing the command “cd” and pressing enter). It will prompt you for the new directory. The directory change will be in effect the next time you launch Python (with the command ppy-shell again).

Then you can just import as usual.

David

I am confused as to how this is better than just invoking a python shell at the command line.