Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a physics engine actually simulate physics? [closed]

This question may be a stupid question, but I'm really curious.

After playing games like HL2, GMod, or Angry Bird, and using physics libraries like Box2D, I began to wonder "how a physics engine simulates physics?"

Like lexer and parser are used to understand the code when compiling and ray-tracing is used to render a 3D scene, I think that there's some notions (other than collision detection) which are used in the physics engine to simulate physics, like calculating torque and velocity of a pentagon performing barrel roll.

How does a physics engine actually simulate physics? What notions are used? Is there any 'tutorial' on the web about making physics engine like this one, which demonstrates ray tracing?

like image 899
JiminP Avatar asked Jun 10 '11 02:06

JiminP


People also ask

How do game engines simulate physics?

It starts off by simulating an external force such as gravity. At each new time step, it detects any collisions, then calculates the velocity and position of an object. And finally, sends the location data to the GPU. This continuous loop creates the illusion that an object is falling due to gravity.

How does physics simulation work?

A physics simulation starts with a mathematical model whose variables define the state of the system at a given time. Each variable represents the position or velocity of some part of the system. The heart of a physics simulation is the set of differential equations that describe how the variables evolve over time.

How do game engines detect collisions?

Collision Detection works by detecting if two bounding volumes are penetrating each other. Each character in a game is wrap with a bounding volume. There are different types of bounding volumes, such as spheres, Axis-Aligned Bounding Boxes (AABB), Oriented Bounding Boxes (OBB), Convex-Hull Bounding volume, etc.

What does a physics engine do?

A physics engine is computer software that provides an approximate simulation of certain physical systems, such as rigid body dynamics (including collision detection), soft body dynamics, and fluid dynamics, of use in the domains of computer graphics, video games and film (CGI).


1 Answers

Creating a (robust) physics engine is a lot more complicated then it may seem at first. The trick is to fake as much as possible rather than calculate the exact values. As a starting point, this blog post has a great introduction. I think this paper by Thomas Jakobsen is also a good read and introduces certain concepts. This blog also has a few interesting articles explaining the details of integrators and how to manage physics for online games.

Going through the source code of physics engines such as Box2D is a good idea to see implementation, but if you don't know the theory of what they're doing, it can come across as confusing. The reason for this is because of the fact that the theory is often too inefficient to implement in a real time game and so algorithms and techniques are used to strike a balance between realism and speed.

If you're creating your own physics engine because you want to use it in a commercial game, I'd suggest choosing an already existing solution instead. (For example, Angry Birds uses Box2D). However, if you're doing it for the experience and for learning about physics engines, it's certainly something that'll teach you quite a bit about efficiency and smart techniques.

like image 88
keyboardP Avatar answered Sep 29 '22 19:09

keyboardP