3 D Game Development Collision detection and rigid

  • Slides: 53
Download presentation
3 D Game Development Collision detection and rigid body dynamics Jernej Vičič

3 D Game Development Collision detection and rigid body dynamics Jernej Vičič

Overview (chapter in book: 12) do we realy need physics in games? middleware for

Overview (chapter in book: 12) do we realy need physics in games? middleware for physics/collision detection, collision detection system, the rigid body dynamics, integration of physics engine for in the game, linear dynamics of point masses; numerical integration; middleware for physics (collision/physics middleware): ODE, Phys. X. 2 3 D Game Development Jernej Vičič

Do we realy need physics in games? physics is great, some features are obligatory:

Do we realy need physics in games? physics is great, some features are obligatory: rag doll effect, it gives something more: clothes, hair in the wind, expensive: 3 keep it to a bare minimum (that is still OK!). 3 D Game Development Jernej Vičič

Do we realy need physics in games? what are we capable of presenting: Detect

Do we realy need physics in games? what are we capable of presenting: Detect collisions between dynamic objects and static world geometry. Simulate free rigid bodies under the influence of gravity and other forces. Spring-mass systems. Destructible buildings and structures. Ray and shape casts (to determine line of sight, bullet impacts, etc. ). Trigger volumes (determine when objects enter, leave or are inside redefined regions in the game world). Complex machines (cranes, moving platform puzzles and so on). Traps (such as an avalanche of boulders). Drivable vehicles with realistic suspensions. Rag doll character deaths. Powered rag doll: a realistic blend between traditional animation and rag doll physics. Dangling props (canteens, necklaces, swords), semi-realistic hair, clothing movements. Cloth simulations. Water surface simulations and buoyancy. 4 Audio propagation. 3 D Game Development Jernej Vičič

Do we realy need physics in games? Is physics fun? 5 not always, often

Do we realy need physics in games? Is physics fun? 5 not always, often a very precise simulation throws us away from the game. 3 D Game Development Jernej Vičič

Middleware for physics/collision detection we can write our engine, we use already prepared :

Middleware for physics/collision detection we can write our engine, we use already prepared : I-Collide, SWIFT, V-Collide, RAPID, University of North Carolina, I-Collide – opensource convex volumes, SWIFT – hitrejša različica, V-Collide – non-convex volumes, RAPID -||-, ODE – Open Dynamix Engine opensource rigid body dynamix SDK, Bullet opensource collision detection in physicy lybrary, Continious Collision Detection (CCD) 6 for small fast moving objects, True. Axis, 3 D Game Development Jernej Vičič

Middleware for physics/collision detection we can write our engine, we use already prepared: 7

Middleware for physics/collision detection we can write our engine, we use already prepared: 7 Phys. X NVIDIA, supports NVIDIA GPU, can be done on CPU, thus engine is used by Unreal engine (version 3. 3), Havok expensive, de-facto standard, PAL – Physics Abstraction Layer, opensource, can be connected to Phys. X, Digital Mollecular Matter (DMM), for simulations, for films. 3 D Game Development Jernej Vičič

System for collision detection determines whether objects are touching, each logical object is represented

System for collision detection determines whether objects are touching, each logical object is represented by one or more geometric shapes, prevents improper collisions (an object inside another object), moves them apart before rendering the new scene, spawns new events: the rocket explodes at the touch, user gets health-pack: change properties, rigid body dynamics. 8 3 D Game Development Jernej Vičič

System for collision detection collidable entities, collision representation: shape and position of the object

System for collision detection collidable entities, collision representation: shape and position of the object in the world, different from gameplay representation, different from visual representation, 9 role and behavior in the game, usually a triangle network, usually a geometric and mathematically simple form, a stone is represented as a sphere, the engine bonnet of a the car is a square, human body as several connected capsules, more demanding only if the game requires. 3 D Game Development Jernej Vičič

System for collision detection 10 3 D Game Development Jernej Vičič

System for collision detection 10 3 D Game Development Jernej Vičič

