• 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
Nokobon

Separating axis test and distance calculation

9 posts in this topic

Hello,

I implemented a separating axis test for 3D collision detection with oriented bounding boxes.
I can get the collision depth by looking for the minimum overlap on the axes.

Now I also need to get the distance of non colliding boxes but I can't figure out if there is a way to calculate it from the projections of the separating axis test.

So is there a way which uses the available data from the separating axis test or do I have to implement a distance calculation algorithm separately?

I would be glad if you have any ideas...
0

Share this post


Link to post
Share on other sites
Is this what you want?

[code]sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))[/code]
0

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1336418857' post='4938157']
Its the minimum positive separating axis distance, isn't it?
[/quote]

No, it's not. Think of the boxes [x1, x1+e] x [y1, y1+e] x [z1, z1+e] and [x2, x2+e] x [y2, y2+e] x [z2, z2+e]. The limit of the distance between them when e -> 0 has to be sqrt(pow(x1-x2, 2) + pow(y1-y2, 2) + pow(z1-z2, 2)). Edited by alvaro
0

Share this post


Link to post
Share on other sites
Ahh yes, of course - I'd forgotten it worked differently for separation compared with penetration. With separation you need to account for more than just the separating axis themselves, you also need to account for the geometry of the faces and edges.

Penetration is different because you only need to worry about the actual axis formed by the faces of both objects and the cross-products of the edges.

In this article I wrote, you can see the problem you need to address:

[url="http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/"]http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/[/url]

Scroll down to the section on OBB vs OBB - there is a little applet demonstrating the difference I was describing. The axis is shown as the line from the centre of the applet to a face on B-A. When this axis is aligned with a face of A or B, the minimum distance is aligned with a separating axis. However, when that axis is not aligned, the distance is actually that of two vertices. In 3d there is vertex vs vertex and edge vs edge distance as well.

Hope that helps!

Cheers, Paul.
0

Share this post


Link to post
Share on other sites
Thanks for your ideas.

[quote name='alvaro' timestamp='1336411199' post='4938116']
Is this what you want?

[code]sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))[/code]
[/quote]

I think this only works for axis-aligned bounding boxes? I use oriented bounding boxes...

[quote name='wildbunny' timestamp='1336425074' post='4938191']
Ahh yes, of course - I'd forgotten it worked differently for separation compared with penetration. With separation you need to account for more than just the separating axis themselves, you also need to account for the geometry of the faces and edges.

Penetration is different because you only need to worry about the actual axis formed by the faces of both objects and the cross-products of the edges.

In this article I wrote, you can see the problem you need to address:

[url="http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/"]http://www.wildbunny...on-for-dummies/[/url]

Scroll down to the section on OBB vs OBB - there is a little applet demonstrating the difference I was describing. The axis is shown as the line from the centre of the applet to a face on B-A. When this axis is aligned with a face of A or B, the minimum distance is aligned with a separating axis. However, when that axis is not aligned, the distance is actually that of two vertices. In 3d there is vertex vs vertex and edge vs edge distance as well.

Hope that helps!

Cheers, Paul.
[/quote]

Interesting approach. This might be a good solution for the problem but it would require a whole new implementation and I could discard my separating axis test.

My main question is:
Is the distance parallel to on of the 15 axes as if the penetration depth?
If so I could use the separating axis test results to calculate it...
0

Share this post


Link to post
Share on other sites
[quote name='Nokobon' timestamp='1336470342' post='4938330']
Thanks for your ideas.

[quote name='alvaro' timestamp='1336411199' post='4938116']
Is this what you want?

[code]sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))[/code]
[/quote]

I think this only works for axis-aligned bounding boxes? I use oriented bounding boxes...
[/quote]

You are right. The word "oriented" threw me off: I thought an arbitrary bounding box would just be called a "bounding box". After a quick web search I see that your name is perfectly common.

I am pretty sure you cannot deduce the distance between two boxes from the projections alone, but perhaps there is something else I don't understand, since you seem to be testing 15 axes, and I can only think of 6 that matter. Would you mind explaining where the 15 axes come from?
0

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1336477315' post='4938345']
You are right. The word "oriented" threw me off: I thought an arbitrary bounding box would just be called a "bounding box". After a quick web search I see that your name is perfectly common.

I am pretty sure you cannot deduce the distance between two boxes from the projections alone, but perhaps there is something else I don't understand, since you seem to be testing 15 axes, and I can only think of 6 that matter. Would you mind explaining where the 15 axes come from?
[/quote]

6 axes: face-normals of both boxes
9 axes: pairwise crossproducts of distinct edges of both boxes (3*3)

The projection of the boxes needs to be done on these 15 axes. If on at least one of them the projections don't overlap, there is a plane that separates both boxes.
If the projections overlap on all axes, the boxes intersect, too. The penetration depth is the smallest overlap on an axis. So the minimum translation vector to get out of the collision is parallel to the axis with the smallest overlap.

The problem is, that the smallest distance between two non-intersecting boxes is not necessarily parallel to one of the 15 axes (e.g. when the minimum distance is between two vertices).

So I don't know if there is a way to deduce the distance from the projections... Edited by Nokobon
0

Share this post


Link to post
Share on other sites
[quote name='Nokobon' timestamp='1336470342' post='4938330']
Interesting approach. This might be a good solution for the problem but it would require a whole new implementation and I could discard my separating axis test.

My main question is:
Is the distance parallel to on of the 15 axes as if the penetration depth?
If so I could use the separating axis test results to calculate it...
[/quote]

No the distance isn't parallel to a separating axis in all cases - you can see that in the demo when the vertices of the two OBBs are the closest features.
0

Share this post


Link to post
Share on other sites
[quote name='Nokobon' timestamp='1336483103' post='4938364']
6 axes: face-normals of both boxes
9 axes: pairwise crossproducts of distinct edges of both boxes (3*3)
[/quote]
Thanks, that makes sense.

I think wildbunny is right and you won't be able to measure distance based on the 15 projections.
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