Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Everything you ever wanted to know about collision detection
2.4. Primitive Tests - Closest point
2.5. B ASIC P RIMITIVE I NTERSECTION Details of common forms of primitive intersection test.
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
CSE 681 Bounding Volumes. CSE 681 Bounding Volumes Use simple volume enclose object(s) tradeoff for rays where there is extra intersection test for object.
2.3. B OUNDING V OLUMES Bounding volumes of use for collision detection.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development 11/28/
Computer graphics & visualization Collisions. computer graphics & visualization Simulation and Animation – SS07 Jens Krüger – Computer Graphics and Visualization.
Geometry Primer Lines and rays Planes Spheres Frustums Triangles Polygon Polyhedron.
Here is where my object is Here is where my object is going to be Here is where I want my object to be.
고려대학교 그래픽스 연구실 Chapter 6 Collision Detection 6.1~6.4 고려대학교 그래픽스연구실 민성환.
Computer Graphics Viewing.
Computational Geometry & Collision detection
Week 14 - Monday.  What did we talk about last time?  Bounding volume/bounding volume intersections.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
By: Andrew Shatz & Michael Baker Chapter 15. Chapter 15 section 1 Key Terms: Skew Lines, Oblique Two lines are skew iff they are not parallel and do not.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Collision Detection CSE 191A: Seminar on Video Game Programming Lecture 3: Collision Detection UCSD, Spring, 2003 Instructor: Steve Rotenberg.
Tomas Mőller © 2000 Speeding up your game The scene graph Culling techniques Level-of-detail rendering (LODs) Collision detection Resources and pointers.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
OBBTree: A Hierarchical Structure for Rapid Interference Detection Gottschalk, M. C. Lin and D. ManochaM. C. LinD. Manocha Department of Computer Science,
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
Geometry Formulas in Three Dimensions
CSE 681 Object Intersection. CSE 681 Object Representation Implicit forms F(x,y,z) = 0 Explicit forms Analytic form x = F(y,z) testing generating Parametric.
Collision Detection David Johnson Cs6360 – Virtual Reality.
Computer graphics & visualization Collision Detection – Narrow Phase.
Week 13 - Wednesday CS361.
12/4/2001CS 638, Fall 2001 Today Using separating planes/axes for collision testing Collision detection packages.
Geometric Intuition Randy Gaul. Vectors, Points and Basis Matrices Rotation Matrices Dot product and how it’s useful Cross product and how it’s useful.
Collision handling: detection and response
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Collisions & Contact.
Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Collision/Acceleration University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Implementation II.
Three-Dimensional Viewing
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Advanced Computer Graphics Spring 2009
Computer Graphics I, Fall 2010 Implementation II.
RENDERING : Global Illumination
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Week 13 - Wednesday CS361.
- Introduction - Graphics Pipeline
Computer Graphics Implementation II
Bounding Volume Hierarchies and Spatial Partitioning
Frustum Culling in OpenGL
Collision Detection Spring 2004.
Bounding Volume Hierarchies and Spatial Partitioning
CS451Real-time Rendering Pipeline
Parts of these slides are based on
Implementation II Ed Angel Professor Emeritus of Computer Science
2.5. Basic Primitive Intersection
Ray Tracing Polyhedra ©Anthony Steed
Computer Animation Algorithms and Techniques
Introduction to Computer Graphics with WebGL
Collision Detection.
CO Games Concepts Week 12 Collision Detection
David Johnson Cs6360 – Virtual Reality
Implementation II Ed Angel Professor Emeritus of Computer Science
GPAT – Chapter 7 Physics.
Presentation transcript:

Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Tomas Akenine-Mőller © 2003 What for? A tool needed for the graphics people all the time… Very important components: – Need to make them fast! Finding if (and where) a ray hits an object – Picking – Ray tracing and global illumination For speed-up techniques Collision detection (treated in a later lecture)

Tomas Akenine-Mőller © 2003 Some basic geometrical primitives Ray: Sphere: Box – Axis-aligned (AABB) – Oriented (OBB) k-DOP

Tomas Akenine-Mőller © 2003 Four different techniques Analytical Geometrical Separating axis theorem (SAT) Dynamic tests Given these, one can derive many tests quite easily – However, often tricks are needed to make them fast

Tomas Akenine-Mőller © 2003 Analytical: Ray/sphere test Sphere center: c, and radius r Ray: r(t)=o+td Sphere formula: ||p-c||=r Replace p by r(t), and square it: o d c r

Tomas Akenine-Mőller © 2003 Analytical, continued Be a little smart… c o d Such tests are called ”rejection tests” Other shapes:

Tomas Akenine-Mőller © 2003 Geometrical: Ray/Box Intersection Boxes and spheres often used as bounding volumes A slab is the volume between two parallell planes: A box is the logical intersection of three slabs (2 in 2D): BOX

Tomas Akenine-Mőller © 2003 Geometrical: Ray/Box Intersection (2) Intersect the 2 planes of each slab with the ray Keep max of t min and min of t max If t min < t max then we got an intersection Special case when ray parallell to slab

