Here is where my object is Here is where my object is going to be Here is where I want my object to be.

Slides:



Advertisements
Similar presentations
Everything you ever wanted to know about collision detection
Advertisements

2.4. Primitive Tests - Closest point
2.5. B ASIC P RIMITIVE I NTERSECTION Details of common forms of primitive intersection test.
Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
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/
Geometry Primer Lines and rays Planes Spheres Frustums Triangles Polygon Polyhedron.
David Breen, William Regli and Maxim Peysakhov
CS 450: Computer Graphics OVERVIEW OF POLYGONS
Computational Geometry & Collision detection
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Basic 3D collision detection We want to know if objects have touched Objects are considered to.
1 Terrain Following & Collision Detection. 2 Both of topics are very game-type-oriented Both of topics are very game-type-oriented Terrain Terrain For.
Collision Detection CSE 191A: Seminar on Video Game Programming Lecture 3: Collision Detection UCSD, Spring, 2003 Instructor: Steve Rotenberg.
3D Coordinate Systems and Transformations Revision 1
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
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.
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.
1Notes. 2 Time integration for particles  Back to the ODE problem, either  Accuracy, stability, and ease-of- implementation are main issues  Obviously.
Vectors.
Collision Detection David Johnson Cs6360 – Virtual Reality.
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
Computer graphics & visualization Collision Detection – Narrow Phase.
Week 13 - Wednesday CS361.
Solving Systems of Linear Equations in Three Variables; Applications
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.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Mathematical fundamentals of 3D computer graphics 1.1 Manipulating three-dimensional structures 1.2 Vectors and computer graphics 1.3 Rays and computer.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Game Physics – Part IV Moving to 3D
COMP 175: Computer Graphics March 24, 2015
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Rasterization Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
Collision handling: detection and response
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
Copyright © 2015, 2011, 2007 Pearson Education, Inc. 1 1 Chapter 4 Systems of Linear Equations and Inequalities.
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.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
CAP4730: Computational Structures in Computer Graphics
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Implementation II.
CGDD 4003 THE MATH LECTURE (BOILED DOWN, YET LIGHTLY SALTED)
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
Introduction to Computer Graphics CS 445 / 645 Lecture 9 Chapter 4: Rasterization L. McMillan MIT notes (Fall ’98)
Three-Dimensional Viewing
Advanced Computer Graphics Spring 2009
Computer Graphics I, Fall 2010 Implementation II.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Vector 2.
Parts of these slides are based on
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Geometry.
2.4. Primitive Tests - Closest point
2.5. Basic Primitive Intersection
What you will learn today
Computer Animation Algorithms and Techniques
CO Games Concepts Week 12 Collision Detection
David Johnson Cs6360 – Virtual Reality
Game Programming Algorithms and Techniques
Geometry.
GPAT – Chapter 7 Physics.
Presentation transcript:

Here is where my object is Here is where my object is going to be Here is where I want my object to be

 A box that is ◦ Defined by the min and max coordinates of an object ◦ Always aligned with the coordinate axes  How can we tell if a point p is inside the box? Initial Airplane Orientation Airplane Orientation 2

 Do a bunch of ifs ◦ if( p x = min x && p y >= min y && p z >= min z ) then collide = true; else collide = false P min x max x max y min y

 if mins/maxes overlap then collide = true else collide = false; Bmin x Bmax x Bmax y Bmin y Amin x Amax x

