Physics Engines


With all this new knowledge about the basics of physics you can now compare existing physics engines a little easier. After these basics are handled and after making sure you have the correct constants defined and feel comfortable in your unit system, you should think a little bit about the requirement for your game. Physics engines can often do a lot of different things and while many physics demos and tutorials look pretty cool, they cannot be used for most games. Having a bunch of boxes on top of each other and kicking them over is fun the first time, but not many games even allow direct control of boxes to push them around, and after a while it really gets boring seeing boxes fall over. It is like being in kindergarten again.

But not all demos are just a bunch of boxes. There are many good examples showing you specific features of physics engines, but my point is that most games only need certain features. First-person shooter games can probably use most of the features from physics engines and you can see that by just looking at the released games in the past couple of years. Almost all first-person shooters have some kind of physics implemented, whereas other games like role playing games, strategy games, and so on have either no physics or just rudimentary physics, often only used to improve the visual effects a little bit, but not game logic itself.

I personally don’t like physics in strategy games, because they are not implemented very well and do not improve the game. They often just add better visuals and have as a side effect that your units can die if some big building collapses or falls over your units. It is like playing chess while an earthquake is going on; it really destroys the game principle and you would not be able to make any clever moves anymore because everything is just shaking and falling over. Maybe it will take time until the developers figure out how to use physics decently in the game play and in a way that makes the game still predictable and not luck-based.

What I really like are physics for explosions, effects, and for improving the visual quality. There are several games that have really nice simulations for water, explosion, and smoke effects that interact with the surrounding environment, and so on.

As I said before you will not be able to use any of the physics engines on the Xbox 360 when using XNA because all of them are based on unmanaged code, which is just not supported in XNA. On the Windows platform you can use whatever you like, but even here most engines do not have a proper .NET interface that allows you to easily use and handle physics directly in your game. The possibilities for .NET are discussed when you go through the engines in a second. Anyway, take a quick look at some of the features of physics engines available today:

  • Forces like gravity, friction, kinetic and contact friction, buoyancy, and so on.

  • Basic physics objects support for defining and handling boxes, spheres, cylinders, plates, and so on. Often these engines also support connected objects and more complex predefined models like cars, planes, hovercrafts, ships, and so on to allow you to quickly play around with them.

  • Checking for collisions between many objects, especially if they are not just spheres. This is usually the main place for optimizations because collision calculations are used very often and require checking a lot of objects, bounding spheres, and even polygon-based checks. The Rocket Commander game shows a good solution on how to check many collisions that are optimized with the help of sectors to achieve great performance.

  • Collision response, which is executed when a collision was detected. Either you let the objects bounce off each other (like in Rocket Commander), or you can even damage or break them (collision force is transformed to kinetic energy and breaks up your models). Games usually use predefined 3D models for explosions, wrecks, and broken parts because it would really be hard to generate this data in real time, but the result is still great looking if the 3D artist does a good job.

  • Projectile physics can help you for bullets, rockets, and other projectiles that are fired. You saw how projectiles are used in the last chapter and if you have a physics engine that handles projectiles too, you would just add the projectile to it and allow using physics parameters and maybe adding special behavior depending on the 3D surroundings (for example, bullets are slower under water).

  • Even complete particle systems can be done with physics and as I said earlier I really like effect systems that can make good use of a physics engine, but effect systems are already a lot of work.

  • There are many more features a physics engine can have like supporting rigid body simulators, rag-doll physics for characters falling down, deformable objects like clothes, flags, fluids, and other complex bodies.

PhysX

PhysX is the name for the physics engine and SDK by AGEIA, which was formerly known as NovodeX SDK, but PhysX is also the name of the PPU (physics processing unit) also developed by AGEIA. The PhysX PPU is the world’s first card devoted just to calculating physics on the PC and can be used in any game that uses the PhysX SDK. Currently there are not many games around that support the PhysX engine, but many engines and upcoming games have already licensed the PhysX SDK and the most popular step was done by Sony licensing PhysX for its Playstation 3 console game development.

