Download - Edward Powell Vectric Ltd
![Page 1: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/1.jpg)
ONLINE CONFERENCE
DESIGN.BUILD.DELIVERwith WINDOWS PHONE
THURSDAY 24 MARCH 2011
![Page 2: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/2.jpg)
Edward PowellVectric Ltd
@VeraShackle
XNA-UK Blog
3D Collisions
![Page 3: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/3.jpg)
Assumptions
• You have reasonable understand basic 3D rendering with BasicEffect, Components, Services and the Content Pipeline.
• You have had a crack at some 2D games• You have some ideas about the principles
2D collision detection.• You’re probably better at C# than me!
![Page 4: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/4.jpg)
Content
• 15 mins - A bit of theory• 15 mins - Building a simple, but flexible
system • 5 mins - The Full Isaac Newton!
![Page 5: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/5.jpg)
Elements of a collision system
• Collision detection– Have any objects collided?– Which object pairs have collided?– In what way have the objects collided?
• Collision Resolution– Simple event?– Complex interaction?– Correcting for detection lag?
![Page 6: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/6.jpg)
Collision Detection
![Page 7: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/7.jpg)
Discrete time step between checks
• The actual moment of collision is never going to coincide with the checking algorithm.
• So Two Options:– Look forward to find collisions about to occur
• Complex interactions, complex algorithm• Never quite sure when the next check will be
– Look back at collisions that have already occurred• Simple algorithm (relatively!)• Know time since the last check• But, have to correct things that have already occurred
![Page 8: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/8.jpg)
Looking back (hopefully not in anger)
• Things to watch out for:– Some overlap already at the point of
detection- ‘Drill through’...– Complete containment – boundaries no
longer intersect• Swept volumes?
– Multiple apparently ‘simultaneous’ collisions
![Page 9: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/9.jpg)
Have objects collided – the lessons from 2D?
• Pixel perfect collision was too expensive– We checked for overlapping bounding
rectangle or circle – Multiple collision shapes per object– Use hierarchy of collision areas to reduce
the pixel perfect search to a manageable area
![Page 10: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/10.jpg)
![Page 11: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/11.jpg)
Same principles apply in 3D - Especially under WP7!
• triangle-triangle is the new pixel perfect!• Same solutions, but replace 2D areas
with 3D entities...
![Page 12: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/12.jpg)
Collision Entities
• XNA Intrinsics– BoundingBox (AABB)– BoundingFrustum– BoundingSphere– Plane– Ray– Model (via spheres)
• Other common ones– Capsule – swept volumes– Oriented Bounding Box (OBB)– Height map– ‘Slabs’– Discrete Oriented Polytopes (DOP)!!– Triangle Mesh
![Page 13: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/13.jpg)
Reduced Poly Collision Skin
![Page 14: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/14.jpg)
Collision Primitives Summary...
• We don’t need a one-to-one mapping of collision primitive to drawable object
• Several simple volumes is generally cheaper than a single more complicated one.
• We can still do high-accuracy collision tests, but limit the volume with cheaper tests first.
(Image Source: http://sharky.bluecog.co.nz )
![Page 15: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/15.jpg)
Pruning the Collision Search Space
• Brute force• Refining Bounding Volumes• Sweep & Prune (SAP)
– Insertion sort, relies on the fact that objects tend to be in a similar state between time steps.
• Grid Registration• BSP, kd-tree, quad-tree , oct-tree...
![Page 16: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/16.jpg)
Collision Resolution
Wotcha gonna do about it...
![Page 17: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/17.jpg)
Approaches to Resolvers
• Distinct Resolver Class– Single location for all your resolution code– Needs to be modified as new entities are added– What collision information is needed?
• Entities Resolve their own collisions– Collision entities are self-contained– Entities need to ‘know’ about at least some
others– Easily extensible
![Page 18: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/18.jpg)
How much information do you need about the collision?
• When did the collision occur?• Which point (or points) contacted?• Other significant properties of the
object?– Velocity– Mass– Angular Momentum, coefficient of
restitution... etc. etc.!
![Page 19: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/19.jpg)
Implementation
• Simple Collision Manager Component– Brute force check each update for...
• ICollidable Interface– Collision check– Collision resolution
• 2 Basic Classes:– CollidableSphere– CollidablePlane
![Page 20: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/20.jpg)
Implementation
![Page 21: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/21.jpg)
Simple start, but...
• Bounding Spheres are calculated by the pipeline for meshes
• Discrete Oriented Polytope (DOP) – defining convex volumes using only planes.
(Image Source: epicgames.com)
![Page 22: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/22.jpg)
Defining a volume with Planes
![Page 23: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/23.jpg)
Has a sphere collided with a plane?
Distance = Plane.DotCoordinate(sphere.Centre)
1. If the distance is positive, the sphere is in front of the plane
2. If the distance is negative, the sphere is behind the plane
3. If the distance from the plane is less than the radius of the sphere - COLLISION
![Page 24: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/24.jpg)
Collision with Volume
In front of 1 plane, but intersecting 0. No collision
In front = 2Intersecting = 0No Collision
In front = 2Intersecting = 1No Collision
Rule: Must be intersecting all the planes we’re in front of...?
![Page 25: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/25.jpg)
Collision with Volume
In front = 1Intersecting = 1COLLISION
In front = 2Intersecting = 2COLLISION
Rule: Must be intersecting all the planes we’re in front of...?
In front = 0COLLISION
![Page 26: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/26.jpg)
Volume Edges & Corners
In front = 2Intersecting = 2But no collision
![Page 27: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/27.jpg)
Simple Collision System Demo
http://www.youtube.com/watch?v=5Xe2twpDe_8
XNACollisions_1
Duration: 1:14s
![Page 28: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/28.jpg)
Using a Full Physics Engine
• Examples– Jitter (jitter-physics.com)
• Full & free use of dll• Source code access US$400
– BEPUPhysics (www.bepu-games.com) • Free for non-commercial use• Open Source as of last week!!
– JigLibX (jiglibx.codeplex.com)• Free• Open-source
![Page 29: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/29.jpg)
JigLibX Phyics Demo
http://www.youtube.com/watch?v=Sc7XOJgCVdc
XNACollisions_2
Duration: 1:00s
![Page 30: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/30.jpg)
Thank You for attending today’s Tech.Days Online Conference.
Today’s Online Conference will be recorded. It will be made available on-demand very soon.
Your Feedback Matters! Please complete the online evaluation form which will be emailed to you.
![Page 31: Edward Powell Vectric Ltd](https://reader034.vdocuments.us/reader034/viewer/2022050802/56816381550346895dd46534/html5/thumbnails/31.jpg)
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
ONLINE CONFERENCE