Home Game-development Learning Physics Modeling with PhysX

Learning Physics Modeling with PhysX

By Krishna Kumar
books-svg-icon Book
Subscription
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
Subscription
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
About this book

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.

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.

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.

Publication date:
October 2013
Publisher
Packt
Pages
104
ISBN
9781849698146

 

Chapter 1. Starting with PhysX 3 SDK

This chapter sheds some light on the history, features, license terms, and system requirements of PhysX. In it, we will learn how to download the PhysX SDK and configure it with MS Visual C++ 2010 for compiling PhysX programs.

 

Brief history


PhysX SDK is a mature physics engine, which has been under development since 2004. It was developed by Ageia with the purchase of ETH Zurich spin-off NovodeX. Ageia was a fabless semiconductor company and the first company that developed a dedicated co-processor capable of performing physics calculations, which was much faster than the general purpose CPUs available at that time.

The intention of Ageia was to sell PPU (Physics Processing Unit) cards much like the dedicated GPU (Graphics Processing Unit) cards that we buy today. It developed the PhysX software SDK (formerly NovodeX SDK) to harness the processing power of a PPU. The company also licensed out the PhysX SDK as a physics middleware library for game production. Unfortunately, the PPU cards didn't sell very well commercially in the market. On February 4, 2008, Nvidia announced that it would acquire Ageia. On February 13, 2008, the merger was finalized. The PhysX engine is now known as Nvidia PhysX. The potential reason of Ageia acquisition by Nvidia was to implement PhysX on top of their CUDA architecture enabled GPU(s), for hardware-accelerated physics processing. The PhysX GPU acceleration is exclusive to Nvidia GPU(s), which gives Nvidia an edge over its competitors; that is, GPU manufacturers such as ATI/AMD.

PhysX SDK 3.3.0 is the latest release at the time of writing this book. PhysX 3.x features a new modular architecture and a completely rewritten PhysX engine. It provides a significant boost in overall performance as well as efficiency. It is a heavily-modified version written to support multiple platforms but has a single base code. Supported platforms include Windows; Linux; Mac OS X; game consoles such as XBOX 360 and PS3; and even Android-powered handheld devices. PhysX 3.3.0 added support for new platforms such as Xbox One, PS 4, Nintendo Wii U, Apple iOS, PS Vita, and Windows RT. PhysX SDK 3.x has undergone architecture and API improvement, and the code is cleaned at many levels to get rid of obsolete and legacy features and to integrate new physics capabilities.

 

PhysX features


Nvidia PhysX is a state-of-the-art physics engine, which provides the following features:

  • Rigid body dynamics: Rigid body dynamics is the most essential aspect of physics simulation, and makes use of physics concepts such as position, velocity, acceleration, forces, momentum, impulse, friction, collision, constraints, and gravity. These properties give us the power to simulate or mimic real-world physics scenarios.

  • Character controller: Character controller is a special type of physics collider, which is mainly used for third-person or first-person player control, or any other kinematic body that may want to take advantage of the properties associated with the character controller.

  • Vehicle dynamics: Vehicle dynamics gives you the capability to simulate vehicle physics by using spherical wheel shapes that can simulate sophisticated tire friction models. A joint-based suspension system is used for vehicle suspension.

  • Particles and fluid simulation: Two of the most exciting features of PhysX are particles and fluid simulation. These features can be used to achieve a vast variety of cinematic effects. Particles can used for creating effects such as fire, spark, and debris, whereas fluid particles, also known as SPH (Smoothed Particle Hydrodynamics), are used to simulate liquid, gases, smoke, or any other SPH-based particle effect.

  • Cloth simulation: This feature allows you to simulate realistic cloth, which can be used for cloth simulation of the characters in the game or any other cloth-based objects, such as flags and curtains. These cloth objects can also be stretched, torn, or attached to other physical bodies.

  • Softbody simulation: This feature allows you to simulate volumetric deformable objects.

New in PhysX 3

Notable features in PhysX 3 are as follows:

  • Automatic and efficient multithreading, and a unified code base for all supported platforms.

  • Improved task manager and a managed-thread pool that is optimized to harness the processing capability of multi-core processors on all platforms.

  • A new aggregate concept in which multiple PhysX actors can be combined into one entity having a common collision boundary, which simplifies processing when large numbers of objects are involved.

  • A new binary in-place serialization by which we can efficiently insert the PhysX actors into a scene with minimal data copying and without extra memory allocation. Creation and destruction of actors is now decoupled from the insertion and removal of scenes, thus allowing flexible asset management strategies.

  • A highly optimized physics runtime that has better a response time, with lower memory footprints.

  • A new release of PhysX Visual Debugger (PVD) that allows for better performance profiling and in-depth memory analysis with enhanced visualization of all PhysX content across all major platforms.

  • A full vehicle model that includes components such as engine, clutch, gears, autobox, differential, wheels, tires, suspension, and chassis.

 

Downloading PhysX SDK and tools


Downloading PhysX SDK requires you to register as an Nvidia developer, which you can do for free at https://developer.nvidia.com. Once you have successfully created a Nvidia developer account, you need to apply for the APEX/PhysX Registered Developer Program, which you can find by clicking on My Account on the top right of the Nvidia developer web page. The approval request may take one to three business days to process.

