Introduction to Collision Detection Lecture based on Real Time Collision Detection, Christer Ericson, Morgan Kauffman, 2005 Game Design Experience Professor.

Slides:



Advertisements
Similar presentations
2.6. B OUNDING V OLUME H IERARCHIES Overview of different forms of bounding volume hierarchy.
Advertisements

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.
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.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
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.
CSE 380 – Computer Game Programming Collision Detection & Response Erin Catto’s Box2D.
Computational Geometry & Collision detection
Week 14 - Monday.  What did we talk about last time?  Bounding volume/bounding volume intersections.
Space Partitioning for Broad Sweep Collision Detection Part 2 - Quadtrees Game Design Experience Professor Jim Whitehead February 13, 2009 Creative Commons.
Computer Science – Game DesignUC Santa Cruz Common Bounding Volumes Most introductory game programming texts call AABBs simply “bounding boxes” Circle/SphereAxis-Aligned.
Computer Science – Game DesignUC Santa Cruz Today Homework Bounding Boxes Quadtrees Per-pixel collision Drawing text (if we have time)
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience Gforge SVN Collision Detection and Resolution.
Collision Detection CSE 191A: Seminar on Video Game Programming Lecture 3: Collision Detection UCSD, Spring, 2003 Instructor: Steve Rotenberg.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
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.
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
Inheritance, Method Overloading, Interfaces, Abstract Classes Game Design Experience Professor Jim Whitehead January 28, 2009 Creative Commons Attribution.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Continuous Collision Detection David Knott COMP 259 class presentation.
Space Partitioning for Broad Sweep Collision Detection Part 1 - Grids Game Design Experience Professor Jim Whitehead February 11, 2009 Creative Commons.
Bounding Volume Hierarchies and Spatial Partitioning Kenneth E. Hoff III COMP-236 lecture Spring 2000.
Exam Questions Chain of Responsibility & Singleton Patterns Game Design Experience Professor Jim Whitehead February 4, 2009 Creative Commons Attribution.
Apex Point Map for Constant-Time Bounding Plane Approximation Samuli Laine Tero Karras NVIDIA.
1 Advanced Scene Management System. 2 A tree-based or graph-based representation is good for 3D data management A tree-based or graph-based representation.
Physics Simple – Pong Medium – Rigid bodies F = ma Circles, spheres, rectangles for collisions Complex – Fluids, clothings, explosions, hair.
Collision Detection David Johnson Cs6360 – Virtual Reality.
12/4/2001CS 638, Fall 2001 Today Using separating planes/axes for collision testing Collision detection packages.
Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0 Key Abstractions in Game Maker Foundations of Interactive Game Design Prof. Jim Whitehead.
Managing Your Objects Paul Taylor 2009 Assignment Due Fri 5/6/2009.
Backgrounds, Inheritance in GameMaker (BrickMania 1 of 2) Foundations of Interactive Game Design Professor Jim Whitehead January 28, 2008 Creative Commons.
CSE 381 – Advanced Game Programming Quickhull and GJK.
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
1 CO Games Concepts Week 20 Matrices continued Gareth Bellaby.
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,
Quaternions Paul Taylor Swizzle What is a swizzle?
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.
12/4/2001CS 638, Fall 2001 Today Managing large numbers of objects Some special cases.
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
1 KIPA Game Engine Seminars Jonathan Blow Ajou University December 6, 2002 Day 10.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
ONLINE CONFERENCE DESIGN.BUILD.DELIVE R with WINDOWS PHONE THURSDAY 24 MARCH 2011.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Chapter 11 Collision Detection 가상현실 입문 그래픽스 연구실 민성환.
11/20/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Collision Detection Overview Player-Environment handling.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
1 Sage Demo 4 Collisions SAGE Lecture Notes Ian Parberry University of North Texas.
David Luebke 3/5/2016 Advanced Computer Graphics Lecture 4: Faster Ray Tracing David Luebke
1 Advanced Scene Management. 2 This is a game-type-oriented issue Bounding Volume Hierarchies (BVHs) Binary space partition trees (BSP Trees) “Quake”
Introduction to Game Programming & Design III Lecture III.
Hierarchical Data Structure in Game Programming Yanci Zhang Game Programming Practice.
Bounding Volume Hierarchies and Spatial Partitioning
Introduction to Collision Detection
3D Game Development and Computer Animation Collision Detection
Introduction to Invariants
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
Bounding Volume Hierarchies and Spatial Partitioning
Parts of these slides are based on
What you will learn today
Computer Animation Algorithms and Techniques
Collision Detection.
Game Programming Algorithms and Techniques
GPAT – Chapter 7 Physics.
Presentation transcript:

