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

Constructing min/max corners of a collision mesh

7 posts in this topic

Hello,
 
I'm having a bit of trouble with constructing the minimum and maximum corners of a collision mesh. I think it's best to explain what steps I'm going through:
 
1) load 3D mesh, assign a world matrix to it (translation, rotation), assign bounding box half extents
2) when a specific event happens in application, generate a 3D bounding box for the mesh using previously defined half extents. This is mainly for debugging as I'm filling the volume defined by this mesh with smaller cubes later. For rendering I'm  generating a cuboid mesh centered around (0,0,0) with the half extents and assign the same world matrix as the original mesh. Rendering this shows the mesh is in the correct place.
3) Now I need to check for collisions only on the xz-plane. To do this, I "construct" a cuboid from min/max corners and transform that to the position of the mesh. Now here is the problem though: I don't know how/where I'm going wrong but the min/max corners don't seem to be right. For example:
mesh half extents on xz (1.05, 0.5) -> constructed min = (-4, -3.5) and max = (-5, -1.45). How can min.x > max.x?
 
Here's the relevant code bit (broadCollisionMeshExtents == half extents):
 
D3DXMATRIX wMat = linkedObj.object->GetWorldMatrix();
D3DXVECTOR2 extents(linkedObj.broadCollisionMeshExtents->x, linkedObj.broadCollisionMeshExtents->z);
 
D3DXVECTOR3 minimum = D3DXVECTOR3(-extents.x, 0.0f, -extents.y);
D3DXVECTOR3 maximum = D3DXVECTOR3(extents.x, 0.0f, extents.y);
D3DXVECTOR4 min4;
D3DXVec3Transform(&min4, &minimum, &wMat);
D3DXVECTOR4 max4;
D3DXVec3Transform(&max4, &maximum, &wMat);
 
minimum = D3DXVECTOR3(min4);
maximum = D3DXVECTOR3(max4);
 
This seems to work as long as the objects don't have any rotation on them. I can sort of force-fix it by doing:
 
float maxX = maximum.x;
float maxZ = maximum.z;
float minX = minimum.x;
float minZ = minimum.z;
maximum = D3DXVECTOR3(max(maxX, minX), 0.0f, max(maxZ, minZ));
minimum = D3DXVECTOR3(min(maxX, minX), 0.0f, min(maxZ, minZ));
 
... but that's just silly. I'm not entirely sure as to what is going on, any help would be greatly appreciated.
 
Thanks in advance!
Edited by dr4cula
0

Share this post


Link to post
Share on other sites

General approach is to construct Axis Aligned Bounding Box, that gets transformed to world space if examination is needed. You compute the object space AABB only once, by a trivial aproach of finding minimum and maximum verticies on particular axises of object space. You are then left of transforming only 8 corners.

1

Share this post


Link to post
Share on other sites
 

General approach is to construct Axis Aligned Bounding Box, that gets transformed to world space if examination is needed. You compute the object space AABB only once, by a trivial aproach of finding minimum and maximum verticies on particular axises of object space. You are then left of transforming only 8 corners.

 

What exactly do you mean by trivial approach of finding min and max vertices? Not quite sure I'm following you...

 

 


How can min.x > max.x?

Rotation.

 

 

Hm... Is my rejection code then wrong?

auto InMesh = [minimum, maximum](const D3DXVECTOR3& cellCenter) -> bool {
if(cellCenter.x < minimum.x) return false;
if(cellCenter.x > maximum.x) return false;
if(cellCenter.z < minimum.z) return false;
if(cellCenter.z > maximum.z) return false;
 
return true;
};

CellCenter is a center point (in world space) of a quad on the xz-plane.

 

Thanks in advance once more.

Edited by dr4cula
0

Share this post


Link to post
Share on other sites

Apparently the world matrix you're using rotates the mesh. If you rotate x1 = -4 and x2 = -5 by some value, you shouldn't expect the values to remain the same. E.g., if x-values -4 and -5 are rotated 180 degrees about the y axis, they become +4 and +5 respectively. -4 is greater than -5, but +4 is less than +5. If you want mins and maxes to be world values, you have to evaluate them after they're placed in the world, not before.

1

Share this post


Link to post
Share on other sites

Apparently the world matrix you're using rotates the mesh. If you rotate x1 = -4 and x2 = -5 by some value, you shouldn't expect the values to remain the same. E.g., if x-values -4 and -5 are rotated 180 degrees about the y axis, they become +4 and +5 respectively. -4 is greater than -5, but +4 is less than +5. If you want mins and maxes to be world values, you have to evaluate them after they're placed in the world, not before.

 

'WorldMatrix' is concat of object matrix and world matrix but since world matrix is identity, then it is essentially an object matrix. How would I do these evaluations in world space then? I thought that my multiplication by the object matrix places it inside the world space - does it not? What I mean is, doesn't the multiplication put the min/max aligned with the mesh and centered around the mesh's origin?

Edited by dr4cula
0

Share this post


Link to post
Share on other sites

I thought that my multiplication by the object matrix places it inside the world space - does it not?

 

Yep, exactly. But that's after you've set the half-extent values, calling them min/max. Those min/max values describe the box in box space, not world space.

 

The code you posted before this comment:

 

 

 


but that's just silly.

 

is, in fact, evaluating the box after you've applied the rotation, as suggested, which is why that fixes the situation.

 

Think about the situation I mentioned in my previous post. If you rotate the box, the most negative (minimum) corner won't remain as the most negative. Just because you named it minimum, doesn't make it the minimum values. If you, for instance, just called the extent values "corners," and the minimum/maximum vectors "currentMin/Max," it might make more sense to you.

Edited by Buckeye
2

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