XNA Game Development Forums
2012/05/18 06:16:24 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1] 2
  Print  
Author Topic: Detecting Model Collision...?  (Read 4277 times)
DaphydTheBard
Jr. Member
**
Offline Offline

Posts: 55


View Profile
« on: 2007/03/02 07:09:29 »

Hey Guys

My own game engine is coming along very nicely now, I have pretty much all the "core" stuff in place that I will need (shaders, textured quads, models, cameras etc, all with manager classes where appropriate).

There is however a topic for which I have absolutely no knowledge, and was wondering if one of you guys here could point me in the right direction, or at least throw some hints my way to get me started Smiley

My engine has reached a point now where I need to implement some model collision detection code.  For "common" objects like fighters, asteroids, and laser blasts, I can do this by simply writing a function to check the distance between the objects and factor in the scale of the object.

However for more complex objects, like starbases, capital ships, etc. this method won't work.  I need to be able to accurately detect when the actual mesh data from each object collides.  I have *no* idea how to even start doing this.

Throw me a bone, someone?
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #1 on: 2007/03/02 16:35:25 »

Simplest way is to generate a BoudingBox/Sphere for your objects and when you update, just do your checks to see if they intercept. I guess the Octtree helps here as well, as you can limit the number of checks per update.
Logged

DaphydTheBard
Jr. Member
**
Offline Offline

Posts: 55


View Profile
« Reply #2 on: 2007/03/03 01:13:06 »

Hmm..

Only problem with doing it this way is that a lot of my larger objects will be odd shapes, such as stations.  I want to be able to fly up pretty close to objects like stations (especially for things like docking), and fly "through" the empty space between station sections.  so I really need to implement some way of detecting collisions for actual mesh data.    Is this possible with XNA?
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #3 on: 2007/03/03 02:33:27 »

Your meshes come with a boundingshpere, use that to get the mesh's volume then subdivide it into smaller spheres to better represent the shape of the mesh....
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #4 on: 2007/03/03 06:11:45 »

yeah, if you custom create your model, split it up into different "objects" in your modelling program before exporting, and then write a custom processor that generates a bounding sphere or box for each smaller "object". For more information on getting the smaller objects and possibly their names from model, a video was done by the XNA team before beta, and that had them writing a custom importer and doing stuff to a child object inside the model.
Logged

Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #5 on: 2007/03/03 12:02:53 »

ooooh, now that sounds cool, do you have a link Chr0n1x?
Logged
EclipsE
Full Member
***
Offline Offline

Posts: 111


View Profile
« Reply #6 on: 2007/03/03 17:01:14 »

Well, i just found out that every mesh part has it's own bounding sphere. How to make a mesh in parts, is not my specialty, but you can access all the parts. Example:

Code:
foreach (ModelMesh modelMesh in model.Meshes)
{
     modelMesh.BoundingSphere   //there is your bounding sphere, the rest is all up to you
}

So you can use the bounding spheres to check if they intersect...
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #7 on: 2007/03/03 17:39:54 »

I am currently using the following property with my HM flavor models:

Code:
        public BoundingSphere ObjectBoundingSphere
        {
            get
            {
                BoundingSphere bs = new BoundingSphere(myModel.Meshes[0].BoundingSphere.Center + myPosition, myModel.Meshes[0].BoundingSphere.Radius);
                return bs;
            }
        }

and it seems to be working quite well at the moment.

to see if two models collide I use this:

Code:
if (MyModel.ObjectsBoundingSphere.Intersects(OtherModel.ObjectsBoundingSphere))
    ... collision code...

Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #8 on: 2007/03/03 23:54:18 »

Here: http://blogs.msdn.com/xna/archive/2006/08/29/730168.aspx
Logged

DaphydTheBard
Jr. Member
**
Offline Offline

Posts: 55


View Profile
« Reply #9 on: 2007/03/05 04:03:47 »

Cool, cheers guys.

I'll bear all this in mind and see what I can come up with.

Logged
Tiago
Newbie
*
Offline Offline