Introduction to Collision Detection Lecture based on Real Time Collision Detection, Christer Ericson, Morgan Kauffman, 2005 Game Design Experience Professor Jim Whitehead February 9, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0

Announcements Homework #1, Revisited (Improved Design) ► Due today ► May turn it in to the box by my door by the end of the day ► Also make sure you do electronic submission ► See details on web site Midterm exam ► Aiming for return of exams on Wednesday ► Will post answer key after class today

Technical Design Document Create a UML structure diagram for your game ► Map out your design on paper, before writing code ► Allows you to think about design decisions early ► Due this Friday, February 13 In one or more UML diagrams, describe all of the classes and interfaces you will create for your project ► For each class and interface, give Class properties, methods, and variables ► Show inheritance and containment relationships

Technical Design Document (cont’d) Items that should be in your design ► input handling ► representation of game levels, if present ► player class ► enemy classes, including a container holding active enemies ► game object classes, including a container to hold them ► collision detection ► classes for drawing player, enemies, other game objects ► classes for handling audio ► menu system classes Make sure TDD is consistent with game design ► Are you missing anything? Strongly recommend using a UML modeling tool ► StarUML is free, has good set of features ► (see link on Tools page) Demonstration of use of StarUML

Collision Detection Collision detection ► Determining if two objects intersect (true or false) ► Example: did bullet hit opponent? Collision resolution (collision determination) ► Determining when two objects came into contact At what point during their motion did they intersect? Example: Two balls needing to bounce off each other ► Determining where two objects intersect Which points on the objects touch during a collision? Example: Pong: where ball hits paddle is important Complexity of answering these questions increases in order given ► If < when < where

Key to collision detection: scaling Key constraint: only ms per clock tick ► Limited time to perform collision detection Object shapes in 2D games can be quite complex ► Naïve: check two objects pixel-by-pixel for collisions Many objects can potentially collide ► Naïve: check every object pair for collisions Drawback of naïve approach ► Takes too long ► Doesn’t scale to large numbers of objects Approaches for scaling ► Reduce # of collision pairs ► Reduce cost of each collision check Chu Chu Rocket, Dreamcast

Naïve Collision Detection: n x n checking Assume ► n objects in game ► All n objects can potentially intersect with each other Conceptually easiest approach ► Check each object against every other object for intersections ► Leads to (n-1) + (n-2) + … + 1 = n(n-1)/2 = O(n 2 ) checks ► Done poorly, can be exactly n 2 checks ► Example: 420 objects leads to 87,990 checks, per clock tick Demonstration of n x n collision checking

Broad vs Narrow Sweep With many small objects in large playfield ► Each object only has the potential to collide with nearby objects Broad sweep ► Perform a quick pass over n objects to determine which pairs have potential to intersect, p Narrow sweep ► Perform p x p check of object pairs that have potential to intersect Dramatically reduces # of checks Mushihimesama