Initialization: Iterate through vertices and find mins and maxes After Transformations: Iterate through AABB vertices and find mins and maxes

 Initialization ◦ iterate through all vertices of your model to find the mins and maxes for x, y, and z  During runtime ◦ Test if any of the AABB mins/maxes of one object overlap with another object’s AABB mins/maxes  MAKE SURE THAT THE AABB VALUES ARE IN THE SAME COORDINATE FRAME (e.g., world coordinates)!  If they aren’t, then manually transform them so they are.  This is equivalent to multiplying the 8 points by a matrix for each object  Then make sure to recalculate your mins/maxes from the 8 transformed points!  Note: it is possible to do this with only 2 points from the box: (min x, min y,min z ), (max x,max y,max z ), but not required

 Keep a position p and a unit vector v.  Each frame add the vector to the position  p+v*speed,  This is essentially how the camera works in my latest code sample on my webpage  How about gravity? ◦ Add a gravity vector (e.g., g = [0,-1,0] ◦ v+=v+g*gravity ◦ p +=v*speed ◦ glTranslatefv(p) ◦ where gravity and speed are float

 Equation: Ax+By+Cz+D = 0 ◦ [A,B,C] is the normal of the plane ◦ D is how far from the origin it is  p = (x p,y p,z p )  What is the shortest distance from p to the plane?  Ax p +By p +Cz p + D = signed distance (assuming [A,B,C] is length 1)  For AABBs, normals are always going to be parallel to a principle axis e.g., x-axis: [A,B,C] = [1,0,0] [A,B,C] D P + -

 Manually (i.e., make your own matrix multiplication functions) transform all things collidable into the same coordinate frame (e.g. world coordinates)  E.g., if you have :  gluLookat(…)  glPushMatrix() ◦ glTranslatefv(p); ◦ Draw sphere projectile  glPopMatrix() glPushMatrix(); ◦ glRotate(a,x,y,z) ◦ glTranslate(tx,ty,tz) ◦ Draw a BB glPopMatrix() Get the vertices of this BB and multiply them by the RT matrix: e.g., RTv i for each of the 8 vertices, v i. This will put the BB into world coordinates RT matrix The p here is already a position in world coordinates! YAY!

 Manually transform the projectile into the BB’s object coordinate frame (less work for cpu)  E.g., if you have :  gluLookat(…)  glPushMatrix() ◦ glTranslatefv(p); ◦ Draw sphere projectile  glPopMatrix() glPushMatrix(); ◦ glRotate(a,x,y,z) ◦ glTranslate(tx,ty,tz) ◦ Draw a BB glPopMatrix() RT matrix 1)Multiply p by (RT) -1 or (-T)(-R)p 2)And do the same its direction vector v 2) do collision detection and response calculations with the untransformed BB 3) Put p back into world coordinates with RTp and its direction vector v Watchout for non-uniform scaling – for this you would need do do multiplications of the form M -1T v

 collide = true; // then what? ◦ Calculate ray intersection with the plane ◦ Calculate reflection vector (sound familiar?) ◦ Calculate new position  Rays are made of an origin (a point) and a direction (a vector) Ray direction Ray origin N Refl direction Current Position Next Position

 Make sure N and Ray direction are normalized!  Adjacent = A*Ray originX + B*Ray originY + C*Ray originZ +D  adjacent / cos(θ) = hypotenuse ◦ That is, dot (Ray direction, N) = cos(θ)  Ray origin +Ray direction *hypotenuse = i Ray direction Ray origin N Refl direction θ θ adjacent i

 Really we should use physics here but…  Think back to lighting ◦ Refl direction =-2dot(N, Ray direction ) *N + Ray direction Ray direction Ray origin N Refl direction θ θ adjacent i

 1) test collisions and response on untransformed objects before trying it with applied transforms ◦ Actually, the only requirement is projectile transformations.  2) use spheres for the projectiles ( you can basically treat these as points) and then you do not need to implement separating axes with OBB  3) draw your bounding boxes so you can see them (this is actually required is the project)  4) graduates : Don’t worry, I don’t expect terrain collisions

 A box that ◦ Stays oriented to the model regardless of transformations ◦ These are often defined by artists in the 3D modeling program ◦ There are algorithms to compute the minimum OBB, but this is out of scope for this class ◦ How to create the initial box?  1) Either:  Iterate through vertices (same as AABB  Make a nice box with a modeling program  2) Convert to plane equations Airplane Orientation 1 Airplane Orientation 2

 Take 3 vertices from one side of your box  Compute the normal ◦ [v3-v1] X [v2-v1] = [a,b,c] ◦ Normalize the normal ◦ [A,B,C] =[a,b,c] / ||[a,b,c]||  Solve the following: ◦ Ax +By+ Cz + D = 0  Plug in a point we know is on the plane ◦ Av1 x + Bv1 y + Cv1 z = - D v1 v2 v3

 Equation: Ax+By+Cz+D = 0 ◦ [A,B,C] is the normal of the plane ◦ D is how far from the origin it is  p = (x p,y p,z p )  What is the shortest distance from p to the plane?  Ax p +By p +Cz p + D = signed distance (assuming [A,B,C] is length 1) [A,B,C] D P + -

 If( a point evaluates to be <=0 distance from all 6 planes that make up the box  Then collide = true  Else collide = false

 Test whether any of the 8 points that make up one box collide with the other ◦ Do this for both boxes. ◦ This won’t always work in 3D…

 In ANY of the following cases, if all of the collision tests evaluate to positive, then assume no intersection ◦ 1) Test collisions between all the vertices of BB A and all the planes of the BB B ◦ 2) Test the collisions between all the vertices of BB B and all the planes of the BB A ◦ 3) Then test collisions between all the vertices of BB A and BB B and all cross products of each pair of edge normals of BB A and BB B This actually works for any convex polyhedron. There are optimizations for OBBs…optimizations

 Again, you will have to make sure that all planes, points, etc are in the same coordinate frame when computing collisions.  Think about normals ◦ Vertex: Mv as usual ◦ Normal: M -1T n, n= [A,B,C,0] T // this is a vector!  Transform the plane equation ◦ p = [A,B,C,D] ◦ Matrix M = arbitrary transforms  M -1T p ◦ OR, if you don’t have any non-uniform scaling  Mp  What would happen if you had non uniform scaling?