3.4. c ontact g eneration generating contacts between rigid bodies

32
3.4. CONTACT GENERATION Generating contacts between rigid bodies

Upload: ellen-powell

Post on 16-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

3.4. CONTACT GENERATIONGenerating contacts between rigid bodies

Page 2: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

CONTACT GENERATIONGenerating contacts between rigid bodies

Page 3: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Introduction to contact generation A collision detection system may simply return the single point of maximum interpenetration if two objects are found to be in contact.

Unfortunately, this does not provide adequate information to implement a realistic physics simulation, i.e. a collision between two objects may involve multiple points of contact (e.g. a car object resting on a surface).

As such, the process of contact generation should produce a set of points of contact for each interpenetrating object pairing.

Page 4: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Introduction to contact generation

One box resting on top of another box will have a region (or patch) in direct contact. The contact patch can be of any shape (depending on the geometry of the touching objects). In order to simplify the process, a contact patch is typically simplified to a representative contact point or set of contact points.

As such, a means of modelling a contact patch using a set of contact points is needed. The next slide shows one means of accomplishing this mapping (producing reasonable physical behaviour in most situations).

●Single contact

Collision detection

●Contact pair

Contact generation

Page 5: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Common types of contact

Point-face contact

Edge-edge contact

Face-face contacts

Face-face collisions are needed when one or both contact faces are curved, otherwise, flat face-face contacts can be modelling using edge–edge and edge–face contacts.

In most cases, the following collision detection algorithms will try to model a contact using either point-face or edge-edge contacts (primitives with curved surfaces will use some of the other cases).

Page 6: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Common types of contact

Point-point contact

Edge–face contacts can often be replaced by a pair of edge–point contacts (except when the face is curved).

Edge-face contact Point-edge

contact

Point–point contacts and point–edge contacts can be effectively ignored as they are unlikely to occur and can be handled as a point-face contact.

Page 7: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Contact data

Assuming the types of contact identified above, the following properties can be defined permitting the contact to be described:

Penetration depth

●Contact point

Contact normal

• Colllision point – the representative point of contact (given interpenetrate any number of points might be selected – some arbitrary means of selecting a point is adopted, e.g. mid penetration point)

• Collision normal - direction in which an impact impulse will be applied between the two objects. By convention, the contact normal points from the first object involved toward the second.

• Penetration depth - amount that the two objects are interpenetrating measured along the direction of the collision normal passing through the collision point

Page 8: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Contact data: Point-Face Contacts

Point–face contacts are the most common and important type of contact.

1.The contact normal is given by the normal of the surface at the point of contact.

2.The contact point is given as the point involved in the contact (if interpenetrating, the midway point between the object’s point and projected face point could be used)

3.The penetration depth is calculated as the distance between the object point and the projected point.

Penetration depth ●

Contact point

Contact normal

Page 9: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Contact data: Edge-Edge Contacts

Edge–edge contacts are the second most important type of contact and are used to model resting contacts between objects with flat or concave sides

1.The contact normal is at right angles to the tangents of both edges (built using a cross product)

2.The contact point is typically the closest point on one edge to the other (a point midway between both edges could also be used)

3.The penetration depth is the distance between the two edges.

Penetration

depth

●Contact point

Contact normal

Page 10: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Contact data: Edge-Face Contacts

Edge–face contacts are only used with curved surfaces (although the contact data is generated in a very similar way to point–face contacts)

1.The contact normal is given by the normal of the face (the edge direction is ignored)

2.The contact point is calculated as the point of deepest penetration geometrically.

3. The penetration depth is the distance between the edge and the face along the direction of the normal passing through the contact point.

Penetration depth ●Contact point

Contact normal

Page 11: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Contact data: Face-Face Contacts1.The contact normal is given by the normal of the first face.

2.The contact point is calculated as the point of deepest penetration geometrically. If a point of deepest penetration cannot be readily obtained (e.g. two interpenetrating flat surfaces), an arbitrary point is selected.

3.The penetration depth is the maximum distance between the two faces involved within the contact.

Penetr

ation

depth

●Contact point

Contact normal

Face–face contacts occur when a curved surface comes in contact with another face (either curved or flat). In this case, the contact data is more arbitrarily selected.

Page 12: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Coherence and Contact Generation

The most efficient algorithms for calculating collision information between a pair of convex objects will typically terminate whenever the point of deepest interpenetration is found, i.e. a single contact is provided.