System for collision detection Phys. X: rigid object=actor, class Nx. Actor, shape – geometric

System for collision detection Phys. X: rigid object=actor, class Nx. Actor, shape – geometric form, transform – position and orientaion in the world. 11 3 D Game Development Jernej Vičič

System for collision detection physix world - class instance of Nx. Scene, collision world

System for collision detection physix world - class instance of Nx. Scene, collision world - data structure, all the information that the collision system needs separate from the game, 12 only collidables that can collide, the rest are ignored, the most appropriate data structure, cache coherency. 3 D Game Development Jernej Vičič

System for collision detection physix world, closelly connected to rigid body dynamics, same data,

System for collision detection physix world, closelly connected to rigid body dynamics, same data, every "rigid body" has its collidable, however, the rigid body dynamics is still separated from the collision system 13 so games that do not use physics can still calculate the collisions. 3 D Game Development Jernej Vičič

System for collision detection shape, shape = a region of space described by a

System for collision detection shape, shape = a region of space described by a boundary, with a definite inside and outside, 2 D: bounded by curve or broken straight line - polygon, 3 D: bounded by curved plains or a series of polygonpolyhedron, some objects are best presented with 2 D planes, 14 wall, landscape. 3 D Game Development Jernej Vičič

System for collision detection intersection, in geometrical terms, the intersection between two shapes is

System for collision detection intersection, in geometrical terms, the intersection between two shapes is just the (infinitely large!) set of all points that lie inside both shapes. contact, 15 we usually do not search for a cross section of points where the objects overlap, we are interested only if they overlap, the collision system usually stores all the necessary information into a data structure, Havok: hk. Contact. Point, separating vector - a vector that allows separation of objects, which collidables are touching, . . . 3 D Game Development Jernej Vičič

System for collision detection convexity, a convex shape is defined as the one for

System for collision detection convexity, a convex shape is defined as the one for which no ray originating inside the shape will pass through its surface more than once, easy computation of cross sections, collidables tend to have convexity property - convexity (true/false), 16 3 D Game Development Jernej Vičič

System for collision detection- primitives for collisions, represented by a 4 D vector: 3

System for collision detection- primitives for collisions, represented by a 4 D vector: 3 D point, radius, capsules, 17 capsule form - medicine, a cylinder and two halves of a sphere, suitable for "almost cylinders" – limbs. 3 D Game Development Jernej Vičič

System for collision detection - primitives Axis-Aligned Bounding Box (AABB) 3 D cuboid: 6

System for collision detection - primitives Axis-Aligned Bounding Box (AABB) 3 D cuboid: 6 rectangular plains, aligned with the coordinate system, mutually perpendicular, [ xmin; ymin; zmin; xmax; ymax; zmax ] easy to check if a point is inside the cuboid: 18 3 D Game Development Jernej Vičič

System for collision detection - primitives Axis-Aligned Bounding Box (AABB) 19 to quickly check

System for collision detection - primitives Axis-Aligned Bounding Box (AABB) 19 to quickly check for collisions, if the AABB objects do not collide, there is no need for more expensive checks. 3 D Game Development Jernej Vičič

System for collision detection - primitives Oriented Bounding Boxes (OBB), 3 D cuboid: 20

System for collision detection - primitives Oriented Bounding Boxes (OBB), 3 D cuboid: 20 the planes are aligned with the (local) coordinate system, convert the coordinates of a point into the local system to check if the point is in the cuboid to, then use the same method as for AABB. Razvoj iger, Jernej Vičič