After the successful approval of your APEX/PhysX Registered Developer Program request, click on PhysX/Tools Download, select your platform, and then download the PhysX SDK. Please note that for this book, we will download the SDK for PC (Windows) platform. Configuration to include the PhysX SDK's Include files and Library files that are covered in this chapter is also for the Windows platform.

The PhysX SDK license

The Nvidia PhysX SDK is totally free for the Windows platform, both commercial and noncommercial use. For Linux, OS X, and Android platforms, the Nvidia binary PhysX SDK and tools are free for educational and noncommercial use. For commercial use, the binary SDK is free for developers who work on their respective PhysX applications and make less than $100K in gross revenue. More information on license agreements can be found at https://developer.nvidia.com/content/physx-sdk-eula.

System requirements for PhysX

The minimum requirements to support the hardware-accelerated PhysX is an Nvidia GeForce 8 series or later GPU with a minimum of 32 CUDA cores and a minimum of 256 MB of dedicated graphics memory. However, each PhysX application has its own GPU and memory recommendations. In general, 512 MB of graphics memory is recommended unless you have a GPU that is dedicated to PhysX. The Nvidia graphics drivers are made in such a way that they can also take advantage of multiple GPU(s) in a system. These can be configured to use one GPU for rendering graphics and the second GPU only for processing PhysX physics.

 

Configuring with VC++ Express 2010


We will use Microsoft Visual C++ 2010 Express for compiling the PhysX program. It is freely available at www.microsoft.com. We have to include the PhysX library files and header files in VC++ Directories that can be found at View | Property Pages. Property Pages can also be modified from Property Manager. A Property Manager window enables us to modify project settings that are defined in property sheets. A project property sheet is basically an .xml file that is used to save project configurations and can also be applied to multiple projects because it is inheritable.

Configuring VC++ 2010 Express requires the following steps:

  1. After downloading the PhysX 3.x SDK for the Windows platform, which comes in a ZIP file, you need to extract it to any preferred location on your PC. For this book, we will extract the PhysX SDK's ZIP file to C:\dev. Finally, our PhysX SDK location will look like C:\dev\PhysX-3.3.0_PC_SDK_Core.

  2. Before including the PhysX library files and header files in Property Manager, we first need to create a new Visual C++ Win32 Console application. To do this, open your MS VC++ compiler from the toolbar and navigate to File | New | Project. Then, a New Project window will pop up. Select Win32 Console Application and also provide Name and Location for the project. Finally, click on the OK button to proceed further as shown in the following screenshot:

  3. Soon after, a Win32 Application Wizard window will pop up. Here, click on the Next button to get the Application Settings screen, where you need to make sure that the Empty project option is checked under Additional options. Finally, click on the Finish button as shown in the following screenshot:

  4. Next, we need to configure our project's VC++ directories so that it can find the PhysX SDK header files and libraries that are required for compiling the PhysX program. We will include the absolute path for PhysX SDK Include Directories and Library Directories. To do this in VC++ 2010 Express, navigate to View | Property Manager. If the Property Manager option is not visible there, navigate to Tools | Settings and select Expert Settings; this will enable the Property Manager option in View. In the Property Manager window, double-click on a configuration-and-platform node, for example, Debug | Win32 or Release | Win32, as shown in the following screenshot:

  5. Double-clicking on a configuration-and-platform node, such as Debug | Win32 or Release | Win32, will open Property pages for the respective node configuration, such as, Debug Property Pages or Release Property Pages. This can also be opened by navigating to View | Property pages.

  6. When configuration-specific Property Pages (namely Debug Property Pages or Release Property Pages) will pop up, select VC++ Directories and add the following entries:

    1. Select Include Directories and then click on <Edit...> to add C:\dev\PhysX-3.3.0_PC_SDK_Core\Include.

    2. Select Library Directories and then click on <Edit...> to add C:\dev\PhysX-3.3.0_PC_SDK_Core\Lib\win32 (for a 32-bit platform) or C:\dev\PhysX-3.3.0_PC_SDK_Core\Lib\win64 (for a 64-bit platform).

    Note

    For this book, we will include libraries for a 32-bit platform because it can run on either a 32-bit machine or a 64-bit machine.

  7. Finally, click on the OK button to save your changes and close the window.

These PhysX SDK directory settings are saved on a per user basis and not on per project basis. So whenever you create a new VC++ project in VC++ 2010 Express, PhysX directories will automatically be added to your Include Directories project. We are now finally done with the PhysX configuration in VC++ 2010 Express. In the next chapter, we will create our first PhysX program.

 

Summary


This chapter enlightened us with all of the basic PhysX-related information that is needed to proceed with the rest of this book. We learned how to register as a Nvidia developer and download the PhysX SDK from the Nvidia website. We also learned how to include the PhysX SDK files in Visual C++ 2010 for compiling PhysX programs.

About the Author
  • Krishna Kumar

    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.

    Browse publications by this author
Latest Reviews (1 reviews total)
Clear, knowledgeable. It needs a modern OpenGL update, using shaders. Also, it would be easier if the sample code was coming with copies of all needed libraries (freeglut for instance).
Learning Physics Modeling with PhysX
Unlock this book and the full library FREE for 7 days
Start now