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.

Slides:



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

2.5. B ASIC P RIMITIVE I NTERSECTION Details of common forms of primitive intersection test.
8.1 Prisms, Area and Volume Prism – 2 congruent polygons lie in parallel planes corresponding sides are parallel. corresponding vertices are connected.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
ADA: 15. Basic Math1 Objective o a reminder about dot product and cross product, and their use for analyzing line segments (e.g. do two segments.
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.
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 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
고려대학교 그래픽스 연구실 Chapter 6 Collision Detection 6.1~6.4 고려대학교 그래픽스연구실 민성환.
Chapter 12: Surface Area and Volume of Solids
Computational Geometry & Collision detection
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.
1 Terrain. Game Type Oriented Game Type Oriented Terrain Terrain –For visual ( 廣義的場景 ) »Ground / Building / Static models / Dynamic models –For terrain.
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.
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.
Content Subdivision First some basics (control point polygon, mesh)
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.
1Notes. 2 Time integration for particles  Back to the ODE problem, either  Accuracy, stability, and ease-of- implementation are main issues  Obviously.
Collision Detection David Johnson Cs6360 – Virtual Reality.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Computer graphics & visualization Collision Detection – Narrow Phase.
Week 13 - Wednesday CS361.
Chapter 15: Geometric Solids Brian BarrDan Logan.
Chapter 12 Notes.
Mathematical fundamentals of 3D computer graphics 1.1 Manipulating three-dimensional structures 1.2 Vectors and computer graphics 1.3 Rays and computer.
Solar potential analysis with shadowing effect. Illustrative examples of surfaces:
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
1 Game AI Path Finding. A Common Situation of Game AI A Common Situation of Game AI Path Planning Path Planning –From a start position to a destination.
On The Graph Name that Transform- ation Lesson 3 Vocabulary Prisms Lesson 4 Vocabulary
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,
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
Section 12-1 Name the Solids. Prism a 3-dimensional figure with two congruent, parallel faces The bases are congruent, parallel faces. The bases lie in.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
12.1 & 12.2 – Explore Solids & Surface Area of Prisms and Cones.
1 Dr. Scott Schaefer Intersecting Simple Surfaces.
CS418 Computer Graphics John C. Hart
Chapter Area, Pythagorean Theorem, and Volume 14 Copyright © 2013, 2010, and 2007, Pearson Education, Inc.
1 Subdivision. 2 Subdivision for game Why? Large model require many memory for storage Need to dynamically tessellated during game play Make surface modeling.
Advanced Computer Graphics Spring 2009
Robust Watermarking of 3D Mesh Models. Introduction in this paper, it proposes an algorithm that extracts 2D image from the 3D model and embed watermark.
1 Advanced Scene Management. 2 This is a game-type-oriented issue Bounding Volume Hierarchies (BVHs) Binary space partition trees (BSP Trees) “Quake”
Solid Modeling Dr. Scott Schaefer.
Vocabulary for the Common Core Sixth Grade.  base: The side of a polygon that is perpendicular to the altitude or height. Base of this triangle Height.
1 Geometry for Game. Geometry Geometry –Position / vertex normals / vertex colors / texture coordinates Topology Topology –Primitive »Lines / triangles.

Intersecting Simple Surfaces
Grids Geometry Computational Geometry
Collision handling: detection and response
Grids Geometry Computational Geometry
2.5. Basic Primitive Intersection
Meshes.
Computer Animation Algorithms and Techniques
Game Programming Algorithms and Techniques
David Johnson Cs6360 – Virtual Reality
Polygons.
GPAT – Chapter 7 Physics.
Presentation transcript:

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 visual purpose For visual purpose Ground / Building / Static models / Dynamic models Ground / Building / Static models / Dynamic models For terrain following For terrain following Polygon mesh Polygon mesh Grids Grids For path finding For path finding Polygon mesh Polygon mesh Grids Grids Terrain following Terrain following Make a 3D entity (character or model) walking on terrain Make a 3D entity (character or model) walking on terrain Path finding Path finding Find a “shortest” path to walk before moving Find a “shortest” path to walk before moving Game AI Game AI A* algorithm A* algorithm Introduction (1/2)

3 Collision detection Collision detection The basic solution for collision detection is solving the intersection of a ray with a plane. The basic solution for collision detection is solving the intersection of a ray with a plane. We will introduce : We will introduce : Containment test Containment test Separating axis Separating axis Collision avoidance Collision avoidance Will be introduced at Steer behavior in Game AI section Will be introduced at Steer behavior in Game AI section Introduction (2/2)

4 Grid Grid 2D 2D Quadtree Quadtree Height map Height map Procedural height map Procedural height map Using noise function to generate the height Using noise function to generate the height Terrain Formats Perlin Noise ROAM ROAM Real-time Optimally Adapting Meshes Real-time Optimally Adapting Meshes Triangular mesh Triangular mesh Procedurally generated Procedurally generated Created by artists Created by artists

5 2D grid map 2D grid map Rectangular or Hexagonal grids Rectangular or Hexagonal grids Attributes Attributes Height Height Walkable or not Walkable or not Texture pattern ID Texture pattern ID Grid Map Step look terrain Step look terrain Application Application 2D games 2D games 3D games with god view 3D games with god view 2D tile-based game terrain 2D tile-based game terrain

6 Almost as same as 2D grid map but :" Almost as same as 2D grid map but :" Height on grid vertex Height on grid vertex Only height is saved Only height is saved Regular grid Regular grid Irregular grid but structured Irregular grid but structured Height Map Top view Application Application As the base data structure for ROAM terrain As the base data structure for ROAM terrain Water simulation Water simulation

7 Real-time optimally adapting mesh Real-time optimally adapting mesh ROAM Application Application Fly-simulation Fly-simulation

8 Use quad tree to construct the level-of-detail of terrain Use quad tree to construct the level-of-detail of terrain A quad tree for LOD A quad tree for LOD Chunked LOD Terrain

9 Possibly the most popular way for 3D games Possibly the most popular way for 3D games General General Can be created by artists Can be created by artists Triangular Mesh Multiple-layered terrain issue Multiple-layered terrain issue

10 h hahahaha hbhbhbhb hchchchc AaAaAaAa AcAcAcAc AbAbAbAb h = h a + h b + h c where A = A a + A b + A c where A = A a + A b + A c If (A a < 0 || A b < 0 || A c < 0) than the point is outside the triangle “Triangular Coordinate System” “Barycentric Coordinate System” AaAaAaAa AbAbAbAb AcAcAcAc A A A p (x a,y a,z a ) (x b,y b,z b ) (x c,y c,z c ) Barycentric Coordinate System

11 Area of a triangle in 2D x a y a A = ½ x b y b x c y c x a y a = ½ (x a *y b + x b *y c + x c *y a – x b *y a – x c *y b – x a *y c ) Triangle Area – 2D (x a,y a,z a ) (x b,y b,z b ) (x c,y c,z c )

12 Area of a triangle in 3D Triangle Area – 3D

13 Terrain following Terrain following Interpolating the height of arbitrary point within the triangle Interpolating the height of arbitrary point within the triangle Hit test Hit test Intersection of a ray from camera to a screen position with a triangle Intersection of a ray from camera to a screen position with a triangle Ray cast Ray cast Intersection of a ray with a triangle Intersection of a ray with a triangle Collision detection Collision detection Intersection Intersection Barycentric Coordinate System - Application

14 Ray Cast – The Ray x = x 0 + (x 1 – x 0 ) t y = y 0 + (y 1 – y 0 ) t, t = 0, z = z 0 + (z 1 – z 0 ) t { Cast a ray to calculate the intersection of the ray with models Cast a ray to calculate the intersection of the ray with models Use parametric equation for a ray Use parametric equation for a ray 8 When t = 0, the ray is on the start point (x 0, y 0, z 0 ) When t = 0, the ray is on the start point (x 0, y 0, z 0 ) Only the t  0 is the answer candidate Only the t  0 is the answer candidate The smallest positive t is the answer The smallest positive t is the answer

15 Ray Cast – The Plane Each triangle in the 3D models has its plane equation. Each triangle in the 3D models has its plane equation. Use ax + by + cz + d = 0 as the plane equation. Use ax + by + cz + d = 0 as the plane equation. (a, b, c) is the plane normal vector. (a, b, c) is the plane normal vector. |d| is the distance of the plane to origin. |d| is the distance of the plane to origin. Substitute the ray equation into the plane. Substitute the ray equation into the plane. Solve the t to find the intersect point. Solve the t to find the intersect point.

16 Solve the terrain height for the object to stand on. Solve the terrain height for the object to stand on. Use the triangular coordinate system Use the triangular coordinate system Find the next neighboring triangle Find the next neighboring triangle Half-edge data structure Half-edge data structure Terrain Following Using Triangular Mesh

17 Create cohesive relationship between triangles using “half edge” Create cohesive relationship between triangles using “half edge” Use half-edge table to search the neighboring triangles Use half-edge table to search the neighboring triangles Edge = two halves Half-edge (1/2)

18 struct HE_edge { HE_vert* vert; // vertex at the end of the half-edge HE_vert* vert; // vertex at the end of the half-edge HE_edge* pair; // oppositely oriented adjacent half-edge HE_edge* pair; // oppositely oriented adjacent half-edge HE_face* face; // face the half-edge borders HE_face* face; // face the half-edge borders HE_edge* next; // next half-edge around the face HE_edge* next; // next half-edge around the face }; }; struct HE_vert { float x; float x; float y; float y; float z; float z; HE_edge* edge; // one of the half-edges HE_edge* edge; // one of the half-edges // emantating from the vertex // emantating from the vertex }; }; struct HE_face { HE_edge* edge; // one of the half-edges bordering the face HE_edge* edge; // one of the half-edges bordering the face}; Half-edge (2/2)

19 Ray cast Ray cast Containment test Containment test Separating axes Separating axesIntersection

20 Intersection = 1, inside Intersection = 2, outside Intersection = 0, outside Trick : Parametric equation for a ray which is parallel to the x-axis x = x 0 + t x = x 0 + t y = y 0, t = 0, y = y 0, t = 0, { 8 (x 0, y 0 ) 2D Containment Test “if the No. of intersection is odd, the point is inside, otherwise, is outside” otherwise, is outside”

21 3D Containment Test “if the No. of intersection is odd, the point is inside, otherwise, is outside” otherwise, is outside” Same as the 2D containment test Same as the 2D containment test

22 Separating Axes For convex objects only For convex objects only If there is existing an axis (2D) or a plane (3D) to separate two convex objects, these two objects are not intersected. If there is existing an axis (2D) or a plane (3D) to separate two convex objects, these two objects are not intersected. How ? How ? Project the vertices of each object on the axis/plane that is perpendicular to axis/plane we are going to find. Project the vertices of each object on the axis/plane that is perpendicular to axis/plane we are going to find. Get the extreme of the projection area of each object. Get the extreme of the projection area of each object. If the projection are of these two object are not overlapped, the two objects are not intersected. If the projection are of these two object are not overlapped, the two objects are not intersected.

23 Separating Axes Algorithm for Convex Polyhedra (1/3) Bool TestIntersect(ConvexPolyhedron C0, ConvexPolyhedron C1) { // test faces of C0 for separation for (i = 0; i < C0.GetFaceCount(); i++) { D = C0.GetNormal(i); ComputeInterval(C0, D, min0, max0); ComputeInterval(C1, D, min1, max1); if (max1 < min0 || max0 < min1) return false; } // test faces of C1 for separation for (i = 0; i < C1.GetFaceCount(); i++) { D = C1.GetNormal(i); ComputeInterval(C0, D, min0, max0); ComputeInterval(C1, D, min1, max1); if (max1 < min0 || max0 < min1) return false; }

24 Separating Axes Algorithm for Convex Polyhedra (2/3) // test cross products of pairs of edges for (i = 0; i < C0.GetEdgeCount(); i++) { for (j = 0; j < C1.GetEdgeCount(); j++) { D = Cross(C0.GetEdge(i), C1.GetEdge(j)); ComputeInterval(C0, D, min0, max0); ComputeInterval(C1, D, min1, max1); if (max1 < min0 || max0 < min1) return false; } return true; }

25 Separating Axes Algorithm for Convex Polyhedra (3/3) void ComputeInterval(ConvexPolyhedron C, Vector D, double &min, double &max) { min = Dot(D, C.GetVertex(0)); max = min; for (i = 1; i < C.GetVertexCount(); i++) { value = Dot(D, C.GetVertex(i)); if (value < min) min = value; else if (value > max) max = value; }

Turn away from possible collision ( 避免可能的碰撞 ) Predict the potential collision ( 預估下一步的碰撞可能性 ) Use bounding spheres Unaligned Collision Avoidance Behavior ( 碰撞迴避 ) If possibly collide, ( 如果可能碰撞, 預估轉向力先行轉向 ) Apply the steering on both characters Steering direction is possible collision result Use “future” possible position The connected line between two sphere centers

27 Use bounding volume to improve the performance Use bounding volume to improve the performance Cylinder volume for characters Cylinder volume for characters Object-oriented bounding box (OBB) or bounding sphere for 3D models Object-oriented bounding box (OBB) or bounding sphere for 3D models Collision detection when the object/character is moving Collision detection when the object/character is moving Very game type oriented Very game type oriented Apply “Collision Avoidance” first, and then “Collision Detection” Apply “Collision Avoidance” first, and then “Collision Detection” Summary for Collision Detection