Tomas Akenine-Mőller © 2003 Separating Axis Theorem (SAT) Page 563 in book Two convex polyhedrons, A and B, are disjoint if any of the following axes separate the objects: – An axis orthogonal to a face of A – An axis orthogonal to a face of B – An axis formed from the cross product of one edge from each of A and B A and B overlaps on this axis axis

Tomas Akenine-Mőller © 2003 SAT example: Triangle/Box Box is axis-aligned 1) test the axes that are orthogonal to the faces of the box That is, x,y, and z

Tomas Akenine-Mőller © 2003 Triangle/Box with SAT (2) Assume that they overlapped on x,y,z Must continue testing 2) Axis orthogonal to face of triangle Triangle seen from side axis

Tomas Akenine-Mőller © 2003 Triangle/Box with SAT (3) If still no separating axis has been found… 3) Test axis: t=e box x e triangle Example: – x-axis from box: e box =(1,0,0) – e triangle = v 1 -v 0 Test all such combinations If there is at least one separating axis, then the objects do not collide Else they do overlap

Tomas Akenine-Mőller © 2003 Rules of Thumb for Intersection Testing Acceptance and rejection test – Try them early on to make a fast exit Postpone expensive calculations if possible Use dimension reduction – E.g. 3 one-dimensional tests instead of one complex 3D test, or 2D instead of 3D Share computations between objects if possible Timing!!!

Tomas Akenine-Mőller © 2003 Another analytical example: Ray/Triangle in detail Ray: r(t)=o+td Triangle vertices: v 0, v 1, v 2 A point in the triangle: t(u,v)=v 0 +u(v 1 - v 0 ) +v(v 2 - v 0 )= =(1-u-v)v 0 +uv 1 +vv 2 [u,v>=0, u+v<=1] Set t(u,v)=r(t), and solve! v2v2 v1v1 v0v0 v 1 -v 0 v 2 -v 0

Tomas Akenine-Mőller © 2003 Ray/Triangle (2) Solve with Cramer’s rule: Share factors to speed up computations

Tomas Akenine-Mőller © 2003 Ray/Triangle (3) Implementation Be smart! – Compute as little as possible then test Examples: Compute Then test valid bounds if (v 1) exit;

Tomas Akenine-Mőller © 2003 Point/Plane Insert a point x into plane equation: origin Positive half space Negative half space

Tomas Akenine-Mőller © 2003 Sphere/Plane AABB/Plane Sphere: compute f (c) is the signed distance ( n normalized) Box: insert all 8 corners If all f ’s have the same sign, then all points are on the same side, and no collision abs( f (c)) > r no collision abs( f (c)) = r sphere touches the plane abs( f (c)) < r sphere intersects plane

Tomas Akenine-Mőller © 2003 AABB/plane The smart way (shown in 2D) Find diagonal that is most closely aligned with plane normal More details in book Need only test the red points

Tomas Akenine-Mőller © 2003 Ray/Polygon: very briefly Intersect ray with polygon plane Project from 3D to 2D How? Find max(|n x |,|n y |,|n z |) Skip that coordinate! Then, count crossing in 2D

Tomas Akenine-Mőller © 2003 Volume/Volume tests Used in collision detection Sphere/sphere – Compute squared distance between sphere centers, and compare to (r 1 +r 2 ) 2 Axis-Aligned Bounding Box/AABB – Test in 1D for x,y, and z Oriented Bounding boxes Use SAT [details in book]

Tomas Akenine-Mőller © 2003 View frustum testing View frustum is 6 planes: Near, far, right, left, top, bottom Create planes from projection matrix – Let all positive half spaces be outside frustum – Not dealt with here -- p Sphere/frustum common approach: – Test sphere against 6 frustum planes – If in positive half space and r distances from plane => no intersection – If intersecting plane or in negative half space, continue – If not outside after all six planes, then inside or intersecting Example follows…

Tomas Akenine-Mőller © 2003 View frustum testing example Not exact test, but not incorrect – A sphere that is reported to be inside, can be outside – Not vice versa Similarly for boxes outside frustum intersecting frustum

Tomas Akenine-Mőller © 2003 Dynamic Intersection Testing [In book: ] Testing is often done every rendered frame, i.e., at discrete time intervals Therefore, you can get ”quantum effects” Frame n Frame n+1 Dynamic testing deals with this Is more expensive Deals with a time interval: time between two frames

Tomas Akenine-Mőller © 2003 Dynamic intersection testing Sphere/Plane No collision occur: – If they are on the same side of the plane ( s c s e >0 ) – Plus | s c | >r and | s e | >r Otherwise, sphere can move |s c |-r Time of collision: e r scsc sese s c & s e are signed distances t=nt=n t=n+1 Response: reflect v around n, and move (1-t cd )r r v c n

Tomas Akenine-Mőller © 2003 Dynamic Separating Axis Theorem SAT: tests one axis at a time for overlap Same with DSAT, but: – Need to adjust the projection on the axis so that the interval moves on the axis as well Need to test same axes as with SAT Same criteria for overlap/disjoint: – If no overlap on axis => disjoint – If overlap on all axes => objects overlap