Collision Frustrations

Started by
8 comments, last by RhoneRanger 20 years, 11 months ago
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!
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Advertisement
*warning: no answer*

So you are making a ID3DXMesh for your mesh, to do CD?
I''m loading MD2''s and I''m lookign for a way to do collision detection too, but is this the right way?

.lick
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!

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.
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.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
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 buffersMesh->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
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.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
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.
Mark, thanks for the reply!

So all I need to do is transform my ray into model space. I will look into Simons posts, and I appreciate the help!
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Isn''t this what I said? Just transform the ray. You don''t need d3dx if you don''t want it.

This topic is closed to new replies.

Advertisement