Even without having the PPU the engine is really powerful and the developers have been doing physics engines for a long time now. They are probably the number two behind the Havok engine, which is more widely used, not only in games, but also in 3D content creation programs like 3D Studio Max. While the idea is nice to offload the heavy lifting for physics calculations to a special card, the PPU is just too expensive ($250–$300) and not many people will have this card. Most people who buy a physics card like this will probably be developers or artists that can benefit from the card in the content creation process, but you can’t expect your gamers to have this card in order for your game to work. But PhysX also performs well on the CPU, and thanks to multi-core systems it runs well on today’s hardware too, but not as crazy good as the PPU.

Not so many games use PhysX right now; you can only find a handful of games using the engine. Examples are Ghost Recon, Gothic 3, Joint Task Force, and most recently Gears of War (Xbox 360). But there are many future titles and engines like the Unreal Tournament 2007 game and the Unreal 3 engine, Splinter Cell, Monster Madness, and so on.

PhysX focuses a lot on games, game engines, and handling effects, the game logic that uses physics, and having a lot of cool looking examples and tutorials. Their main advantage is that they have the PPU hardware to run a lot faster than all the other physics engines and PhysX also uses a more unified architecture to handle all physic calculations the same way.

You can find more information about PhysX on the official website at http://www.ageia.com.

Havok

Havok is the name of the very popular and widely known Havok Game Dynamics SDK (currently at version 4, released in 2006) and also the name of the company that develops this SDK. It was founded in 1998 and the first SDK (v 1.0) was released in 2000. More than 100 games use the Havok physics engine today and the most famous ones are games like Half-Life 2 and the Source engine by Valve, which is used by many other mods based on Half-Life. Havok is mainly used by first-person shooter games, but some other game genres also have been using the Havok engine.

Havok is available on many platforms including the PC (Windows and Linux) and almost every console that came out since it was released (Xbox, Xbox 360, PS 2, PS 3, WII, Game Cube). It is written in C/C++ and is very portable to any system that allows compiling C code. For you as a .NET developer there is not much support; there may be wrappers out there, but I have not heard of any .NET game or engine that uses Havok.

This physics engine is not only used in games, but it is also available in 3D Studio Max, which uses the middleware internally and is quite popular in the 3D artist community for simulating physics effects. In previous versions it was implemented as a plug-in named reactor, but in recent versions it is implemented into the basic version of 3D Studio Max. Havok was even used in the movie production of the Matrix trilogy.

Havok supports two major physics operations. Effect physics are used for anything that does not affect the game play and they can even be offloaded to a GPU that supports Shader Model 3.0 like the GeForce 7x and 8x series, especially if the GPU is fast. And then there are game physics, which are calculated on the CPU. Havok is the main competitor of PhysX and proves that you can do really great things without having an extra PPU; even the Half-Life 2 game from 2004 proved that it was possible to have pretty good physics in a game and even how to improve the game play through physics.

You can find more information about Havok on the official website at http://www.havok.com/.

ODE

ODE stands for Open Dynamics Engine and unlike PhysX and Havok is not a commercial engine, which may be more interesting to most beginner developers or teams that just don’t have the kind of money to use a big commercial physics engine.

ODE is an open source physics engine, which uses the BSD license (or LGPL if you like that). It was started in 2001 and some games have been developed with it already, but it is not as feature-complete as PhysX or Havok and certainly not that successful.

ODE basically supports rigid body dynamics and collision detection. You will still have a lot of work to do for more advanced physics, but ODE gives you a nice basic framework, which gives you all the basic geometries (like boxes, spheres, cylinders, and so on) and physics calculations you need to do some basic physics demos. There are also frameworks that have been built on top of ODE or use ODE.

Now comes the cool part: ODE has a nice .NET wrapper called ODE.NET, which can be found on the following website. There are several samples available and it is always nice to see some .NET code between all these physics engines, which are all just using C++ code and only give you C++ samples. The samples show basic physics problems like stacking boxes and pushing them over, and rag-doll physics and controlling some basic objects like cars or toys are also presented on ODE.NET at http://www.thejamesrainenetwork.co.uk/ode/ode.html.

