Computer Science – Game DesignUC Santa Cruz Today Homework Bounding Boxes Quadtrees Per-pixel collision Drawing text (if we have time)

Slides:



Advertisements
Similar presentations
2.5. B ASIC P RIMITIVE I NTERSECTION Details of common forms of primitive intersection test.
Advertisements

Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Intermediate Code Generation
Computational Geometry
Efficient access to TIN Regular square grid TIN Efficient access to TIN Let q := (x, y) be a point. We want to estimate an elevation at a point q: 1. should.
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/
Computer graphics & visualization Collisions. computer graphics & visualization Simulation and Animation – SS07 Jens Krüger – Computer Graphics and Visualization.
Computer Science C++ High School Level By Guillermo Moreno.
Computational Geometry & Collision detection
Space Partitioning for Broad Sweep Collision Detection Part 2 - Quadtrees Game Design Experience Professor Jim Whitehead February 13, 2009 Creative Commons.
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.
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 CMPS 20: Game Design Experience Gforge SVN Collision Detection and Resolution.
Main Index Contents 11 Main Index Contents Tree StructuresTree Structures (3 slides) Tree Structures Tree Node Level and Path Len. Tree Node Level and.
Tomas Mőller © 2000 Speeding up your game The scene graph Culling techniques Level-of-detail rendering (LODs) Collision detection Resources and pointers.
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
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 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.
Collision Detection David Johnson Cs6360 – Virtual Reality.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
10/02/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Octrees.
Computer Graphics 2 Lecture x: Acceleration Techniques for Ray-Tracing Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
Managing Your Objects Paul Taylor 2009 Assignment Due Fri 5/6/2009.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Trees, Binary Search Trees, Recursion, Project 2 Bryce Boe 2013/08/01 CS24, Summer 2013 C.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Data types and their representation Jordi Cortadella Department of Computer Science.
Lecture X Augmenting Data Structures
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
1 2-D Trees You are given a set of points on the plane –Each point is defined by two coordinates (x, y) (5,45) (25,35) (35,40) (50,10) (90,5) (85,15) (80,65)
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.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
Chapter 11 Collision Detection 가상현실 입문 그래픽스 연구실 민성환.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
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.
Spatial Indexing Techniques Introduction to Spatial Computing CSE 5ISC Some slides adapted from Spatial Databases: A Tour by Shashi Shekhar Prentice Hall.
1/14/20161 BST Operations Data Structures Ananda Gunawardena.
Constructive Solid Geometry Ray Tracing CSG Models
Maths & Technologies for Games Spatial Partitioning 2
1 Sage Demo 4 Collisions SAGE Lecture Notes Ian Parberry University of North Texas.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Computer Game Design and Development Collision Detection Havok Destruction.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
Hierarchical Data Structure in Game Programming Yanci Zhang Game Programming Practice.
Bounding Volume Hierarchies and Spatial Partitioning
Introduction to Collision Detection
Collision Detection Spring 2004.
Bounding Volume Hierarchies and Spatial Partitioning
Trees.
Chapter 20: Binary Trees.
Chapter 21: Binary Trees.
Binary Heaps Text Binary Heap Building a Binary Heap
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
What you will learn today
Collision Detection.
BVH Student: Jack Chang.
Heaps By JJ Shepherd.
Game Programming Algorithms and Techniques
Trees.
GPAT – Chapter 7 Physics.
Presentation transcript:

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 Secret Game Two Parts – Part I: Debug Syntax errors Logical errors Improvements Comments – Part II: Complete Game Score Lives

Computer Science – Game DesignUC Santa Cruz 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

Computer Science – Game DesignUC Santa Cruz 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.

Computer Science – Game DesignUC Santa Cruz 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 Can easily be extended to 3D

Computer Science – Game DesignUC Santa Cruz 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; }

Computer Science – Game DesignUC Santa Cruz 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)

Computer Science – Game DesignUC Santa Cruz 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

Computer Science – Game DesignUC Santa Cruz 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; }

Computer Science – Game DesignUC Santa Cruz 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)

Computer Science – Game DesignUC Santa Cruz 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 points/mxquad.html Demo both points and rectangles root root

Computer Science – Game DesignUC Santa Cruz 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]

Computer Science – Game DesignUC Santa Cruz 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

Computer Science – Game DesignUC Santa Cruz 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)

Computer Science – Game DesignUC Santa Cruz Per-pixel collision

Computer Science – Game DesignUC Santa Cruz Drawing Text Create a new SpriteFont in Content folder Add a SpriteFont myText variable to your game In LoadContent(), use myText =Content.Load (“SpriteFont1”) In Draw(), spriteBatch.Begin(); spriteBatch.DrawString(myText, … ); spriteBatch.End();