Space Partitioning for Broad Sweep Collision Detection Part 2 - Quadtrees Game Design Experience Professor Jim Whitehead February 13, 2009 Creative Commons.

Slides:



Advertisements
Similar presentations
Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Advertisements

Nearest Neighbor Search
Spatial Indexing SAMs. Spatial Indexing Point Access Methods can index only points. What about regions? Z-ordering and quadtrees Use the transformation.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
Searching on Multi-Dimensional Data
Algorithms and Data Structures Lecture 4. Agenda: Trees – fundamental notions, variations Binary search tree.
Computer Science C++ High School Level By Guillermo Moreno.
CSE 381 – Advanced Game Programming Scene Management
Quiz3! Midterm! Assignment2! (most) Quiz4! Today’s special: 4 for 1.
Quad Trees By JJ Shepherd. Introduction So far we’ve only used binary trees to solve problems – Sort data – Search data – Confuse students Trees are not.
QuadTrees 1. 2 x Quad Tree y 3 Quad Trees Split on all (two) dimensions at each level Split key space into equal size partitions (quadrants) Add a new.
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.
Multiple-key indexes Index on one attribute provides pointer to an index on the other. If V is a value of the first attribute, then the index we reach.
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
Space Partitioning for Broad Sweep Collision Detection Part 1 - Grids Game Design Experience Professor Jim Whitehead February 11, 2009 Creative Commons.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
Introduction to Collision Detection Lecture based on Real Time Collision Detection, Christer Ericson, Morgan Kauffman, 2005 Game Design Experience Professor.
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
AALG, lecture 11, © Simonas Šaltenis, Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.
1 BST Trees A binary search tree is a binary tree in which every node satisfies the following: the key of every node in the left subtree is.
BSP Trees, Quadtrees & Octrees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January 28, 2004.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
Storage CMSC 461 Michael Wilson. Database storage  At some point, database information must be stored in some format  It’d be impossible to store hundreds.
F453 Computing Searches. Binary Trees Not this kind of tree!
10/09/2001CS 638, Fall 2001 Today Spatial Data Structures –Why care? –Octrees/Quadtrees –Kd-trees.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
COSC 2007 Data Structures II Chapter 15 External Methods.
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
CS 361 – Chapter 3 Sorted dictionary ADT Implementation –Sorted array –Binary search tree.
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
Foundations of Data Structures Practical Session #8 Heaps.
Binary Heaps Text Read Weiss, § Binary Heap One-array representation of a tree Complete trees Building a Binary Heap Insert Delete.
CS 206 Introduction to Computer Science II 10 / 02 / 2009 Instructor: Michael Eckmann.
H EAPS. T WO KINDS OF HEAPS : MAX AND MIN Max: Every child is smaller than its parent Meaning the max is the root of the tree 10 / \ 9 7 / \ 6 8 / \ 2.
Spatial Indexing Techniques Introduction to Spatial Computing CSE 5ISC Some slides adapted from Spatial Databases: A Tour by Shashi Shekhar Prentice Hall.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
Maths & Technologies for Games Spatial Partitioning 2
HEAPS. Review: what are the requirements of the abstract data type: priority queue? Quick removal of item with highest priority (highest or lowest key.
Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Week 9 - Monday.  What did we talk about last time?  Practiced with red-black trees  AVL trees  Balanced add.
CS 367 Introduction to Data Structures Lecture 8.
1 B+ Trees Brian Lee CS157B Section 1 Spring 2006.
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
Search Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
Hierarchical Data Structure in Game Programming Yanci Zhang Game Programming Practice.
Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size.
Introduction to Collision Detection
Binary search tree. Removing a node
Multiway search trees and the (2,4)-tree
Week 11 - Friday CS221.
Wednesday, April 18, 2018 Announcements… For Today…
Binary Heaps Text Binary Heap Building a Binary Heap
Multi-Way Search Trees
B-Trees.
Quadtrees 1.
Brian Lee CS157B Section 1 Spring 2006
CS679 - Fall Copyright Univ. of Wisconsin
Heaps By JJ Shepherd.
Presentation transcript:

Space Partitioning for Broad Sweep Collision Detection Part 2 - Quadtrees Game Design Experience Professor Jim Whitehead February 13, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0

Announcements Technical Design Document ► Due today ► May turn it in to the box by my door by the end of the day Have midterm exams ► See me after class to pick up ► Answer key is on class website

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)

Trees A tree is a data structure ► Places contents into nodes ► Each node has Contents Pointers to 0 or more other levels ► Children are represented as references root ab c d A tree with 5 nodes (root, a, b, c, d). Root node has contents 56. Node a has contents 45, and two children, c and d. Node b has contents 75, and no children. Node c has contents 24, and no children. Node d has contents 51, and no children. // A simple tree node class Class Node { List children; // List of references to Nodes int contents; }

Tree Operations Adding a child ► Create new node n = new Node(); ► Add it to list of children of parent parentNode.children.Add(n); Removing a child ► Find and remove child node from list of children parentNode.children.Remove(childToRemove); (childToRemove is reference to Node of child to be deleted)

Point Quadtree A tree where each node has four children ► Each level represents subdividing space into 4 quadrants ► Each node holds information about one quadrant ► A deeper tree indicates more subdivisions MX Quadtree Demo ee/points/mxquad.html Demo both points and rectangles root root

C# Node Representation quads is an array with four elements ► Each element is a reference to a Node Quad[0] – upper left, etc. ► A recursive data structure Nodes hold pointers to Nodes Min[] is an array with four elements ► Each element is upper left point of quadrant Max[] holds lower right point of each quadrant Level indicates how many levels down in the tree ► Useful for bounding the depth of the tree class Node { Point min[4]; Point max[4]; int level; Node Quad[4]; // holds 4 quadrants List objectList; // list of game objects in a Node } Quad[0]Quad[1] Quad[2]Quad[3]

Adding object to tree Insert(Node n, IGameObject g) Iterate through all 4 quadrants of current node (n) ► If at maximum depth of the tree Add IGameObject to objectList and return ► If AABB (bounding box) of IGameObject lies fully within a quadrant Create child node for that quadrant, if necessary Then call insert on that node (recursion) ► Otherwise, AABB does not lie in just one quadrant Add to contents list at this level First call is Insert(root, g) ► That is, start at root node for insertions

Finding, removing object in tree Find(Node n, IGameObject g) Iterate through all 4 quadrants of current node (n) ► Check if AABB (bounding box) of IGameObject spans multiple quadrants Yes: IGameObject is in this node. Return node. ► At maximum level of tree? Yes: IGameObject is at this level ► If AABB (bounding box) of IGameObject lies fully within a quadrant Call find on that node (recursion) Removing object from tree ► Found_node = Find(root, g) ► Found_node.objectList.Remove(g)