Download presentation
Presentation is loading. Please wait.
Published byBrook Pitts Modified over 9 years ago
1
Computer Game Design and Development Collision Detection Havok Destruction
2
Overlap Bisection
3
Limitations of Overlap Testing
4
Intersection Testing
5
Collision Approximations Minkowski Sum – sweep origin of X across Y
6
Performance Possible collision between R and B since overlap in all axis (2 in this case) Subdivide such that on average one object in each cell.
7
Per-Pixel Collision // The color data for the images; used for per-pixel collision Color[] personTextureData; Color[] rocketTextureData; // Load textures rocketTexture = Content.Load (“Rocket"); personTexture = Content.Load ("Person"); // Extract collision data rocketTextureData = new Color[rocketTexture.Width * rocketTexture.Height]; rocketTexture.GetData(rocketTextureData); personTextureData = new Color[personTexture.Width * personTexture.Height]; personTexture.GetData(personTextureData); http://creators.xna.com/en-US/tutorial/collision2dperpixel
8
Per-Pixel Collision (cont) static bool IntersectPixels(Rectangle rectangleA, Color[] dataA, Rectangle rectangleB, Color[] dataB) { // Find the bounds of the rectangle intersection int top = Math.Max(rectangleA.Top, rectangleB.Top); int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom); int left = Math.Max(rectangleA.Left, rectangleB.Left); int right = Math.Min(rectangleA.Right, rectangleB.Right); // Check every point within the intersection bounds for (int y = top; y < bottom; y++) for (int x = left; x < right; x++) { // Get the color of both pixels at this point Color colorA = dataA[(x - rectangleA.Left) + (y - rectangleA.Top) * rectangleA.Width]; Color colorB = dataB[(x - rectangleB.Left) + (y - rectangleB.Top) * rectangleB.Width]; // If both pixels are not completely transparent, if (colorA.A != 0 && colorB.A != 0) // then an intersection has been found return true; } // No intersection found return false; }
9
Bounding Volumes AABBOBB
10
Terrain Collision Heightmap information Look up terrain height 3 LERPs – Linear Interpretation between points – X – Z – Between x and z http://creators.xna.com/en-US/sample/collision3dheightmap
11
Resolving Collision Gross collision & subdivide if needed Three phases – Prologue – ignore or trigger other events – Collision – point of impact, new velocities – Epilogue – destroy object, effects, damage
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.