• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
janzdott

EPA (Expanding Polytope Algorithm)

2 posts in this topic

Hello.  I recently implemented the GJK algorithm for collision detection in my 3D engine, basing my implementation on a great video located here.  The algorithm is robust, and seems to work for all convex objects and all cases so far.  Now I need to determine the contact point, normal, and penetration depth of the collision.  EPA seems like a good algorithm for this, because it uses the same principles of the Minkowski Sum and support mappings that GJK does.

 

Here are the only two resources I have been able to find that give much detail about EPA...

http://graphics.stanford.edu/courses/cs468-01-fall/Papers/van-den-bergen.pdf

http://uu.diva-portal.org/smash/get/diva2:343820/FULLTEXT01

 

The idea behind EPA is very simple.  It starts with the tetrahedron simplex that GJK terminates with.  It then projects the origin onto each triangle of the simplex.  Lets call this point v.  It then finds the triangle whose v is closest to the origin, and calls the support function using v as the direction.  The triangle is subdivided, and new triangles are creating using the result of the support function as a new vertex.  This is repeated over and over, so the algorithm essentially expands the simplex inside the Minkowski Sum.  Once the distance between v and the support point is less than a certain threshold, we have found the penetration depth, and can easily determine the contact point and normal.

 

The only issue I'm having with EPA is the subdivision of the triangles.  The only two resources I've found give two completely different methods for subdivision....

 

The first says to subdivide the edges of the triangle and use the support point to create 6 new triangles.  The problem with this is, what the hell do you do with the adjacent triangles?  They will have to be subdivided too, or else the mesh will have holes in it.  This is a very ugly problem to solve, and he does not give much detail about the rest of the subdivision process.

 

The second one gives a more detailed explanation, but is completely different.  Instead of subdividing the single triangle, we find every triangle whose normal is facing toward the support point.  We then delete all of those triangles, and then create new triangles that all converge at the support point to fill the hole.  This is what I'm trying to implement right now.  It just doesn't seem like it would be very efficient.  EPA is an iterative algorithm, and this must be done many times per frame.

 

I've looked and looked, and those were the only two decent resources I could find, and I cannot come up with a better method myself.  Bullet uses EPA and I've looked at their source code, but it's utterly unreadable.  So my question is, does anybody who has experience with EPA the best way of doing this?  Or can anybody point me to a place with a different method?  I'm not sure who came up with EPA, and I'm unable to find an official paper from the original author documenting the correct way to do it.  Any help would be greatly appreciated.

 

Edit:  I'm using method two now, and now I understand the methods they use to make it more efficient.  I will post an explanation of the algorithm with sample code when I'm done

Edited by janzdott
1

Share this post


Link to post
Share on other sites

I think EPA was introduced by Gino v.d. Bergen. Personally I find it very difficult to make it numerically stable. The other issue you need to deal with is when GJK terminates with a simplex that is not a tetrahedron or even only gives you a fuzzy answer whether it is just very close or penetrating. I recommend testing objects with very different dimensions to see if you run into problems. In practice people use a brute-force fallback where they sample a fixed number possible directions on a unit sphere if things go bad. And they will go bad...

 

So why not use SAT instead?

Edited by Dirk Gregorius
0

Share this post


Link to post
Share on other sites

My GJK implementation always terminates with a tetrahedron simplex if there is a collision, so that's not a problem.  I almost have EPA working now.  I added debugging code to draw the polytope and let me go through the algorithm step by step while rotating the view to inspect the polytope and make sure everything is working correctly.  It expands the polytope correctly for several iterations, and then I start getting incorrect triangle normals.  I'm almost positive I handle the triangle windings correctly, but I'll keep checking to find out what the problem is.  As for the numerical stability...  This is my first time writing a physics engine, so I don't expect everything to work 100% all the time laugh.png

 

And I've never actually looked into using SAT in 3D.  How is the performance?  Does it work curved shapes?  And does it compute the contact info?

 

Edit:  I got it working now.  It finds the correct penetration depth and normal.  It seems to work very well.  I've tested it with boxes and spheres of different sizes.  I'll add other types of shapes soon.  The only thing I'm confused about is how to find the contact points relative to each object

Edited by janzdott
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0