Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Create an oriented bounding box from vertices

Posted on 2009-05-04
Medium Priority
1,728 Views
Hi there,

I'm doing this in XNA but it shouldn't be too different in DirectX
I'm getting the vertices of a box mesh from the vertexbuffer, now from those vertices I'd need to recreate that box as an oriented bounding box.
This is my code, in transformedvertices my vertices are stored in world space, a total of 24, now I'd need to be able to turn that into an oriented bounding box.
Anyone have any ideas?

``````ModelMeshPart part = modelmesh.MeshParts[j];
n = part.NumVertices;

VertexPosition[] vertices = new VertexPosition[part.NumVertices];

modelmesh.VertexBuffer.GetData<VertexPosition>(part.BaseVertex * part.VertexStride, vertices, 0, part.NumVertices, part.VertexStride);

int t = MySkinnedModel.SkeletonBones.Count;
string[] names = new string [t];

for (int p = 0; p < t; p++)
{
names[p] = MySkinnedModel.SkeletonBones[p].Name.ToString();
}

Vector3[] transformedvertices = new Vector3[(part.NumVertices)];

Matrix transformmatrix = MyAnimationController.SkinnedBoneTransforms[0];

for (int i = 0; i < part.NumVertices; i++)
{
transformedvertices[i] = Vector3.Transform(vertices[i].Position, transformmatrix);
}
``````
0
Question by:Snapples
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 20

Accepted Solution

ikework earned 1500 total points
ID: 24302428
hi Snapples,

this might be interesting for you:

http://codesuppository.blogspot.com/2006/06/best-fit-oriented-bounding-box.html

another technique is to compute a covariance-matrix of the point-cloud to compute the bounding box.

ike
0

LVL 2

Author Comment

ID: 24325501
Thanks for the link, I hadn't seen that one yet. Unfortunately it's of no use to me, I should have mentioned this. The bounding box surrounds part of an animated mesh, so the box has to be updated every frame. The code in your link is too performance heavy to run every single frame.
0

LVL 20

Expert Comment

ID: 24326621
ok i see .. did you try the covariance-matrix yet?
0

LVL 2

Author Comment

ID: 24347474
I found the solution I needed.

In my OBB class, I have a global Vector3[24] array, in the constructor I fill it with the VertexBuffer of my mesh. I also have an Edge and a Quad struct, which has 2 and 4 short values in which I store the IndexBuffer values of the edges and faces. So basically storing every vertex, edge, face and quad with a minimum of data. Every frame I just have to transform the Vector3 array with the transformation matrix of the bone.
Then to check for collision I check if any of the edges of box1 collide with any faces of box2.

But thank you ike, I did get a lot of help from that first link you posted.
0

LVL 20

Expert Comment

ID: 24348308
great to hear that .. good luck .. :)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month11 days, 16 hours left to enroll