XNA Game Development Forums
2012/05/21 19:41:22 *
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: 3D Collision Detection and Physics  (Read 4651 times)
LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« on: 2007/06/13 00:50:45 »

Hello, I am trying to get gravity to work properly when falling and landing on a platform of differnt shapes and sizes. It's in 3D but I don't know how I can get an accurate collision detection from this. I'm also wondering how physics could be applied to the falling shapes could bounce around as in real world situations. Any ideas?
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #1 on: 2007/06/13 01:32:04 »

The physics part of what you are asking requires maths that is simply too much to put into a small post, and also requires a knowledge of how physical objects react with the world and what equations to use, and an in depth understanding of them to write it yourself. Rather go with a 3rd party library like that provided by XNADev.ru.

As for the collision detection, that is also provided in those libraries and is most optimised by them, but for simple stuff you just need the mesh's bounding box/sphere for both objects and then you do the intersection test on them.
Logged

LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #2 on: 2007/06/14 21:27:50 »

Thanks for the link. I have a custom content processor and I want to create bounding volumes for the entire outline of a mesh. If the mesh were a star, I would want each side of the star to be the side of the bounding volume. Is their a way to create a bounding volume out of just the vertices? I don't know where to start im terms of creating additional code to the content processor to add support for that. It might not be the most cost effieicnt way but the game isn't that big and I want some realistic collision detections going on.

Thanks for any help.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #3 on: 2007/06/15 00:38:46 »

See the Static method BoundingBox.CreateFromPoints, pass in an array of Vector3 points.
If your star's points are equidistant from the center, use a bounding sphere and you only need to supply the radius and center point. All of this can be found in the XNA documentation under the Collision Detection Overview. (ms-help://MS.VSExpressCC.v80/MS.VSIPCC.v80/MS.XNAFX.1033/XNA/Math_CollisionDetectionOverview.htm  <-- Copy this into your Documentation browser)
Logged

LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #4 on: 2007/06/15 20:48:01 »

Each mesh in the platform have a boundingsphere. Is their a way to divide the sphere into several smaller ones that can make up the mesh? I don't know how I can do this but if you have some kind of tutorial or example I would appreciate that. I looked at Sharkys tutorial but it looks too complicated and has more than I need in it.

Or is their a way to have vertex collisions? I have an array of points for each vertices in each seperate mesh. Does anyone know an algorythm that can detect collisions with just checking the coordinates/vectors? Either that or some way to make the game know that that mesh is a solid and nothing can pass through it from checking the coordinates. Anyone have an idea?

Thanks
« Last Edit: 2007/06/15 23:16:03 by LucianX » Logged
EclipsE
Full Member
***
Offline Offline

Posts: 111


View Profile
« Reply #5 on: 2007/06/16 12:37:59 »

Check this out

my NModel class

http://paste.lisp.org/display/42874

my NBoundingGroup class

http://paste.lisp.org/display/42874#1

when you load the graphics content in the model, bounding boxes are made for every mesh in the model, and a big one containing everything
you can also make bounding spheres if you create the model with the overloaded constructor NModel(string ModelAssetName, string shaderName, bool MakeBSList, string BSStartsWith)
the bool MakeBSList set to true if you want bounding spheres, set to false if you don't want to
the string BSStartsWith is the name with every bounding sphere starts, so you make some spheres in your model, and they all start with, example, boundingSphere, then when you create a model set the MakeBSList to true and the BSStartsWith to "boundingSphere", and the bounding group class will make bounding spheres from all of the meshes that start with boundingSphere
if you need anything else from my engine, say it Grin
Logged
LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #6 on: 2007/06/16 16:11:56 »

And using that will divide the bounding sphere in each mesh into several for more accurate collision detection? Could you show a code example? I have a content processor that gets a box and a sphere for each mesh in a model, but with things going up and allowing you to go through a hole or something the bounds don't work.

I'll take a look at it though, thanks a lot!
Logged
EclipsE
Full Member
***
Offline Offline

Posts: 111


View Profile
« Reply #7 on: 2007/06/16 16:21:42 »

It will not divide the bounding sphere, when you make the model, you place some spheres(meshes) that will be used for the bounds. That way, you can have like 2 meshes for the model, but you can represent the model with a couple of bounding spheres, for more accurate collision detection.
As for the code example, it would look something like