Posts: 42


View Profile
« Reply #10 on: 2007/03/08 22:18:47 »

you should still use a "global" bounding sphere to detect if your ship is close enough to the station to check for more detailed colitions. that way if your ship is far away from your station you wont waste procesor time checking for more detailed colitions that you know cant happen
Logged
LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #11 on: 2007/03/19 00:59:10 »

How can I update the bounding box with the position of the actual mesh? I have spheres and the right size box, but it's default is the centter of the model and I need to update it with the correct location of the mesh.
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #12 on: 2007/03/19 02:34:31 »

I use this Property in my engine.

Code:
        public BoundingBox ObjectsBoundingBox
        {
            get
            {
                BoundingBox bb = new BoundingBox(myBounds.Min + myPosition, myBounds.Max + myPosition);
                return bb;
            }
        } 
Logged
LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #13 on: 2007/03/19 11:51:09 »

Im using a method that updates the bounds of the box. im passing arrays to it, i've done it several ways but I still get the same default center of world space.

I know how to move a bounds with the player objects. But the platform dosen't move and I don't always know the coordinates of the mesh because the level would be different. When i create a box with the mesh, it is in the default center of the levels location 0,0,0. I believe it's the right size but in the wrong spot. I am using .fbx files for the levels because im able to cycle through seperate meshes that way.

Is their a way to find the coordinates of each mesh from a model loaded into world space? Then move the bounding box to that location?
« Last Edit: 2007/03/19 13:39:01 by LucianX » Logged
Aglet
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #14 on: 2007/03/26 23:51:04 »

I use this Property in my engine.

Code:
        public BoundingBox ObjectsBoundingBox
        {
            get
            {
                BoundingBox bb = new BoundingBox(myBounds.Min + myPosition, myBounds.Max + myPosition);
                return bb;
            }
        } 

How do you get the

Code:
myBounds.Min
and
Code:
myBounds.Max
?
I've been struggling with this for long now. My models consists of one big mesh so I can't use several bounding spheres because there are just one mesh to enclose.

Struggling with this and would appreciate the help.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tut 6: Model Class Hazy Mind XNA Engine MicahN 2 2258 Last post 2006/11/15 09:43:47
by MicahN
Tutorial 6 :: Getting a Model on Screen Tutorial Discussion mikeschuld 11 5582 Last post 2007/02/18 10:35:28
by Iarus
How To: Render a model with a texture?? Hazy Mind XNA Engine Quinn 6 2323 Last post 2007/01/07 00:33:58
by mikeschuld
Terrain Traversing/Collision Hazy Mind XNA Engine Quinn 1 1604 Last post 2007/02/28 00:27:04
by Ardman
Climbing stairs with collision detection Hazy Mind XNA Engine internetking 8 3786 Last post 2007/03/19 16:32:35
by mikeschuld
Model exporters General Discussion EclipsE 13 3719 Last post 2007/04/26 12:25:03
by EclipsE
Loading a model in runtime? General Discussion XNASorcerer 10 3303 Last post 2007/05/06 21:22:42
by XNASorcerer
Has anybody managed to get some collision in the game? Hazy Mind XNA Engine Jonotron 5 2114 Last post 2007/06/19 01:22:35
by Nemo Krad
Mouse selection (collision?) Hazy Mind XNA Engine Requests Zan 2 2696 Last post 2007/05/19 16:32:50
by Zan
3D Collision Detection and Physics General Discussion « 1 2 » LucianX 15 4648 Last post 2007/08/02 20:54:38
by mikeschuld
Tranforming a model's vertices Hazy Mind XNA Engine « 1 2 » DoomMarine 29 6876 Last post 2007/08/28 05:15:34
by DoomMarine
Game-ready model shops General Discussion Balosh 0 1605 Last post 2009/07/10 02:37:54
by Balosh
Game- ready model shops Hazy Mind 3D Engine Tinlau 0 1181 Last post 2010/02/03 20:23:12
by Tinlau
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 2.561 seconds with 19 queries.