Sign in to follow this  

More D3DXIntersect problems

This topic is 4371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I call D3DXIntersect to allow the character in my first-person game to move up and down with the landscape. The mesh I use is 64x64. The character starts at (0,0), which is the center of the mesh. The problem is, whenever the X or Z values are greater than 0, D3DXIntersect is not seeing the mesh, so the character cannot move up and down according to what the mesh looks like. This means I can only walk around in 1/4 of the map. The .x mesh is also divided into 4 groups (for the materials). This means that it is either the X and Z values that is stopping it working, or that only 1 quarter of the mesh is being seen by D3DXIntersect, even though they are all being drawn. Any help on this would really be appreciated.

Share this post


Link to post
Share on other sites
I think that it would help if we could actually see your code for the d3dxintersect call and preparation for it.
Right now it could be anything.
Do you transform the mesh when rendering it? Perhaps their is a problem with the sub meshes? It's hard to tell from the given information.

Regards,
/Omid

Share this post


Link to post
Share on other sites
Remember that your ray and the mesh you are checking for intersection have to be in the same space. This is typically done by transforming the ray (composed of an origin and a direction) into the model space of the mesh you're checking for intersection. You do this by transforming the ray by the inverse of the mesh's world matrix.

neneboricua

Share this post


Link to post
Share on other sites
Here is the code for the D3DXIntersect call:

D3DXIntersect(m_MapMesh,
&D3DXVECTOR3(XPos/SCALE,YPos/SCALE,ZPos/SCALE),
&D3DXVECTOR3(0.0f, -1.0f, 0.0f), &Hit, &FaceIndex, &u, &v, &Dist,
NULL, NULL);

How do I transform the ray by the inverse of the mesh's world matrix?

Share this post


Link to post
Share on other sites
I have just experimented with a different mesh for the map, and I had a similar problem, but instead of only being able to walk properly when X and Z were both negative, with the second map I can only walk properly when X is negative and Z is positive.

I had a look through the .x files, and found that at the beginning where the texture filenames are given, the texture of the part of the mesh I can walk on is always the last one mentioned. The thing is these are different textures each time. For the first map it is the 3rd texture, and the second it is the 1st.

So I am almost certain now that the problem is D3DXIntersect not noticing the parts of the mesh whose textures are mentioned 1st, 2nd, and 3rd in the .x file.

If anybody has any ideas, I would be very grateful if you could share them.




[Edited by - Harryu on December 29, 2005 6:38:37 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Harryu
So I am almost certain now that the problem is D3DXIntersect not noticing the parts of the mesh whose textures are mentioned 1st, 2nd, and 3rd in the .x file.

Have you transformed your ray into model space?? What you mention is more than likely not the problem. Use D3DXMatrixInverse to compute the inverse of your mesh's world matrix. Then use D3DXVec3TransformCoord to transform your ray's origin and D3DXVec3TransformNormal to transform your ray's direction by this inverse matrix.

neneboricua

Share this post


Link to post
Share on other sites
Try to make sure your call to D3DXIntersect is working as you expect; send it some rays in different areas of your world to make sure the intersection test is happening as you expect.

If the intersection tests are working fine, then take a look at the logic to move your camera/character around.

If the intersection tests are not working as intended, try to use one of the meshes that comes with the SDK as a test. Those meshes are built correctly. That will help you narrow down the source of the problem

neneboricua

Share this post


Link to post
Share on other sites

This topic is 4371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this