Generating a complete set of contacts is considerably more difficult as a contact can be interpreted in different ways (e.g. a point-face contact could be interpreted as another point–face contact for a different face, with a different penetration depth). To generate a complete set of contacts, a means of interpretating and integrating points of contact is needed.

Page 13: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Coherence and Contact Generation

The problem of contact set generation can be (somewhat) avoided by introducing a degree of frame coherence and then simply generating a single contact (of maximum penetration), e.g.: consider two stacked boxes

Frame 1: A single contact is generated and resolved in the normal manner.

Frame 2: As only one point of contact was resolved, the boxes will likely re-interpenetrate but probably in a different way. This is detected as a new contact, providing two contacts which are resolved.

●Frame 1: First contact

Frame 3: A third point of contact is generated. We have three contacts which is sufficient to keep the boxes stacked in a stable manner.

●Frame 2: Second contact

Page 14: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Coherence and Contact GenerationTo take advantage of the coherence, we store the type of contact (e.g. point–edge or edge–edge) and which feature was involved for each object.

If in the next frame, the same type of contact is generated (but with updated contact properties) that the stored contact can be updated.

Aside: Typically a

small negative value

is used for the

interpenetration

distance, i.e. contacts

that have only just

separated are still

maintained in the

cache).

If a new type of contact has been detected, then it is added to the set of cached contacts.

Contacts are removed from the set of cached contacts if the interpenetration depth is less than some fixed value (i.e. the contact has moved sufficient apart).

Page 15: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

PRIMITIVE CONTACT GENERATION ALGORITHMSGenerating contacts between rigid bodies

Page 16: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Primitive Contact Generation Algorithms

A contact generation algorithm generates contact information between pairs of potentially colliding primitives, returning zero, one or more contacts.

Iterated over a set primitive pairings (e.g. as returned from some form of collision broad pass algorithm) a pool of contacts will be generated which can then be passed to the physics engine to be resolved.

See the recommended course text book for details of contact generation given

•sphere-sphere, and

•sphere-plane primitives.

Page 17: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Plane Contact GenerationThis algorithm can return more than one contact.

Only point-face contacts will be returned, i.e. rather than return a face-face contact, up to four point-face contacts will be returned (one for each corner point in contact with the plane/half-space). Likewise, an edge-face contact will be returned using two point-face contacts.

● ●

● ●

Page 18: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Plane Contact Generation

Contacts are generated by checking for interpenetration of each box vertex against the plane, i.e. the vertex is in contact if (where p is the vertex location, n the plane normal and d the plane distance)

foreach( Point p : box.Vertices ) { float d = dot( p, plane.n ); if( d < plane.d + ε ) {

contact.Point = p + plane.n * (d - plane.d);

contact.Normal = plane.n; contact.Penetration = plane.d – d; }}

Determine the vertex-plane distance

An epsilon value might be introduced to cover resting contacts

Generate contact information, assuming the contact point is midway between the vertex and plane.

Page 19: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Sphere-Box Contact GenerationA sphere-box collision will result in a single contact, although the contact type can differ (face-face, edge-face, or point-face).

All three types of contact can be tested/constructed using the same approach (assuming that the collision normal is from the perspective of the sphere), as follows:

1.Find the closest point on the box (OBB) to the centre of the sphere (as outlined within an earlier lecture). The closest point may be in a box corner, edge or face.

2.If the closest box point to sphere centre distance is less than the sphere radius then generate contact information.

Page 20: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contact Generation

Generating box-to-box contacts is notably more complex than the previous generation algorithms; however, the technique employed behind box-to-box contact generation is similar to that for any pair of concave shapes.

Page 21: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Type of Box-Box Contacts

There are six possible types of contact between two boxes

Point-face contact

Edge-edge contact

Face-face contact

Edge-face contact

Point-point contact

Point-edge contact

Page 22: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Type of Box-Box Contacts: SimplificationFace-face and edge-face contacts can be represented using a number of point-face or edge-edge contacts.

Face-face contact

●● ●●

Edge-face contact

● ●

Aside: Modelling a face-face (or edge-face) contact using a single contact (assuming the definition above) will likely not be stable. Multiple contacts, whilst increasing computation, also increase stability.

The point–point and point–edge contacts do not have any obvious means of determining a contact normal, additionally these forms of contact are very unlikely to occur. As such, they can be safely ignored (and will result in a point-face or edge-face contact).

Page 23: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contact Generation

In order to generate contacts between two boxes the following steps are used:

