An Introduction to the Panda3D SDK

How to Start Programming with the Panda3D Games Engine

An Introduction to the Panda3D SDK - Mark Alexander Bain
An Introduction to the Panda3D SDK - Mark Alexander Bain
Create a simple 3D application with Pand3D's SDK and the Python programming language. Make this the first step in becoming a games programmer

The most important question that any mew games programmer can ask themselves is not "what game should I create?". It is actually "which games engine should I choose?". If they do ask that question then one very good answer is Panda3D and there are a number of reasons for that. Panda3D:

  • is free and open source;
  • is multi-platform
  • allows games programming in both C++ and Python
  • is powerful but not resource hungry
  • encourages object oriented design

Above all, Panda3D is incredibly easy to use.

Obtaining Panda3D

The Panda3D SDK (Software Developer's Kit) can be downloaded from the Panda3D web site. Here the programmer will find installation packages for:

  • Windows
  • Linux
  • Mac

It's then just a matter of following the instructions and in just a few minutes the ordinary programmer will be ready to become a games programmer.

Testing Panda3D

Just to make sure that the programmer really appreciates the versatility of the games engine, Panda3D come with some demo games already installed. The programmer can, therefore, test out games such as Asteroids (as shown in figure 1 at the bottom of this article) or Boxing Robots (as shown in figure 2).

Getting Ready to Program with Panda3D

Panda3D has no IDE (Integrated Design Environment). Instead it allows the programmer to choose the environment in which they want to program. For example the programmer may choose to use:

  • Windows Notepad to write code and and the command prompt to run it
  • Programmer Notepad to create and run the code

However, the process is always the same:

  • write Python code in a text editor
  • save the file with a .py extension
  • run the file using Panda3D's ppython executable.

The next stage is, of course, to write the code.

A Simple Panda3D Application

Not only does Panda3D come with some ready to run games, but it also comes with some ready to use models. It is, therefore, easy to create a simple application. One which will, for example, load a terrain and then spin a camera around it:

#Load the classes to be used from math import pi, sin, cos from direct.showbase.ShowBase import ShowBase from direct.task import Task
#Create a new class for the game
class MyApp(ShowBase):
_def __init__(self):
__ShowBase.__init__(self)
__# Load the environment
__self.environ = self.loader.loadModel("models/environment")
__# Render the model
__self.environ.reparentTo(self.render)
__# Scale the model
__ self.environ.setScale(0.1, 0.1, 0.1)
__self.environ.setPos(-8, 42, -10)
__# Spin the camera
__self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
_# The camera spinning function
_def spinCameraTask(self, task):
__angleDegrees = task.time * 6.0
__angleRadians = angleDegrees * (pi / 180.0)
__self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
__self.camera.setHpr(angleDegrees, 0, 0)
__return Task.cont
#Run the game
app = MyApp()
app.run()

The end result can be be seen in figure 3. And that just leaves one question for the new games programmer - "why haven't I programmed with Pand3D before?".

Mark Alexander Bain - Mark Alexander Bain is a writer, Mo Bro and consultant for all aspects of software development at dsquared. He has also written regularly ...

rss
Advertisement
Advertisement
Advertisement