利用者:Brita/GSoC BGE cleanup and support/doc/physics

提供: wiki
< 利用者:Brita‎ | GSoC BGE cleanup and support
2018年6月29日 (金) 06:09時点におけるYamyam (トーク | 投稿記録)による版 (1版 をインポートしました)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Physics

Note: Physics dev docs are part of my (already finished) gsoc. This page is yet incomplete because most of my notes are written on paper, I will copy them here slowly, as I am focusing on my thesis now -- Ines

Intro - this page is an overview of how physics engines work, then blender's implementation, and bullet documentation. The bullet documentation is official and updated, by Erwin Coumans.

Rigid Body

Concepts

Rigid Body - are solids with a constant shape "A rigid body is an idealized, infinitely hard, non-deformable solid object."

Dev-GE-physics-bullet-rigid body pipeline.png

An object, for the physics engine, has its own representation that is distinct from the one that the Game Engine itself needs for logic, animation and rendering. For a physics engine, an object is typically represented by a collision shape and a transform with orientation and position, but not scale or shear as it is a rigid body.

Rigid Body transforms

A Physics Engine or Physics SDK is typically composed of the following components:

  • collision detection -
  • dynamics simulation -
  • constraints solving -

The physics engine is not of mandatory usage in a game ¹ It can also be used just for the collision detection without the physics 'behavior'.

¹ BGE is using bullet for frustrum culling (at least) there is no way to run the GE without using bullet currently.

Collision

Each object is represented by one or more collision shapes. The internal representation of an object for Blender or the Game Engine is not the same as for the physics engine and not necessarily one to one. A complex object in Blender - non-convex and with independently moving parts - may be broken down into several objects with their own collision shape.

The physics engine job is to perform collision detection using those shapes by performing an intersection test between each pair. The test depends on the pair of shapes, standard examples include sphere-sphere, axis aligned bounding boxes (AABB) and casting a ray to a shape. The tests are basically math and their efficiency and speed varies.


'Collision Shapes'

Dev-GE-physics-sat.png

As for efficiency and speed, the shape should be well adjusted to the visual and logical representation of the object for it to work well, but non-convex triangle meshes should be avoided because of their expensiveness. An object like a character, can and should be broken down into capsules, but something like a terrain should use a polygon soup (triangle mesh). The main difference between these two use cases is that a character is dynamic (the polygons typically move in each frame) and a terrain is not, making it a lot more efficient.

The simplest test is using spheres (only test distance vs sum or radius) and the most efficient test is using AABB, because it uses an algorithm based on the Separating Axis Test (SAT) illustrated on the figure. The algorithm uses a number of axis corresponding to the dimensionality of the world (3 axis for 3D).

Dev-GE-physics-aabb obb.png

Common shapes are: sphere, capsule/swept sphere, oriented bounding box (OBB), axis aligned bounding box (AABB), k-DOP (discrete oriented polytype with k faces), cylinders, cones, pyramids.. and then triangle mesh/polygon soup.

Some physics engines (like Bullet) also provide optimized functionality to test a collision between a shape and a view frustum. This is what the Game Engine uses for culling.

'Physics World' + ghosts

Broadphase, mid phase and narrow phase

'Dynamic Intersection Testing'

  • Snapshots/discrete, Bullet through paper problem
  • Swept Volumes, CCd (continuous collision detection aka TOI - Time of Impact)

'Collision Casts'

'Collision Queries' The engine's collision system can be used to 'ask questions'

'Collision Filtering' masks and groups


References:

Dev-GE-physics-bullet-collision shapes.png

Dynamics

Dynamics is the system to determine the objects' movement and behavior in a physically realistic way.

The simulation typically uses classical, Newtonian mechanics, meaning that it takes in consideration all the forces being applied to an object over time and its mass to calculate the acceleration, and from that obtain the velocity and position of the object.

A rigid body can be translated and rotated on all 3 axes of the world independently - 6 degrees of freedom (6DOF). The movement is calculated in 2 separate steps for each axis and then layered:

  • linear dynamics - how the object's center of mass moves/translates in a step of time
  • angular dynamics - if a force is applied outside the center of mass, the object will spin/rotate

There are several ways of performing the calculations. Integrating the acceleration in order to obtain the position is done via numerical integration using methods that vary in their accuracy, stability and performance.

An alternative to finding the net force and from there the acceleration, velocity and position is to use impulses instead of forces (an impulse is the action of a force over a time interval). From the net impulse, the velocity and then the position are obtained without the need to use the acceleration. Impulses are particularly useful when calculating the effects of collisions.

    • references


The dynamics simulation is tightly integrated with the collision detection system inferring constraints and forces (or impulses) from the objects being simulated, such as contact constraints, frictions, bounces, etc.

Collision Response

<- I have it written on a paper, will copy here soon -> Dev-GE-physics-contacts.png

Constraints

Bullet

Dev-GE-physics-bullet-architecture.png

The official documentation for Bullet v2.82 (currently used version) ファイル:Dev-Physics-bullet-documentation.pdf

Notes on the development of Bullet 3.x are here -> http://www.multithreadingandvfx.org/course_notes/GPU_rigidbody_using_OpenCL.pdf

Other Physics Engines

  • I-Collide, SWIFT, V-Collide, and RAPID
  • ODE
  • Bullet
  • TrueAxis
  • PhysX
  • Havok
  • IBDS
  • PAL, no updates since 1y ago?

Blender Implementation

  • how it connects with physics and the main loop (+other transform affecting systems)
  • common/dummy/bullet
  • bullet