A program should take input, process it and give output. So what exactly does a physics engine take as input and provide as output?
|
|
A physics engine is responsible for simulating the motions and reaction of objects as if they were under the constraints of real-world (or similar to real-world physics). It is, I should note, not usually a standalone program but rather a component of a larger more interesting program (such as a game). The input to a physics simulation is generally a collection of objects ("bodies") with properties (such as whether or not they are rigid or soft, their masses, shapes, and so on) as well as the collection of forces acting on those bodies. Based on that input, the engine simulates updated positions and orientations of the bodies and applies ("outputs") them. Generally when objects collide or overlap, that is included in the output of a simulation step in the form of a callback that client code can hook to handle the specific gameplay logic relevant to the collision. |
||||
|
|
|
The input it speed, mass, and time, the output is new speeds. Sometimes rotation/angular momentum is an input and output too. Essentially Physics engines try to simulate the effects of both gravity and collisions. For better physics engines that means they include both permanent and temporary deformation of objects, including splitting objects into multiple objects, and angular momentum of objects. Ideally they'd also simulate stress, e.g. how many trucks can cross that bridge until it collapses, but that's quite rare. Further simulation variables like air resistance would also count as physics engine, but as far as I know these haven't made it into any game yet. Most physics engines are specialized to some degree and will simulate physics to a point that's necessary for the game. Physics engines for car games are often quite different from physics engines for 3D shooters. And the physics engine of a golf game might have excessive calculations of the interactions of the golf ball and the individual grass leaves, while completely missing the handling of high speed collisions and deformation of a car (in case it get's hit by a golf ball). |
|||
|
|
|
Typically a physics engine is used to make object in a game in a realistic manner relative to their environment without having to design specific animations for every possible scenario. Specifically a physics engine will take a model with a set of properties (mass, joints etc) and render it in-game according to a set of parameters. An early example of this were raggdoll engines (eg in Unreal) which modelled the way that limp bodies would fall down steps etc. In current technology physics engines will often be closely integrated in an overall game deign package along with AI, in-game UI, cutscene generation etc. You could certainly argue that physics engines go back to the dawn of games design eg pong could be considered a crude physics engine. However the main point is that a physics engine is capable of generating animation points on the fly based on a set of parameters rather than just using predetermined animation sequences from motion capture or manual animation. AS mentioned in other answers, in some classes or game like driving or flight simulation the physics engine may be fundamental to the game play and as such will be the main input driving the on-screen animation. |
|||
|
|