Stefander

I've been enjoying myself with XNAGSE for a while now, and wanted to start actually developing something real. So I started to play around with shaders a little, looking into terrain collision algorithms, but they all use a heightmap or a bytemap for terrains. What if I modeled something with Maya, loaded it in using the DirectX model content pipeline and wanted to use that as a level I searched around the Net, but haven't found anything that explains at least in understandable detail how to actually apply the algorithms to meshes themselves. Same goes for physics, a lot of info about the algorithms (Newton and Euler's laws etc.), but no real solid code as to how to do it in C#, let alone XNA. I'm sorry if this has been posted before, I glanced over everything and couldn't find anything solid, so I thought it would be better to give it it's own thread.

It may seem a bit much to explain, but I would really love to get some good solid info about this, including links that I might have missed regarding this subject. I guess there must be quite a lot of people struggling with the same problem, so maybe we could collect all sorts of related info in this thread, since it is a very important part of game development. I would greatly appreciate any sort of info... :)

- Stef



Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

BLiTZWiNG

As far as I know you can't do collisions inside shaders... you would do a normal collision test with a model using either the average y of the surrounding vertices, or the return value of a ray cast in the -y direction against your mesh.




Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

Stefander

True, I figured that out using a few other tutorials that I found on these forums and ofcourse the trusty Google. But what I need help with is accessing the vertices or triangles so I can setup the BSP and use a ray-triangle intersect or as you said average y of the surrounding verts to see if a model is under or out of the bounds of the game level. I'm really not sure as to how to do that in XNA, it seemed pretty obvious in C++ with all the code samples lying around, but with the Content Pipeline in XNA I'm kind of lost... Thank you for pointing those things out too, you're really helping me to get over this :)

All I want is a simple-as-possible (since collisions aren't simple) int GetHeight(int x, int z, Model levelMesh) which returns the height at the specified x and z coordinates so I can adjust my character's y-position, ignoring the verts that are far away so it saves processing time. Is there any simple way to do this in XNA





Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

BLiTZWiNG

Definitely moving out of my realm of experience with XNA. IIRC you can't access the vertices of a mesh loaded with the content pipeline at run time, but I have seen some posts on how to do a hack around by leclerc9...

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=985192&SiteID=1

Also, check out

http://www.codeplex.com/quadtreeload
http://www.codeplex.com/animationcomponents

Clyde has done a great job with these, and they might show you what you're looking for better than I possibly could.




Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

Stefander

Thanks man, you gave me everything I needed to know, experimenting with extending the model processors :)





Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

BLiTZWiNG

Glad I could help, I really hope it gives you all you need!




Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

CodePfo

Here's a recomendation for terrain mesh collision: look for this algorithm called TriBox3d. It's a great and speedy way to determine intersection between a triangle mesh and a bounding box (perfect for heightmaps). More complex collision checking is going to require more robust objects than the built-in bounding objects. These objects will tell you if there is a collision, but not where or when it happened. You will also need to build scene management structures (like quadtrees) to manage collision testing, blindly testing every collision will slow your game to a crawl when the object count gets large.

I don't know of any good articles on the net for physics in C#, but I just got this book recently "Physics for Game Programmers" that has some examples in C# and Java. It's really good, very thorough, you can start reading it with only a basic understanding of physics and it goes into lots of detail.

Oh, and btw: you can simulate physics on the GPU using shaders, you can simulate practically everything if your GPU is capable and you are clever.




Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

Stefander

Heh, thanks for the help with the physics on GPU-part, man, it's going to save me a lot of processing power with that :) But what I'm looking for is a way to access the triangles in a mesh using overrides in the ModelContent pipeline class, maybe putting them in an array/list, sorting them out with a BSP-script so it gets rid of all the unnecessary triangles, and do my collision checking with the remaining few so it becomes economical. Now my question is what to actually write in the override, since I'm kind of lost with the current documentation there is for the content pipeline extenders. Can you/someone else lend me hand for that



Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

Jon Watte

What you write in the override, is to call into the base function. Then you get the vertex data, and calculate your accelerated collision structure, and add that to the model that the base returned, using the "Tag" property. Then you need to write a reader and a writer for the class that you assign to the Tag.

In the game, after loading the Model, get your object out from the Tag, and use it.






Re: XNA Game Studio Express Recommendations for terrainmesh collision and physics

Stefander

Thanks for the quick help Jon... I'm sorry if I'm asking too much, but can you or someone else help me out with writing the code for that.. I've only barely started to get to know the classes inside the content pipeline, and all I can do with it at the moment is writing pseudo-C# code, since I don't have any idea as to how to access any kind of model data at the moment (the documentation's a bit vague on that part), and other samples I picked up don't use any of the functions I need, so it would help with a lot of other stuff as well that I have piling up to be coded into my engine, but if it's too much trouble it's ok :)