Tài liệu Panda3D 1. 6 Game Engine Beginner''''s Guide by Dave Mathews doc - Pdf 10

www.it-ebooks.info
Panda3D 1.6 Game Engine
Beginner's Guide
Create your own computer game with this 3D rendering and
game development framework
David Brian Mathews
www.it-ebooks.info
Panda3D 1.6 Game Engine
Beginner's Guide
Copyright © 2011 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmied in any form or by any means, without the prior wrien permission of the
publisher, except in the case of brief quotaons embedded in crical arcles or reviews.
Every eort has been made in the preparaon of this book to ensure the accuracy of the
informaon presented. However, the informaon contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.
Packt Publishing has endeavored to provide trademark informaon about all of the
companies and products menoned in this book by the appropriate use of capitals. However,
Packt Publishing cannot guarantee the accuracy of this informaon.
First published: February 2011
Producon Reference: 1040211
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-849512-72-5
www.packtpub.com
Cover Image by Charwak A ()
www.it-ebooks.info

Kruthika Bangera
www.it-ebooks.info
About the Author
David Brian Mathews is a graduate in Electronic Visualizaon program from the
University of Illinois at Chicago. He began programming in the h grade with QBASIC
and has been designing games of various kinds, from table-top board games to computer
games, since childhood. Prior to entering higher educaon, he served for two years in the
United States Navy as a nuclear engineer before being honorably discharged for medical
reasons, where he learned discipline, advanced mathemacs, and nuclear theory, as well
as teamwork and leadership skills. During his years in school, Mathews earned valuable
experience with professional game development methods working both by himself and
with teams. He is skilled at programming, 3D modeling and animaon, drawing, and 2D
composing.
I'd like to thank my friends and family, who have been immensely
supporve of me throughout the wring of this book. In parcular, I'd like
to thank my mother, Carol Malley, and my friends Je Fuja and William
Hebert for all their eorts and sacrices on my behalf.
www.it-ebooks.info
About the Reviewers
Paulo Barbeiro Ferreira is Brazilian, from São Paulo, and graduated in Graphic Design
in 2004 at Belas Artes SP college. He is a postgraduate in Game Development at SENAC SP.
Paulo started his professional career in 1999 as a web developer.
Today, besides the web and mobile applicaon development work, Paulo is involved in
experimental educaonal projects in technology and cyber culture at SESC SP, where he
leads acvies about creave code and art soware, such as interacve environments,
games, and entertainment media.
Joni Hariyanto graduated from the Engineering Faculty of Brawijaya University a few years
ago. Now, he works as a freelance architect.
Actually, he's just a hobbyist in the computer science world. He has been programming since
rst grade junior high in languages including Pascal, Python, and C++.

immediate access.
www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: Installing Panda3D and Preparing a Workspace 7
Geng started with Panda3D installaon packages 8
Time for acon – downloading and installing Panda3D 8
Switching to an advanced text editor 11
Time for acon – downloading and installing Notepad++ 11
Installing the game content 13
Time for acon – demoing Suicide Jockeys 13
Installing oponal tools 14
Blender and Chicken 15
Spacescape 16
Explosion Texture Generator 16
Summary 17
Chapter 2: Creang the Universe: Loading Terrain 19
Notepad++ 20
Seng up a new le in Notepad++ 20
Time for acon – seng up a new le in Notepad++ 20
Imporng Panda3D components 21
Time for acon – imporng DirectStart 21
Creang a World Object 22
Time for acon – creang a World Object 23
Loading the terrain 27
Time for acon – loading the terrain 28
Loading les into Panda3D 30
The model path 30
Eggs 30
Bams 32

Time for acon – removing tasks by name 62
Dissecng task objects 64
Summary 65
Chapter 4: Taking Control: Events and User Input 67
Working with events 67
Time for acon – registering and responding to events 68
Using keyboard events 70
Using a key map 71
Time for acon – creang and using a key map 72
Implemenng advanced cycle controls 75
Time for acon – implemenng acceleraon 75
Time for acon – implemenng throle control 78
Time for acon – implemenng turning 80
Ulizing mouse input and creang camera control 82
www.it-ebooks.info
Table of Contents
[ iii ]
Time for acon – tying the camera to the cycle 82
Reacng to mouse movement 84
Time for acon – turning the camera with the mouse posion 85
Ending event response 86
Summary 87
Chapter 5: Handling Large Programs with Custom Classes 89
Imporng custom classes 89
Time for acon – making and imporng a custom class 90
Adding NodePath funconality to a custom class 93
Time for acon – dening the Cycle class 93
Simulang dri 97
Time for acon – simulang dri 97
Accessing classes from within another class 103

Time for acon – adding a bloom lter 161
Using a sky sphere 164
Time for acon – adding a sky sphere 164
Summary 167
Chapter 8: GUI Goodness: All About the Graphic User Interface 169
Creang a menu system 169
About DirectGUI 170
Time for acon – creang a menu system 171
Pung menus to use 187
Time for acon – using menus 188
In-game HUD 195
Time for acon – creang a basic HUD 196
Summary 203
Chapter 9: Animang in Panda3D 205
Actors and Animaons 205
Time for acon – loading Actors and Animaons 206
Controlling animaons 208
Animaon blending 209
Time for acon – blending two animaons 209
Creang and using Actor subparts 211
Time for acon – playing animaons on subparts 213
Exposing joints 214
Time for acon – animang our cycles 215
Summary 219
Chapter 10: Creang Weaponry: Using Mouse Picking and Intervals 221
Using mouse picking 221
Time for acon – seng up mouse aim 222
Understanding Intervals, Sequences, and Parallels 225
Sequences and Parallels 228
Creang machine guns 229

Time for acon – creang a preloader to load models 273
File handling 276
Time for acon – reading data from a le 277
Customizing the mouse cursor 278
Time for acon – customizing the mouse cursor 279
Creang an Installer 282
Time for acon – packing a Panda3D game 282
Summary 285
Appendix A: Creang a Sky Sphere with Spacescape 287
Learning Spacescape basics 288
Time for acon – geng started with Spacescape 289
Blending layers 292
Time for acon – blending layers to create nebulas 294
Using point stars and billboard stars 297
Time for acon – populang the sky with stars 297
Creang a sky sphere from a skybox made with Spacescape 302
Time for acon – populang the sky with stars 302
Time for acon – creang the sky sphere in Panda3D 303
Summary 305
Appendix B: Using Egg-Texture-Cards and ExploTexGen 307
Using ExploTexGen 308
Time for acon – reading the ExploTexGen documentaon 308
www.it-ebooks.info
Table of Contents
[ vi ]
Time for acon – designing an explosion 310
Creang ipbook animaons with egg-texture-cards 313
Time for acon – using egg-texture-cards 313
Addional egg-texture-card opons 314
Summary 315

Advanced animaon 323
Chapter 10: Creang Weaponry: Using Mouse Picking and Intervals 324
Mouse picking 324
Intervals 324
www.it-ebooks.info
Table of Contents
[ vii ]
Chapter 11: What's that Noise? Using Sound 325
Making music 325
Sounding o 325
Chapter 12: Finishing Touches: Geng the Game Ready for the Customer 325
Garbage collecon 325
Using a custom mouse cursor 326
Building an installer 326
Index 327
www.it-ebooks.info
www.it-ebooks.info
Preface
Panda3D is a game engine, a framework for 3D rendering and game development for
Python and C++ programs. It includes graphics, audio, I/O, collision detecon, and other
abilies relevant to the creaon of 3D games. Also, Panda3D is Open Source and free for
any purpose, including commercial ventures. This book will enable you to create nished,
marketable computer games using Panda3D and other enrely open source tools, and then
sell those games without paying a cent for licensing.
Panda3D 1.6 Game Engine Beginner's Guide follows a logical progression from a zero start
through the game development process all the way to a nished, packaged installer. Packed
with examples and detailed tutorials in every secon, it teaches the reader through rst-
hand experience. These tutorials are followed by explanaons that describe what happened
in the tutorial and why.
You will start by seng up a workspace, and then move on to the basics of starng up

hands dirty with some coding. It will take them from a blank le to a simple program that will
load up a terrain model and introduce related basic concepts.
Chapter 3, Managing Tasks Over Time introduces the reader with tasks, the task manager,
and controlling processes that need to occur over me or in an ongoing manner.
Chapter 4, Taking Control: Events and User Input focuses on creang user controls for the
game. Keyboard, mouse click, and mouse movement response will be covered. Camera
control will be integrated with handling mouse input.
Chapter 5, Handling Large Programs with Custom Classes; as the game has grown larger, the
me has come to show the reader how to break it apart into custom classes.
Chapter 6, The World in Acon: Handling Collisions will focus on making the reader
comfortable with collision detecon and the dierent collision event handlers. Collisions are
vital to a working game and their use is one of the hoest topics on the Panda3D forums.
Chapter 7, Making it Fancy: Lighng, Textures, Filters, and Shaders will explain textures
and the built-in shaders available in Panda3D while allowing the reader to apply lighng,
textures, lters, and shaders to the world and the characters in it.
Chapter 8, GUI Goodness: All About the Graphic User Interface takes the reader through the
producon of the game's GUI, including the HUD that displays during game play, the start
menu, and other bits and pieces.
www.it-ebooks.info
Preface
[ 3 ]
Chapter 9, Animang in Panda3D; here the reader will replace the stac models of hover
cycles with actors and learn all about actor animaon and joint manipulaon.
Chapter 10, Creang Weaponry: Mouse Picking and Intervals focuses on using intervals to
create weapons and their controls and describes how sequences and parallels can be used to
create interval scripts.
Chapter 11, What's that Noise? Using Sound; here with the game nearly complete, it's me to
introduce some sound eects and background music to bring the game to life. This chapter also
introduces eding the
config.prc le to change the audio library Panda3D uses.

learned.
You will also nd a number of styles of text that disnguish between dierent kinds of
informaon. Here are some examples of these styles, and explanaons of their meanings.
Code words in text are shown as follows: "The event name we give to the
accept() method
is a string that serves as an idener for the unique event we want to respond to."
A block of code is set as follows:
if(self.keyMap["d"] == True):
self.turn("r", dt)
elif(self.keyMap["a"] == True):
self.turn("l", dt)
When we wish to draw your aenon to a parcular part of a code block, the relevant lines
or items are set in bold:
self.menuGraphics = loader.loadModel(
" /Models/MenuGraphics.egg")
self.fonts = {
"silver" : loader.loadFont(" /Fonts/LuconSilver.egg"),
"blue" : loader.loadFont(" /Fonts/LuconBlue.egg"),
"orange" : loader.loadFont(" /Fonts/LuconOrange.egg")}
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "Now we see an entry for the
Cycle Move task in the sleep column".
www.it-ebooks.info
Preface
[ 5 ]
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to

nd any errata, please report them by vising http,//www.packtpub.com/support,
selecng your book, clicking on the errata submission form link, and entering the details
of your errata. Once your errata are veried, your submission will be accepted and the
errata will be uploaded on our website, or added to any list of exisng errata, under the
Errata secon of that tle. Any exisng errata can be viewed by selecng your tle from
http,//www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt
Publishing, we take the protecon of our copyright and licenses very seriously. If you come
across any illegal copies of our works, in any form, on the Internet, please provide us with
the locaon address or website name immediately so that we can pursue a remedy.
Please contact us at
with a link to the suspected pirated material.
We appreciate your help in protecng our authors, and our ability to bring you valuable content.
Questions
You can contact us at if you are having a problem with any
aspect of the book, and we will do our best to address it.
www.it-ebooks.info
Installing Panda3D and Preparing
a Workspace
It's me to take the rst big step. In this chapter we're going to acquire
Panda3D and get our work environment set up. Once we have all that done,
we're going to take a look at the game we'll be creang over the course of this
book.
In this chapter we shall:
 Download and install Panda3D
 Download and install Notepad++
 Install all of the content necessary for the game
 Demo the game we'll be creang
 Install any oponal tools desired

5. Click Next to connue and then accept the terms. Aer that, you'll be prompted
about where you want to install Panda3D.
www.it-ebooks.info
Installing Panda3D and Preparing a Workspace
[ 10 ]
6. The default locaon is just ne. Click the Install buon to connue. Wait for the
progress bar to ll up. When it's done, you'll see another prompt.
7. This step really isn't necessary. Just click No and move on.
8. When you have nished the installaon, you can verify that it's working by going
to Start Menu | All Programs | Panda3D 1.6.2 | Sample Programs | Ball in Maze
| Run Ball in Maze. A window will open, showing the Ball in Maze sample game,
where you lt a maze to make a ball roll around while trying to avoid the holes.
www.it-ebooks.info


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status