Broad sweep approaches Grid ► Divide playfield into a grid of squares ► Place each object in its square ► Only need to check contents of square against itself and neighboring squares ► See for example Space partitioning tree ► Subdivide space as needed into rectangles ► Use tree data structure to point to objects in space ► Only need to check tree leaves ► Quadtree, Binary Space Partition (BSP) tree Application-specific ► 2D-shooter: only need to check for collision against ship ► Do quick y check for broad sweep Point Quadtree (Wikipedia)

Reducing Cost of Checking Two Objects for Collision General approach is to substitute a bounding volume for a more complex object Desirable properties of bounding volumes: ► Inexpensive intersection tests ► Tight fitting ► Inexpensive to compute ► Easy to rotate and transform ► Low memory use Megaman X1 (Capcom). White boxes represent bounding volumes.

Common Bounding Volumes Most introductory game programming texts call AABBs simply “bounding boxes” Circle/SphereAxis-Aligned Bounding Box (AABB) Oriented Bounding Box (OBB) Convex Hull Better bounds, better culling Faster test, less memory

Circle Bounding Box Simple storage, easy intersection test Rotationally invariant struct Point { int x; int y; } struct circle { Point c; // center int r; // radius } r c bool circle_intersect(circle a, circle b) { Point d; // d = b.c – a.c d.x = a.c.x – b.c.x; d.y = a.c.y – b.c.y; int dist2 = d.x*d.x + d.y*d.y; // d dot d int radiusSum = a.r + b.r; if (dist2 < = radiusSum * radiusSum) { return true; } else { return false; } Compare Euclidean distance between circle centers against sum of circle radii.

Axis-Aligned Bounding Boxes (AABBs) Three common representations ► Min-max ► Min-widths ► Center-radius // min.x < =x < =max.x // min.y < =y < =max.y struct AABB { Point min; Point max; } // min.x < =x < =min.x+dx // min.y < =y < =min.y+dy struct AABB { Point min; int dx; // x width int dy; // y width } // | c.x-x | < = rx | c.y-y | < = ry struct AABB { Point c; int rx; // x radius int ry; // y radius } min max min c dx dy ry rx struct Point { int x; int y; } Can easily be extended to 3D

Axis Aligned Bounding Box Intersection (min-max) Two AABBs intersect only if they overlap on both axes a.max.x<b.min.x a.min.x>b.max.xa.min.x=b.min.x a.max.y<b.min.y a.min.y>b.max.y a.min.y=b.min.y bool IntersectAABB(AABB a, AABB b) { { if (a.max.x < b.min.x || a.min.x < b.max.x) return false; if (a.max.y < b.min.y || a.min.y < b.max.y) return false; return true; }

Axis Aligned Bounding Box Intersection (min-width) Two AABBs intersect only if they overlap on both axes -(a.min.x- b.min.x)>a.dx (a.min.x- b.min.x)>b.dx a.min.x=b.min.x -(a.min.y- b.min.y)>a.dy (a.min.y- b.min.y)>b.dy a.min.y=b.min.y bool IntersectAABB(AABB a, AABB b) { { int t; t=a.min.x-b.min.x; if (t > b.dx || -t > a.dx) return false; t=a.min.y-b.min.y; if (t > b.dy || -t > a.dy) return false; return true; } // Note: requires more operations than // min-max case (2 more subtractions, 2 more negations)

AABB Intersection (center-radius) Two AABBs intersect only if they overlap on both axes b.c.x-a.c.x > a.rx+b.ry a.c.x-b.c.x > a.rx+b.rx a.c.x=b.c.x b.c.y-a.c.y > a.ry+b.ry a.c.y-b.c.y > a.ry+b.ry a.c.y=b.c.y bool IntersectAABB(AABB a, AABB b) { { if (Abs(a.c.x – b.c.x) > (a.r.dx + b.r.dx)) return false; if (Abs(a.c.y – b.c.y) > (a.r.dy + b.r.dy)) ) return false; return true; } // Note: Abs() typically single instruction on modern processors

Homework Readings from Real Time Collision Detection ► See forum/syllabus for details, will scan today