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

SAT collision detection for oriented bounding boxes (in 3D)

0 posts in this topic

AABB aren't that difficult to deal with, but I'm having one heck of a time implementing oriented bounding regions (rectangular prisms) in 3-space. My current algorithm is an extension of my understanding of the separated axis theorem (SAT) method, but unfortunately the only discussion I've heard of it so far was related to 2-space. The algorithm I use is to first compute the 8 vertices ("points" in code) and 12 edges (point[i]-[/i]point[k]) as vectors. I find an axis perpendicular to the edge using the cross product of the edge vector and the shortest principle axis (code below), and project each point of both colliders onto the result. This "projection" is then used to compute the minimum and maximum bounds (as per the SAT method). Last I check if the bounds of each collider overlap. If they do, I continue with SAT and use the axis as a direction vector and the magnitude of the lowest overlap as the magnitude of the separating vector. If any do not overlap, the test ends.

It all sounds good and well, but I've made at least one serious error in my code because its behavior is sporradic. I do not get false positives, but the separating vector is never the shortest and testing some collider a vs b yields true but b vs a yields false (so, for instance, this algorithm always returns false unless I do NOT swap a and b in the first for loop but can return true if I don't) and rarely sufficient for separation (it's slightly too short). I'm not sure where I'm going wrong, either.

The root of the problem:
[code]
bool Collider::collisionCheck(ColliderPtr other,Vec3* separation){
getPoints();//update points
other->getPoints();//also update OTHER's points
F64 overlap=10000;//10000 is an arbitrarily large number. No collision should ever occur at this range.
//for every edge on EACH collider, get the axis, compute the bounds, and compare. If no overlap, return FALSE.
Collider* col[2] = {this,other.get()};//simplifies code by reducing duplicates. "this" = col[0], "other" = col[1]
for(U8 n=0;n<2;n++){
U8 a=n,b=-1*(n-1);//flip between a,b = 1,0 and 0,1 to eliminate redundant code
for(U8 i=0;i<12;i++){
AxisEdge axis = col[a]->getAxisEdge(i,true);//get the axis of the i'th edge
//project bounds onto 1d axis
F64 max=-10000,omax=-10000,min=10000,omin=10000,projection;
for(U8 j=0;j<8;j++){
projection = axis.project(col[a]->points[j]);//project the j'th point onto the axis
if(projection
min = projection;
if(projection>max)
max = projection;
}
//project other bounds onto 1d axis
for(U8 k=0;k<8;k++){
projection = axis.project(col[b]->points[k]);//project the k'th point onto the axis
if(projection
omin = projection;
if(projection>omax)
omax = projection;
}
//check and report overlap
if(omin>=min&&omin<=max){
if(separation!=NULL&&overlap>=max-omin){
overlap = max-omin;
(*separation)=axis.axis.normal()*overlap;
}
}else if(omax>=min&&omax<=max){
if(separation!=NULL&&overlap>=omax-min){
overlap = omax-min;
(*separation)=axis.axis.normal()*overlap;
}
}else
return false;//Separation = no collision
}
}
return true;
}[/code]

The principle axis method for computing an edge's axis. Note that edge is the aforementioned point[x]-point[y] vector.
[code]Vec3 AxisEdge::perpendicular(void){
Vec3 principle;
F64 min = std::min(edge.x,std::min(edge.y,edge.z));
if(compared(min,edge.x))
principle = Vec3(1,0,0);
else if(compared(min,edge.y))
principle = Vec3(0,1,0);
else
principle = Vec3(0,0,1);
return (edge%principle).normal();
}[/code]

I can provide any of the functions mentioned in the code. Also note that Vec3 operator% is the cross product of two vectors, while compared is a simple function that returns if abs(a-b)<1E-14?true:false.

I really appreciate any help on the matter, or any links that might be informative. I hope I've been clear, and I'll gladly clarify any points which I've left ambiguous. Thank you for your time and assistance.

Edit: After considerable consideration and experimentation, I believe the problem is with the axis selection code itself. While "any" perpendicular vector works in 2D (since there is only one and its parallels/opposites), it seems like only a limited set of orthogonal vectors are useful for ascertaining the direction of separation. Thus, the collision detection portion works, but causes the separation vector to be wrong in some cases, which is why separation fails, does not follow the shortest route, or behaves unexpectedly. Unfortunately, in every discussion on the topic I find, they simplify the problem by explaining it in 2D, which isn't helpful for axis selection in 3D. At least, as I understand it.

I have tried grouping the different edges by face, and using the normal of that face as the orthogonal vector to the edge. On half the edges, this works well. On the other half, the problem persists and the separation does not follow the shortest path (sometimes taking even the [i]longest path[/i]). Is there a way to intelligently chose these orthogonal vectors?

Edit: I've resolved this issue, but thank you for reading. If anyone has questions, I'll gladly post the code that resolved the situation, or explain the logic I used to arrive at the solution. Thanks again, even if it was just for reading.
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