Code:
NModel model = new NModel("assetName", "shaderName", true, "boundingSphere");

That's what you have to do, of course, you need to edit the NModel class to suit you... My engine structure is similar to HMEngine but very different in some things... Like, my model class can have meshes which use different shaders! Yeah, that's true....
The main thing is to do the spheres that represent the bounds of the model. And when you load the graphics content, you can use the bounding spheres like model.BoundingGroup.BoundingSpheres and it will return a List<BoundingSphere>
Logged
LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #8 on: 2007/06/16 16:30:15 »

Aside from that, there was another way i thought of. Using the vector coordinates to check exact collisions with the vector points that make up the model. I already have the array of coordinates but am not sure of the algorithm that could provide exact checking if the sphere, and the box has been breached it then would only check the vertex positions.

If you know of a way or if this might be of some use to you, let me know and I'll toss the ContentProcessor over for you to try out.

Im not really worried about efficiency yet.
Logged
EclipsE
Full Member
***
Offline Offline

Posts: 111


View Profile
« Reply #9 on: 2007/06/16 16:33:01 »

I have no idea how to do vertex perfect collision detection.... that's too hard! And too expensive for the CPU
Logged
LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #10 on: 2007/06/16 16:36:32 »

It's working ok for the types of platform levels I have but checking player greater than X, Y, and Z only work to some extent. Maybe a collision detection Im looking for is too complicated for me right now huh. Until I can find a way to check coordinates or divide a mesh into seveal bounding spheres to better make up the model.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #11 on: 2007/06/16 22:56:53 »

You can never have perfect vertex collision, you will still be using only be planes or lines in your checks, because vertices have no width to check against, so you would only get a collision if the other vertices passed over it's exact point.
Logged

LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #12 on: 2007/06/16 23:41:00 »

Hmm, there dosent seem to be a very clear way to implement collision detection. You've played marble madness right? Kind of like that but if I can't check the vertex being greater than = a collision then there has to be some other way. Dividing up the mesh into several spheres to represent the mesh's shape coudl work but I don't know how to do that. Undecided

Thanks for the though everyone.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #13 on: 2007/06/18 01:09:44 »

Marble Madness uses im pretty sure a bounding sphere for the player marble and a bunch of bounding boxes or planes for the level itself, since the level is just a series of boxes essentially. You can do this I think in the content importer, or create each piece of the level individually, thing is I don't know too much about custom content importers so someone else will have to help with that aspect, but to me the best way to debug as well and keep your game easilly extended is to build your game level with blocks that then have easily defined bounding boxes.
Logged

LucianX
Jr. Member
**
Offline Offline

Posts: 66



View Profile WWW
« Reply #14 on: 2007/06/18 18:34:00 »

Yeah, i might have to do that. I was wanting to be able to go under things and have some nice detailed levels, but that might be too advanced as of yet. I already have a content processor that gets the bounding box and sphere for every mesh in the level as well as an array of vertices.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Terrain Traversing/Collision Hazy Mind XNA Engine Quinn 1 1605 Last post 2007/02/28 00:27:04
by Ardman
Detecting Model Collision...? General Discussion « 1 2 » DaphydTheBard 15 4291 Last post 2007/03/27 01:29:52
by Nemo Krad
Climbing stairs with collision detection Hazy Mind XNA Engine internetking 8 3789 Last post 2007/03/19 16:32:35
by mikeschuld
Physics Architecture Hazy Mind XNA Engine Jonotron 0 1081 Last post 2007/04/15 09:11:12
by Jonotron
Has anybody managed to get some collision in the game? Hazy Mind XNA Engine Jonotron 5 2118 Last post 2007/06/19 01:22:35
by Nemo Krad
Mouse selection (collision?) Hazy Mind XNA Engine Requests Zan 2 2699 Last post 2007/05/19 16:32:50
by Zan
Physics simulation: BulletX (Bullet for XNA) physics and Hazy Mind Xna Engine Hazy Mind XNA Engine Yubastard 6 5560 Last post 2007/08/12 08:57:21
by Yubastard
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 0.192 seconds with 19 queries.