System for collision detection - primitives frustum we present it with 6 planes (point,

System for collision detection - primitives frustum we present it with 6 planes (point, normal vector), represents the player's view, we are testing whether the point is in the region, convert the coordinates of the point s projection to into the perspective of the camera, 21 then the same as AABB. 3 D Game Development Jernej Vičič

System for collision detection - primitives Regions limited by convex polyhedra any number of

System for collision detection - primitives Regions limited by convex polyhedra any number of planes, test if a point in the region: useful for describing arbitrarily complex bodies, a lot of Engines use this. 22 3 D Game Development Jernej Vičič

System for collision detection - primitives Discrete Oriented Polytopes (DOP), convex polytop: the simplest

System for collision detection - primitives Discrete Oriented Polytopes (DOP), convex polytop: the simplest form of polytope is the polygon - 2 D, polyhedron- 3 D - is a polytope in three dimensions, - any number of planes, it can be assembled by taking some planes in infinity and bringing them closer to our object, AABB is a special case of DOP (6 -DOP): 23 normal planes are parallel to the axes of coordinate system. The simplest form of poliytope is the polygon, which is a polytope in two dimensions, a polyhedron is a polytope in 3 D. 3 D Game Development Jernej Vičič

System for collision detection - primitives any convex bodies, body is defined by the

System for collision detection - primitives any convex bodies, body is defined by the artist in Maya, constructed out of polygons, Maya ensures that polygons really form a convex polyhedron, lightly arranged as needed more expensive to test cross-section than other primitives. 24 3 D Game Development Jernej Vičič

System for collision detection - primitives Poly Soup, any non-convex bodies, consisting of simple

System for collision detection - primitives Poly Soup, any non-convex bodies, consisting of simple polygons, 25 expensive, used only for non-movig objects 3 D Game Development Jernej Vičič

System for collision detection - primitives Composite bodies, collection of shapes, bounding volume, Composite

System for collision detection - primitives Composite bodies, collection of shapes, bounding volume, Composite body, that surrounds the “real” body, used for first test. 26 3 D Game Development Jernej Vičič

Collision testing analytical geometry, point versus sphere, s=c-p, if |s|<=r, p is in the

Collision testing analytical geometry, point versus sphere, s=c-p, if |s|<=r, p is in the sphere, sphere vs. sphere, 27 s=c 1 -c 2, if |s|<=(r 1+r 2), spheres intersect, 3 D Game Development Jernej Vičič

Collision testing AABB proti AABB, 3 D, min and max coordinates of both AABB,

Collision testing AABB proti AABB, 3 D, min and max coordinates of both AABB, x: [x. Amin, x. Amax], [x. Bmin, x. Bmax], y, z similar, if intervals intersect ON ALL THREE AXES: 28 AABB intersect, otherwise not. 3 D Game Development Jernej Vičič

Collision testing GJK algoritem, for convex polytopes, https: //mollyrocket. com/849 29 3 D Game

Collision testing GJK algoritem, for convex polytopes, https: //mollyrocket. com/849 29 3 D Game Development Jernej Vičič

Collision testing Collides in moving bodies, possible solution: discreete timing steps: we regard collides

Collision testing Collides in moving bodies, possible solution: discreete timing steps: we regard collides as static, this does not work for fast objects (especially small ones), individual time intervals can cause holes for fast objects, 30 these holes may cause a non-intersection, swept shapes, Continuous Collision Detection (CCD). 3 D Game Development Jernej Vičič

Collision testing collision filtering, enable/disable certain collides, water, Collision Masking, 31 layers and a

Collision testing collision filtering, enable/disable certain collides, water, Collision Masking, 31 layers and a mask that determines whether the layers can collide with each other. 3 D Game Development Jernej Vičič

Rigid Body Dynamics The rigid body having a position and orientation Rigid bodies do

Rigid Body Dynamics The rigid body having a position and orientation Rigid bodies do not deform Moving a rigid body with only 2 parameters: - center of mass - orientation (rotation matrix) 3 D Game Development Jernej Vičič

Rigid Body Dynamics Objects are defined in the body space and transformed 3 D

Rigid Body Dynamics Objects are defined in the body space and transformed 3 D Game Development Jernej Vičič

Linear Velocity Change of the center of gravity in time For pure rotation moveing

Linear Velocity Change of the center of gravity in time For pure rotation moveing with velocity is constant, all points are 3 D Game Development Jernej Vičič

Angular velocity Change of orientation in time Encodes the axis and speed of rotation

Angular velocity Change of orientation in time Encodes the axis and speed of rotation § direction encodes the axis § magnitude encodes the velocity (rad/s) How are and related? 3 D Game Development Jernej Vičič

Angular velocity For a given vector Rows represent transformed axes 3 D Game Development

Angular velocity For a given vector Rows represent transformed axes 3 D Game Development Jernej Vičič

Angular velocity Vector product with matrix So: 3 D Game Development Jernej Vičič

Angular velocity Vector product with matrix So: 3 D Game Development Jernej Vičič

Point velocity Point in time can be represented: Cumulative velocity is sum of parts:

Point velocity Point in time can be represented: Cumulative velocity is sum of parts: Cleaned 3 D Game Development Jernej Vičič

Force The force affects any point on the object The total force is a

Force The force affects any point on the object The total force is a simple sum of all forces No information on which point is this force applied 3 D Game Development Jernej Vičič

Torque describes „rotational force“ Total torque on the object : Torque presents how the

Torque describes „rotational force“ Total torque on the object : Torque presents how the force is distributed over 3 D Game Development Jernej Vičič the object.

Movement equations for rigid body Previous equations combined: We discretize the continious equations and

Movement equations for rigid body Previous equations combined: We discretize the continious equations and integrate. 3 D Game Development Jernej Vičič

Using quaternions to represent orientaion: 3 D Game Development Jernej Vičič

Using quaternions to represent orientaion: 3 D Game Development Jernej Vičič

Collisions and touches So far, we have not taken into account the interaction between

Collisions and touches So far, we have not taken into account the interaction between rigid bodies Collision detection - determine if, when and where the collisions occur. Response to collision - calculate the state (speed, . . . ) after the collision. 3 D Game Development Jernej Vičič

Collisions and touches What should we do if a collision occurs? 3 D Game

Collisions and touches What should we do if a collision occurs? 3 D Game Development Jernej Vičič

Rollback the simulation Replay the simmulation at the collision. The collision time is determined

Rollback the simulation Replay the simmulation at the collision. The collision time is determined using bisection. 3 D Game Development Jernej Vičič

Collision detection Two convex objects do not overlap if and only if there is

Collision detection Two convex objects do not overlap if and only if there is a plane that divides them. separating plane First, find a plane that divides two objects and check if it is still valid at the next step. Accelerated with simplified objects that surround our main objects - bounding boxes, grids, hierarchies, …

Collision detection Conditions for the collision no collision the cross section is empty touch

Collision detection Conditions for the collision no collision the cross section is empty touch collision - the cross is not empty 3 D Game Development Jernej Vičič

Collision “Elastic” (non-rigid) body collision Force does not allow for two bodies to overlap

Collision “Elastic” (non-rigid) body collision Force does not allow for two bodies to overlap (cut, break) - interpenetration 3 D Game Development Jernej Vičič

Collision “Elastic” (non-rigid) body collision Force changes velocity. 3 D Game Development Jernej Vičič

Collision “Elastic” (non-rigid) body collision Force changes velocity. 3 D Game Development Jernej Vičič

Collision More rigid collisions Bigger force in a time-frame. 3 D Game Development Jernej

Collision More rigid collisions Bigger force in a time-frame. 3 D Game Development Jernej Vičič

Collision Rigid body collisions A short stroke of force results in a non-continious 3

Collision Rigid body collisions A short stroke of force results in a non-continious 3 D Game Development Jernej Vičič speed increase.

Existing touch The bodies do not collide, nor overlap. We want a force that

Existing touch The bodies do not collide, nor overlap. We want a force that is strong enough to withstand penetration, but not too strong to keep contact. 3 D Game Development Jernej Vičič

Simulation algorithm Algorithm with collides and touches currect state calculate new state detect collisions

Simulation algorithm Algorithm with collides and touches currect state calculate new state detect collisions and go back collision state calculate and take into account impulses state after collision calculate take into account bound. forces 3 D Game Development Jernej Vičič