Learning Physics Modeling
with PhysX
Master the PhysX 3 Physics Engine and learn how
to program your very own physics simulation
Krishna Kumar
BIRMINGHAM - MUMBAI
Learning Physics Modeling with PhysX
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information 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 information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2013
Production Reference: 1211013
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84969-814-6
www.packtpub.com
Cover Image by Aniket Sawant (aniket_sawant_photography@hotmail.com)
Credits
Project Coordinator
Sherin Padayatty
Proofreader
Dirk Manuel
Indexer
Hemangini Bari
Production Coordinator
Conidon Miranda
Cover Work
Conidon Miranda
Author
Krishna Kumar
Reviewers
Devin Kelly-Collins
Rui Wang
Acquisition Editor
Kevin Colaco
Commissioning Editor
Deepika Singh
Technical Editors
Rosmy George
Jinesh Kampani
Shruti Rawool
Aman Preet Singh
Copy Editors
Mradula Hegde
Kirti Pai
Alfida Paiva
Adithi Shetty
Laxmi Subramanian
About the Author
Krishna Kumar is a Graphics and Game Programmer. He completed his Bachelor
of Engineering in Computer Science in 2010. Since then, he has been working in the
field of graphics, game programming, 3D interactive applications, and virtual reality.
He feeds on the advancement of graphics and game technologies. In his free time
he learns new things or plays FPS games such as Crysis, Far Cry, and COD. He
also maintains a website at www.gfxguru.org, which is dedicated to graphics
and game programming.
I would like to thank my parents for tolerating me since my birth,
giving me opportunities, and making me look at the world from
a different perspective. I would like to thank my brother, Pawan,
and my sister, Sangeeta, who have always acted as my backbone;
they keep on fueling my determination. I would like to thank my
brother-in-law, Chandrika Prasad, for his motivation.
I would also like to thank Sumeet Sawant, Yogesh Dalvi, and Sherin
Padayatty; without their contributions, this book would not have
been written.
About the Reviewers
Devin Kelly-Collins is currently a student at Kansas State University, pursuing
his undergraduate degree in Computer Science. He has mostly worked with Java
and C#, developing multithreaded desktop applications and Web applications.
He also has experience in developing games using XNA and Unity.
He is currently working with Surface Systems and Instruments, developing software
that is used to process road profiling data in real-time. He has also worked with
Kansas State University, developing web-based tools.
I would like to thank my girlfriend, Kalen Wright, for providing me
with a base of operations.
Rui Wang is the founder and CTO of Beijing iLyres Technology Co. Ltd. He is in
charge of new media interactive applications development. He is one of the most
active members of the official OpenSceneGraph community, and contributes to this
open source 3D engine regularly. He wrote the books OpenSceneGraph 3.0 Beginners'
Guide, OpenSceneGraph 3 Cookbook, and Augment Reality with Kinect, all of which
are published by Packt Publishing. He is also a novel writer and a guitar lover in
his spare time.
Many thanks to the writer and the Packt Publishing team for making
such a great book about PhysX, the world-famous Physics Engine.
And my deep gratitude to my family, for their love and spiritual
support.
www.PacktPub.com
Support files, eBooks, discount offers
and more
You might want to visit www.PacktPub.com for support files and downloads related to
your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
TM
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt’s online digital book
library. Here, you can access, read and search across Packt’s entire library of books.
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
immediate access.
Table of Contents
Preface
Chapter 1: Starting with PhysX 3 SDK
Brief history
PhysX features
New in PhysX 3
Downloading PhysX SDK and tools
The PhysX SDK license
System requirements for PhysX
Configuring with VC++ Express 2010
Summary
Chapter 2: Basic Concepts
Scene and Actors
Materials
Shapes
Creating the first PhysX 3 program
Initializing PhysX
Creating scene
Creating actors
Simulating PhysX
Shutting down PhysX
Summary
Chapter 3: Rigid Body Dynamics
Exploring a rigid body
Mass
Density
Gravity
Velocity
Force and Torque
1
7
7
8
9
10
11
11
11
15
17
17
18
19
20
20
21
22
23
24
25
27
27
27
28
28
28
28