Archived

This topic is now archived and is closed to further replies.

RhoneRanger

Collision Frustrations

Recommended Posts

I am trying to implement a ray/poly test on my meshes in DX9, and I am having problems getting transformed data from my models. I dont use X files, so telling me to use D3DX in this matter will not do. How do I get the vertices transformed position into my mesh data? Basically I am loading the mesh from a file, and storing data in system memory. Now, I am trying to transform the vertice data according to the world transformation, but the results are less than desirable. I also read once on this forum to transform your world coordinates into the object''s coordinates. This would be easier, since I have the vertices original placement from the model but I am not sure how to do that either. Any help would be appreciated!

Share this post


Link to post
Share on other sites
Wow.
I''m trying to use MD2 models with DirectX9.
And my plan was to use simple bounding spheres.
I didnt know you could perform collision detection at mesh-level!

If you figure this out, please say so...as I and probably a few others will be very interested in knowing how to do just that!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
d3dx isn''t just for x files, I''ve used it quite well for my own conversion from patch-based model files (so you can set the detail level at run-time!)

The library has a bunch of helper functions for handling matrix manipulation and even ray intersection which I''ve used.

It depends on what you are trying to do, but if you want to convert a ray into model-space just multiply three direction vectors (up,direction,rotation), and one position vector, by the model matrix (hope this is clear). Now you have a transformed set of vectors which I believe you can use for your test.

Share this post


Link to post
Share on other sites
okay, of course I have my up, look, and right vectors
and my position.

All you need to do is multiply all these by the model matrix?

That seems like a lot of wasted time! Is their an easier/better way?

And for all others:

I do use spheres for a lot of collision tests, but to get more accurate CD, if I cross the bounding sphere, then cast a ray to see if it hits a poly.

I got collision detection working fine for my landscape, but it is these transformed models that are posing a problem.

I am NOT using id3dx mesh just to reiterate.

Share this post


Link to post
Share on other sites
quote:
Original post by RhoneRanger
I dont use X files, so telling me to use D3DX in this matter will not do.



You can use D3DX without using X files by doing this:

D3DXCreateMeshFVF();

Mesh->LockVertexBuffer();
Mesh->LockIndexBuffer();

... // Fill in the vertex and index buffers

Mesh->UnlockVertexBuffer();
Mesh->UnlockIndexBuffer


then if you want to transform your mesh''s coordinates to world
coordinates you can try D3DXVec3TransformCoord

I hope this helps


KaM1KaZ3

Share this post


Link to post
Share on other sites
The whole point I am making is that I want to do collision on models in world space. I have very good and fast functions for collisions, but all I need to do is to fill the copy of vertices of the object I have in system memory with the position of the Transformed vertices. That''s all.

I don''t want to lock and unlock vertex/index buffers every frame, when all I have to do is this:

If you are in same area as model:

perform sphere/sphere test.

if you intersect spheres:
perform ray-triangle test on mesh.

Share this post


Link to post
Share on other sites
Here are a few suggestions:

You do not want to try and retrive the transformed mesh from DX, as this will hinder performance.

It is cheaper and easier to transform the ray/sphere or whatever into the models local space because:

1) tranforming the start/end point ( and possibly direction ) vectors is far cheaper than rotating every vert in a mesh to world space.

2) if you have the mesh instanced twice in the world you would have to store 2 transformed meshes, or do it several times a frame.

3) You want to do collision on the CPU, not the GPU as this will cause stalls -> lower performance.

There have been many threads discussing similar issues, it might be a good idea to look into those too.

Other people have good advice on this topic (See threads by Simon O''Conner amongst others )

hope this is of some help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Isn''t this what I said? Just transform the ray. You don''t need d3dx if you don''t want it.

Share this post


Link to post
Share on other sites