You can also take a look at the official website of ODE. If it is down, check out the Wikipedia entry about the Open Dynamics Engine at http://www.ode.org/.

Other

There are many other physics engines available and I certainly do not know about all of them. Maybe there are even other useful engines that can be used in .NET, but I have not found any other wrappers that were as useful as ODE.NET yet.

Here are a couple of other physics engines I have encountered:

  • Newton Game Dynamics is a free physics engine with really nice samples and a good documentation. It can be used for hobby and commercial use and it supports the Windows, Mac, and Linux platforms.

    A free engine like this one is nice. I remember seeing a .NET wrapper for this engine somewhere a year ago, but the source code for the base engine is not available. This makes it very hard to implement it into .NET or to change anything if you want to improve the engine. ODE, on the other hand, is highly customizable to your every need. Check it out at http://www.newtondynamics.com/.

  • Tokamak Game Physics is another nice physics engine that is completely free to use for both non-commercial and commercial projects. It also has quite a few samples and tutorials, but again, there is no source code available for the core engine itself, just for the samples. Sadly this engine has not been updated for almost two years now and it seems that the developers do not care anymore; the forum is completely overrun by spam. The last news entry was March 2005. I implemented a simple .NET wrapper a few years back and played around with the engine a little bit, but I never found the time to get any further. Today I would probably just use one of the other available engines, especially ODE.NET since it already works with .NET. Visit http://www.tokamakphysics.com/.

  • Physics and Math Library (also called Game Physics Engine) is a German-based engine that was originally developed for a book. It focuses on implementing many of the available features of the commercial engines like Havok and PhysX. It is free to use, but I could not find many screenshots or forum discussions. It is hard to tell if an engine like this is really worth the effort you would probably put into it (making it run in your project and maybe even porting it to .NET), but the project looks pretty promising. The website is http://game-physics-engine.info/.

  • nV Physics Engine (also called The Physics Engine) has a nice website and some screenshots on it (which is always good for a website presenting a product). It looks promising but all samples are C++ again and you probably don’t even have access to the source code. The website is http://www.thephysicsengine.com/.

  • Bullet Physics Library is yet another free physics engine, this time hosted by sourceforge.net and it includes the full source code, which is nice. The author worked at Havok before and the engine is already used by several engines, especially open source engines and the 3D modeler tool Blender 3D. It also supports the latest file formats and has several advanced features already. The website is http://www.continuousphysics.com/Bullet/.

  • There are probably many more physics engines, especially smaller ones. Try to search for something specific when you encounter a certain problem and don’t really need a full-blown physics engine.

As you can see there are many physics engines available, but it is not easy to use them in .NET. This doesn’t have much to do with XNA; it is just annoying that you can’t use them on the Xbox 360 because all of them are developed in C++ and use unmanaged code, which means no-no for the Xbox 360 when using XNA.

But even if you don’t use a physics engine in the end, just by checking them out and playing around with the many available samples and tutorials you can get a clearer picture what is possible with a physics engine and which parts will probably be hard to re-implement if you do it yourself. You don’t really need a complex physics engine in the Racing Game. Well, it would be nice to have good solid foundation, but because implementing physics engines is so hard in .NET and because I want the game to run on the Xbox 360 too, you are back to doing it yourself again.




Professional XNA Game Programming
Professional XNA Programming: Building Games for Xbox 360 and Windows with XNA Game Studio 2.0
ISBN: 0470261285
EAN: 2147483647
Year: 2007
Pages: 138

Similar book on Amazon
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
XNA Game Studio 4.0 Programming: Developing for Windows Phone 7 and Xbox 360 (Developer's Library)
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Learning XNA 3.0: XNA 3.0 Game Development for the PC, Xbox 360, and Zune
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Beginning XNA 2.0 Game Programming: From Novice to Professional (Expert's Voice in Game Programming)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)
Microsoftu00ae XNAu00ae Game Studio 3.0: Learn Programming Now! (Pro - Developer)

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net