Solved

Create an oriented bounding box from vertices

Posted on 2009-05-04
5
1,657 Views
Last Modified: 2013-12-17
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?

Thanks in advance.
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);

                }

Open in new window

0
Comment
Question by:Snapples
  • 3
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
ikework earned 500 total points
Comment Utility
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

by:Snapples
Comment Utility
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

by:ikework
Comment Utility
ok i see .. did you try the covariance-matrix yet?
0
 
LVL 2

Author Comment

by:Snapples
Comment Utility
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

by:ikework
Comment Utility
great to hear that .. good luck .. :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now