1 / 116

Interaction and Normals

Interaction and Normals. Intro to Programming in 3D Applications Lecture 20. Collision handling detection & response. Particle-plane collision detection Polyhedron-polyhedron collision detection overlap of Bounding volumes Vertex inside polyhedron test Concave case Convex case

ikia
Download Presentation

Interaction and Normals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Interaction and Normals Intro to Programming in 3D Applications Lecture 20

  2. Collision handling detection & response Particle-plane collision detection Polyhedron-polyhedron collision detection overlap of Bounding volumes Vertex inside polyhedron test Concave case Convex case Edge-face intersection test detection kinematic response Penalty method Impulse force of collision response

  3. Collision Detection • One part of the physics generally necessary in today’s game environments • Basics • Ray-Polygon Intersection • Object motion vector is the ray • Wall or other object is the polygon(s) • Simple to implement • Polygon-Polygon Intersection • Can be expensive to calculate • Separate from Collision Response

  4. Ray Basics • Segment-Plane Intersection • Intersect movement segment with plane of polygon • Segment is defined by start and end points • Intersection Point • Find the exact 3D location of the intersection • Point in Polygon Check • Easy for simple polygons • Calculate dot product of edge normals to vector • Fast, Minimum Storage Ray-Triangle Intersection (best) • http://www.acm.org/jgt/papers/MollerTrumbore97/ • More difficult for concave polygons • Sum angles between vectors to vertices • Divide polygon into quadrants, sum edge crossings • Scanline +/- • If the point is in the polygon the movement vector went through the surface and we have a collision

  5. Collision detection: point-plane N

  6. Collision detection: time of impact 2 options Consider collision at next time step Compute fractional time at which collision actually occurred Tradeoff: accuracy v. complexity

  7. Intersection Testing • General goals: given two objects with current and previous orientations specified, determine if, where, and when the two objects intersect • Alternative: given two objects with only current orientations, determine if they intersect • Sometimes, we need to find all intersections. Other times, we just want the first one. Sometimes, we just need to know if the two objects intersect and don’t need the actual intersection data.

  8. Primitives • We often deal with various different ‘primitives’ that we describe our geometry with. Objects are constructed from these primitives • Examples • Triangles • Spheres • Cylinders • AABB = axis aligned bounding box • OBB = oriented bounding box • At the heart of the intersection testing are various primitive-primitive tests

  9. Particle Collisions • mainly be concerned with the problem of testing if particles collide with solid objects • A particle can be treated as a line segment from it’s previous position to it’s current position • If we are colliding against static objects, then we just need to test if the line segment intersects the object • Colliding against moving objects requires some additional modifications that we will also look at

  10. Segment vs. Triangle • Does segment ab intersect triangle v0v1v2 ? •

  11. Segment vs. Triangle • First, compute signed distances of a and b to plane • Reject if both are above or both are below triangle • Otherwise, find intersection point x •

  12. Segment vs. Triangle • Is point x inside the triangle? (x-v0)·((v2-v0)×n) > 0 • Test all 3 edges v2 v2-v0 x-v0 x • v0 v1 (v2-v0)×n

  13. Faster Way • Reduce to 2D: remove smallest dimension • Compute barycentric coordinates x' =x-v0 e1=v1-v0 e2=v2-v0 α=(x'×e2)/(e1×e2) β=(x'×e1)/(e1×e2) • Reject if α<0, β<0 or α+β >1 v2 β x v0 α v1

  14. Segment vs. Mesh • To test a line segment against a mesh of triangles, simply test the segment against each triangle • Sometimes, we are interested in only the ‘first’ hit along the segment from a to b. Other times, we want all intersections. Still other times, we just need any intersection. • Testing against lots of triangles in a large mesh can be time consuming. We will look at ways to optimize this later

  15. Segment vs. Moving Mesh • M0 is the object’s matrix at time t0 • M1 is the matrix at time t1 • Compute delta matrix: M1=M0·MΔ MΔ=M0-1·M1 • Transform a by MΔ a'=a·MΔ • Test segment a'b against object with matrix M1

  16. Triangle vs. Triangle • Given two triangles: T1 (u0u1u2) and T2 (v0v1v2) v2 u2 v0 T2 T1 u0 v1 u1

  17. Triangle vs. Triangle Step 1: Compute plane equations n2=(v1-v0)×(v2-v0) d2=-n2·v0 v2 v2-v0 n v1 v1-v0 v0

  18. Triangle vs. Triangle • Step 2: Compute signed distances of T1 vertices to plane of T2: di=n2·ui+d2 (i=0,1,2) • Reject if all di<0 or all di>0 • Repeat for vertices of T2 against plane of T1 u0 d0

  19. Triangle vs. Triangle • Step 3: Find intersection points • Step 4: Determine if segment pq is inside triangle or intersects triangle edge q p

  20. Mesh vs. Mesh • Geometry: points, edges, faces • Collisions: p2p, p2e, p2f, e2e, e2f, f2f • Relevant ones: p2f, e2e (point to face & edge to edge) • Multiple simultaneous collisions

  21. Sphere-Sphere Intersection • Two objects are said to have collided if their bounding spheres intersect. • To determine if two spheres intersect, simply calculate the distance between the centers of the two spheres. • If the distance is greater than the sum of the two sphere radii, they don’t intersect. Otherwise they intersect. r2 r1 d = r1 + r2 d > r1 + r2

  22. Sphere-Plane Intersection • Sometimes, it’s necessary to find the intersection between a sphere and a plane, for example, the bounding sphere of an object with a wall (or slope). • Given that the equation of the plane is n.p = k (where n is the unit normal of the plane, p is any point on the plane, and k is a number) • Then, given the center coordinates C of the sphere, and the radius r of the sphere, • The sphere and the plane intersect if |(n.C) – k| < r

  23. Dot Product • Let U and V be vectors such that U = (Ux, Uy, Uz), and V = (Vx, Vy, Vz) • Then, the dot product U.V = UxVx + UyVy + UzVz • U.V is also equal to |U||V| cos q where q is the angle between U and V. U V q

  24. Collision of Fast-Moving Objects • We need a different method to detect collision of fast-moving, and often small, objects. • Example, a bullet is fired, and we want to see if it intersects a wall. However, if we examine every time frame, because the bullet moves very fast, even though at some point in time it intersects the wall, we may only sample it in front of the wall and behind it, but on at the point of intersection. • Therefore, we need to consider the path of the bullet, and determine if that path intersects the wall. • We use a line to represent the path of the bullet. We then test for line-object intersection. We consider: • Line-Sphere intersection, and • Line-Triangle intersection

  25. Line-Sphere Intersection • Let a point on a line be X(t) = P + tD • Here X(t) is a function of t, and gives the point on the line, P is the starting point of the line, and D is a unit vector in the direction of the line. • Let a point on a sphere satisfy | X – C | = r • Here, X is a point on the sphere, C is the center of the sphere, and r is the radius of the sphere.

  26. Line-Sphere Intersection • Suppose the line and sphere intersect at point X, then | P + tD – C |2 – r2 = 0 • Let M = P – C. Then, | tD + M |2 – r2 = 0 • Expanding, t2 + 2D.Mt + | M |2 – r2 = 0 • See Note 1 on next page • Solving for t, t = -D.M +/- sqrt((D.M)2 – ( | M |2 – r2 )) • See Note 2 on next page • The discriminant d is (D.M)2 – ( | M |2 – r2 ) • If d > 0, the line and sphere intersect at two points. • If d = 0, the line and sphere intersect at one point. • If d < 0, the line and sphere don’t intersect. • If (d>0) or (d=0), we can solve for t. Assuming that P is the position of the fast-moving object at the beginning of the game loop, and D is the vector that it will travel during a game loop, then the objects intersect during this game loop if 0<t<1.

  27. Notes on Line-Sphere Intersection Note 1 Note 2 |a+b|2 = |a|2 + |b|2 + 2a.b Let A, B and C be coefficients of the quadratic equation: Ax2 + Bx + C = 0 Then, x = -B +/- sqrt(B2-4AC) 2A b by a+b ay a ax bx Proof: |a+b|2 = (ax+bx)2 + (ay+by)2 = ax2+ 2axbx + bx2 + ay2+ 2ayby + by2 But, |a|2 = ax2 + ay2 and |b|2 = bx2 + by2 Therefore, |a+b|2 = |a|2 + |b|2 + 2(axbx + ayby) |a+b|2 = |a|2 + |b|2 + 2a.b

  28. Line-Triangle Intersection • Once again, let a point on a line be X(t) = P + tD • Let a triangle be defined by its three corner points P0, P1 and P2. • Strategy: • First, find the intersection between the line and the plane containing the triangle. • Then, find out if this point is within the triangle

  29. Line-Triangle IntersectionThe Plane Containing the Triangle Equation of a plane: A point p on the plane will satisfy the equation p.n = k where n is the normal of the plane. Step 1: Find the normal n of the plane Let edge e0 be P1 – P0. Let edge e1 be P2 – P1. Then n = e0 x e1 In other words, the normal of the plane is the cross product of two edges. Step 2: Find k k = P0.n

  30. Line-Triangle IntersectionLine-Plane Intersection 1. Substitute equation of the line into equation of the plane. (P + tD) . n = k 2. Find t. Re-arranging, t = (k – P.n)/(D.n) 3. Substitute t back to get intersection point. Intersection point R = P + tD.

  31. Line-Triangle IntersectionCheck if point is within triangle Remember that the cross product of consecutive vectors going counter-clockwise will always be of the same sign. R is inside the triangle if it is always to the left side of each edge. P2 e1 e2 R P0 e0 P1 Therefore, Point R is inside the triangle if: (e0 x (R – P0)) . n > 0 and (e1 x (R – P1)) . n > 0 and (e2 x (R – P2)) . n > 0

  32. Speeding up Collision Detection • Spatial subdivision method • Divide the space into different regions. • At each step, determine which region each object is in. • Only test objects in the same region for collision.

  33. Collision detection: polyhedra Order tests according to computational complexity and power of detection 1. test bounding volumes for overlap 2. test for vertex of one object inside of other object 3. test for edge of one object intersecting face of other object

  34. Collision detection: bounding volumes Don’t do vertex/edge intersection testing if there’s no chance of an intersection between the polyhedra Want a simple test to remove easy cases Tradeoff complexity of test with power to reject non-intersecting polyhedra (goodness of fit of bounding volume)

  35. Bounding Spheres Compute bounding sphere of vertices Compute in object space and transform with object • Find min/max pair of points in each dimension • use maximally separated pair – use to create initial bounding sphere (midpoint is center) • for each vertex adjust sphere to include point

  36. Bounding Boxes Axis-aligned (AABB): use min/max in each dimension Oriented (OBB): e.g., use AABB in object space and transform with object. Vertex is inside of OBB if on inside of 6 planar equations

  37. Bounding Slabs For better fit bounding polyhedron: use arbitrary (user-specified) collection of bounding plane-pairs Is a vertex between each pair?

  38. Convex Hull Best fit convex polyhedron to concave polyhedron but takes some (one-time) computation • Find highest vertex, V1 • Find remaining vertex that minimizes angle with horizontal plane through point. Call edge L • Form plane with this edge and horizontal line perpendicular to L at V1 • Find remaining vertex that for triangle that minimizes angle with this plane. Add this triangle to convex hull, mark edges as unmatched • For each unmatched edge, find remaining vertex that minimizes angle with the plane of the edge’s triangle

  39. Collision detection: polyhedra 1. test bounding volumes for overlap 2. test for vertex of one object inside of other object 3. test for edge of one object intersecting face of other object

  40. Collision detection: polyhedra Intersection = NO For each vertex, V, of object A if (V is inside of B) intersection = YES For each vertex, V, of object B if (V is inside of A) intersection = YES A vertex is inside a convex polyhedron if it’s on the ‘inside’ side of all faces A vertex is inside a cancave polyhedron if a semi-infinite ray from the vertex intersects an odd number of faces

  41. Collision detection: polyhedra Edge intersection face test Finds ALL polyhedral intersections But is most expensive test If vertices of edges are on opposite side of plane of face Calculate intersection of edge with plane Test vertex for inside face (2D test in plane of face)

  42. Collision detection: swept volume Time & relative direction of travel sweeps out a volume Only tractable in simple cases (e.g. linear translation) If part of an object is in the volume, it was intersected by object

  43. Laws of Motion • First law simplified into the sentence "A body continues to maintain its state of rest or of uniform motion unless acted upon by an external unbalanced force." This law is known as the law of inertia. • Second law is often stated as "F = ma: the net force on an object is equal to the mass of the object multiplied by its acceleration." • Third law Whenever a particle A exerts a force on another particle B, B simultaneously exerts a force on A with the same magnitude in the opposite direction. This law is often simplified as "To every action there is an equal and opposite reaction."

  44. Linear Momentum and Collisions Linear momentumis defined as: p = mv Momentum is given by mass times velocity. Momentum is a vector. The units of momentum are (no special unit): [p] = kg·m/s

  45. Sincepis a vector, we can also considerthecomponents of momentum: px = mvx py = mvy pz = mvz Note: momentum is “large” if m and/or v is large. (define large, meaning hard for you to stop). • Name an object with large momentum but small velocity. • Name an object with large momentum but small mass

  46. Recall that Another way of writing Newton’s Second Law is F = Dp/Dt= rate of change of momentum This form is valid even if the mass is changing. This form is valid even in Relativity and Quantum Mechanics.

  47. Impulse We can rewrite F = Dp/Dt as: FDt = Dp I = FDtis known as the impulse. The impulse of the force acting on an object equals the change in the momentum of that object.

  48. If there are no external forces on a system, then the total momentum of that system is constant. This is known as: The Principle of Conservation of Momentum In that case, pi = pf.

  49. Conservation of Momentum • In the absence of external forces, the total momentum of a given system remains constant. A 90 kg hockey player traveling with a velocity of 6 m/s collides head-on with an 80 kg player traveling a 7 m/s. If the two players entangle and continue traveling together as a unit following the collision, what is their combined velocity? Known: m1= 90 kg m2=80 kg v1= 6 m/s v2= -7 m/s m1v1 + m2v2 = (m1 + m2) (v) (90 kg) (6 m/s) + (80 kg) (-7 m/s) = (90 kg + 80 kg) (v) 540 kg m/s – 560 kg m/s = (170 kg) (v) - 20 kg m/s = (170 kg) (v) v = 0.12 m/s in the direction of the 80 kg player’s original direction of travel

  50. Conservation of Momentum and Newton’s Third Law • Consider a system consisting of just the two masses m1 and m2. • Mass m1 exerts a force F21 on mass m2. • Mass m2 exerts a force F12 on mass m1. • Force on m1 = rate of change of momentum of m1 • F12 =Dp1 / Dt • Force on m2 = rate of change of momentum of m2 • F21 =Dp2 / Dt • Dp1 / Dt + Dp2 / Dt = F12 + F21 = 0 (Newton’s Third Law). • D(p1+p2 )/ Dt = 0 • Rate of change of total momentum is zero. • Total Momentum does not change if net external force is zero • Composite objects can be treated like point particles

More Related