Book Image

Learning Physics Modeling with PhysX

By : Krishna Kumar
Book Image

Learning Physics Modeling with PhysX

By: Krishna Kumar

Overview of this book

<p>In this day and age, physics engines play a very critical role in the success of a sophisticated game. PhysX is a state-of-the-art cross-platform physics engine widely used by top game studios and developers. It contains all the physics-related components you will need and exploits the parallel-processing capability of modern GPUs as well as multi-core CPUs to make a game as physically-realistic as possible. This book will help you to program and simulate games by using PhysX 3.</p> <p>Learning Physics Modeling with PhysX helps you to master physics simulation using the PhysX Physics Engine from scratch. This is useful not only for game developers, but also for developers making virtual walkthroughs or training and other simulation applications. It will cover all the essential features of PhysX 3 with easy-to-understand code snippets and examples to help you learn quickly and efficiently.</p> <p>This book will start off by introducing you to the basic concepts of physic engines and will give you a glimpse of PhysX implementation. We then gradually cover more sophisticated topics with sample source code so that you can see what you have learned in action. We will cover the history and features of the PhysX SDK as well as how to configure it with the C++ compiler. After touching upon essential topics like rigid body dynamics and collision detection, we will gradually move on to more advanced topics like joints, scene queries, character controllers, particles, and cloth simulation. By the end of this book, you will have learned everything you need to know about the PhysX 3 Physics Engine, and you will be able to use it to program your very own physics simulation quickly and efficiently.</p>
Table of Contents (17 chapters)
Learning Physics Modeling with PhysX
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Welcome to Learning Physics Modeling with PhysX. Video games are emerging as a new form of entertainment, and are developed for all kind of platforms, such as PCs, consoles, Tablet PC, mobile phones, and other hand-held devices. Current-generation games are much more sophisticated and complex than ever. Third- party physics engines are widely used in video games as middleware to achieve a physically-realistic world behavior such as gravity, acceleration, collision, force, friction, and so on. Nvidia PhysX is the state-of-the-art cross-platform physics engine that is widely used by top-notch game studios and developers. It contains virtually all of the physics-related components that a developer may want to integrate into their game. PhysX Physics Engine exploits the parallel-processing capability of a modern GPU as well as multi-core CPUs to make a game as physically realistic as possible.

PhysX Physics Engine is not only useful for game developers but also for developers who want to make an interactive walkthrough, training, or any other 3D application that requires real-time physics simulation.

What this book covers

Chapter 1, Starting with PhysX 3 SDK, covers a brief history, features, licence terms, system requirements, and what's new in PhysX SDK. We will also learn how to configure PhysX SDK with VC++ 2010 compiler.

Chapter 2, Basic Concepts, covers the basic concepts of PhysX SDK, including terminologies such as scenes, actors, materials, shapes, and how they are created, updated, and destroyed in PhysX SDK.

Chapter 3, Rigid Body Dynamics, covers rigid body properties such as mass, density, gravity, velocity, force, torque, and damping, and how we can modify these in PhysX SDK. We will also learn about kinematic actors, sleeping state, and the solver accuracy of a rigid body.

Chapter 4, Collision Detection, covers collision shapes and their types, trigger shapes, collision detection phases such as Broad-Phase Collision Detection, Narrow Phase Collision Detection, Enabling Continuous Collision Detection (CCD), and so on.

Chapter 5, Joints, explains exploring joints and their types, such as a fixed joint, revolute joint, spherical joint, distance joint, prismatic joint, and D6 joint.

Chapter 6, Scene Queries, covers types of scene queries such as raycast queries, sweep queries and overlap queries, and their mode operations.

Chapter 7, Character Controller, covers the basics of a character controller, including creating and moving a character controller, updating its size, and other related properties such as auto stepping and slope limit.

Chapter 8, Particles, covers the creation of particles, and particle systems, and their types. We will learn about particle system properties and particle creation, updating, and releasing. We will also cover particle drains and collision filtering.

Chapter 9, Cloth, covers creation of cloth and cloth fabric, tweaking cloth properties such as cloth collision, cloth particle motion constraint and separation constraint, cloth self-collision, intercollision, and GPU acceleration.

Chapter 10, PhysX Visual Debugger (PVD), covers the basics of PVD, connecting to PVD using TCP/IP network, saving a PVD datafile to a disk, and PVD connection flags.

What you need for this book

You need a Windows PC (preferably with Windows 7 OS or higher) with Microsoft Visual C++ 2010 Express compiler installed on it. You can download VC++ 2010 Express for free from http://www.microsoft.com. You also need to download Nvidia PhysX SDK 3.3.0 from https://developer.nvidia.com/physx-downloads, which requires you to register for the Nvidia Developer Program. You may also want to download the freeglut library for Windows, which is freely available at http://freeglut.sourceforge.net. This library is used in the example code to render the PhysX components.

Who this book is for

This book is for game developers, hobbyists, or anybody who wants to learn about the PhysX Physics Engine with minimal prior knowledge of it. You don't have to be a die-hard programmer to get started with this book. Basic knowledge of C++, 3D mathematics, and OpenGL will be fine.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can explicitly wake an actor by calling PxRigidDynamic::wakeUp(), which requires an optional real value that determines how long until the body is put to sleep."

A block of code is set as follows:

PxMaterial* mMaterial = gPhysicsSDK->createMaterial(0.5,0.5,0.5);
PxRigidDynamic* sphere = gPhysicsSDK->createRigidDynamic(spherePos);
sphere->createShape(PxSphereGeometry(0.5f), *mMaterial);

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: "We have to include the PhysX library files and header files in VC++ Directories that can be found at View | Property Pages."

Note

Warnings or important notes appear in a box like this.

Tip

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 develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title in the subject of your message.

If there is a topic that you have expertise in and on which you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection 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 location 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 protecting 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.