1. Use a separating axis test along each possible separating axis as a means of providing an early out for non-collision or to determine the axis of greatest interpenetration.

2. Generate a contact for the point of greatest interpenetration.

3. Use the notion of contact coherence, to combine the contact with previously detected contacts to update/extend the set of box-box contacts.

Page 24: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contacts: Separating axesThe separating axis test can be performed for two boxes by projecting the half-size of the box onto the separating axis, i.e.:bool FindPenetrationOnAxis ( Box one, Box two, Vector3 axis ) {

float oneProj = TransformToAxis(one, axis); float twoProj = TransformToAxis(two, axis);

Vector3 centre = two.Centre - one.Centre; float distance = Math.Abs( Dot( center, axis) );

return (distance < oneProj + twoProj);}

Project the half-size of each box onto the axis

Determine the midpoint between the boxes and project this onto the axis

Return true if the projected half-widths overlap

●●

float TransformToAxis(Box box, Vector3 axis) { return box.HalfSizeX * Math.Abs( Dot( axis, box.AxisX ) ) + box.HalfSizeY * Math.Abs( Dot( axis, box.AxisY ) ) + box.HalfSizeZ * Math.Abs( Dot( axis, box.AxisZ ) );}

Return the accumulated projection of each box axis onto the separating axis

Page 25: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contacts: Separating axes testA total of 15 different axes must be tested (to confirm interpenetration), these include:

• The three principal axes of each box

• The nine axes which are perpendicular to each pair of principal axes from each box

Aside: The nine perpendicular axis are formed by taking the cross product of each pairing of principle axes

Page 26: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contacts: Building a contactOnce the point of deepest interpenetration has been found it is necessary to interpret this point in terms of a particular type of contact.

Aside: A range of more efficient and more complex algorithms exist for general polyhedral (such as GJK or V-Clip) – see directed

reading.

This is a complex problem to solve for general polyhedral. A workable approach for box-to-box contacts is to simply (and exhaustively) check for each possible type of point-face and edge-edge contact.

If the point of deepest interpenetration is:

•Along one of the principles axis of a box, then it is a point-face contact,

•Along a perpendicular axis, then it is an edge-edge contact

As only a single contact is returned, if more than one contact is found within the search, then the contact that has the greatest interpenetration is returned.

Page 27: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contacts: Point-Face A point-face contact uses the same approach as for a sphere-box collision (but assuming a zero-radius sphere).

Each vertex from one box is projected onto the principal axes of the other. If the vertex is inside the box, then a point–face collision is required. If the vertex is inside the box on more than one axis, then the axis with the shallowest penetration is used.

Page 28: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contacts: Point-Face Vector3 relPoint = box.TransformToLocal(point);Vector3 normal;

float minDepth = box.HalfSizeX – Math.Abs(relPoint.X);if (min_depth < 0) return;normal = box.AxisX * ((relPoint.x < 0)?-1:1);

float depth = box.HalfSizeY – Math.Abs(relPoint.Y);if (depth < 0) return;else if (depth < min_depth) { min_depth = depth; normal = box.AxisY * ((relPoint.Y < 0)?-1:1);}

depth = box.HalfSizeZ – Math.Abs(relPoint.Z);if (depth < 0) return 0;else if (depth < min_depth) { min_depth = depth; normal = box. AxisZ * ((relPoint.Z < 0)?-1:1);}

Determine the axis of least (positive) penetration

Ensure the point is expressed in the box’s local space

The collision normal will be constructed to be stored within the contact

Build the contact using the determined point, normal and interpenetration depth

Page 29: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Box-Box Contacts: Edge-Edge

Each edge from one object is checked against the edges of the other object. This is accomplished by:

1.Consider each edge of object A.

2.Work out its interpenetration with each edge of object B.

3.The shallowest interpenetration of an edge from A is the interpenetration of the edge.

4.The edge from object A with the deepest interpenetration is retained.

Page 30: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

DIRECTED READINGDirected physics reading

Directed

reading

Page 31: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Directed reading Directed

reading

• Read Chapter 13 of Game Physics Engine Development (pp263-297) on rotations.

• Read Chapter 9 of Real Time Collision Detection (pp383-412) on convexity based methods of intersection.

Page 32: 3.4. C ONTACT G ENERATION Generating contacts between rigid bodies

Summary

To do:Read the directed

reading.

Consider if you might

wish to develop your

own physics engine as

your project.

Today we explored:

How to model different forms of contact

Means of generating contacts between rigid body primitives