Jump to content
  • Advertisement
Sign in to follow this  
wizardpc

Ray Intersecting Problem

This topic is 4726 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 have a 128 x 128 heightmap that i use to create the terrain. Im trying to get the triangle of the terrain through the function D3DXIntersectTri(). I transformed the screen mouse click into a 3d vector correctly, i know this. IM getting a wierd problem and that is i place a mesh where i click on the terrain. Well that works for 3/4 of the terrain, and then the las 1/4 the mesh's x value will stay at arround 188 and always be off the terrain. i think that my loop is excluding some values maybe. i have the verts like so V1----V2/V5 | / | | / | | / | V3/V4----v6 im accessing the buffer and calling the function on the two triangles in the quad that i make. it works fine for the most part except that special part in the terrain. any help is greatly and i mean grealy appreciated. been staring at hours and don't know whats wrong. TerrainVertex *tv; TheTerrain->_vb->Lock(0,0,(void**)&tv,0); for(int i = 0; i < (TheTerrain->_numCellsPerCol ) ; i++) { for(int j = 0; j < TheTerrain->_numCellsPerRow ; j++) { V1.x = tv[(i * TheTerrain->_numVertsPerRow +j)]._x; V1.y = tv[(i * TheTerrain->_numVertsPerRow +j)]._y; V1.z = tv[(i * TheTerrain->_numVertsPerRow +j)]._z; V2.x = tv[(i * TheTerrain->_numVertsPerRow + j +1)]._x; V2.y = tv[(i * TheTerrain->_numVertsPerRow + j +1)]._y; V2.z = tv[(i * TheTerrain->_numVertsPerRow + j +1)]._z; V3.x = tv[((i+1) * TheTerrain->_numVertsPerRow + j)]._x; V3.y = tv[((i+1) * TheTerrain->_numVertsPerRow + j)]._y; V3.z = tv[((i+1) * TheTerrain->_numVertsPerRow + j)]._z; V4.x = tv[((i+1) * TheTerrain->_numVertsPerRow + j)]._x; V4.y = tv[((i+1) * TheTerrain->_numVertsPerRow + j)]._y; V4.z = tv[((i+1) * TheTerrain->_numVertsPerRow + j)]._z; V5.x = tv[(i * TheTerrain->_numVertsPerRow + j +1)]._x; V5.y = tv[(i * TheTerrain->_numVertsPerRow + j +1)]._y; V5.z = tv[(i * TheTerrain->_numVertsPerRow + j +1)]._z; V6.x = tv[ ((i+1) * TheTerrain->_numVertsPerRow + j +1)]._x; V6.y = tv[ ((i+1) * TheTerrain->_numVertsPerRow + j +1)]._y; V6.z = tv[((i+1) * TheTerrain->_numVertsPerRow + j +1)]._z; if(D3DXIntersectTri(&V1, &V2, &V3, &vecRay, &vecDir, &u, &k, &Dist)) { strcpy(picker,"HIT"); bHit = true; R.x = V3.x; R.y = V3.y; R.z = V3.z; sprintf(XC, "%f", V1.x); sprintf(YC, "%f", V1.y); sprintf(ZC, "%f", V1.z); } else if(D3DXIntersectTri(&V4, &V5, &V6, &vecRay, &vecDir, &u, &k, &Dist)) { strcpy(picker,"HIT"); bHit = true; R.x = V4.x; R.y = V4.y; R.z = V4.z; sprintf(XC, "%f", V1.x); sprintf(YC, "%f", V1.y); sprintf(ZC, "%f", V1.z); } } } TheTerrain->_vb->Unlock(); return bHit; Also how can i post my code so it doesn't get the spacing all messed up?

Share this post


Link to post
Share on other sites
Advertisement
OMG I DIDDDDDDDDDDDDDDDDDDDDDDDDDDDDD IT

im soooooo happy, only took me about 10 hours of trying to figure this out. ok if you look at my above for loops it read

for(int i = 0; i < (TheTerrain->_numCellsPerCol ) ; i++)
{
for(int j = 0; j < TheTerrain->_numCellsPerRow ; j++)
{


It SHOULD read

for(int i = 0; i < (TheTerrain->_numCellsPerCol- 3 ) ; i++)
{
for(int j = 0; j < TheTerrain->_numCellsPerRow- 3 ; j++)
{

the code works perfectly. anyone else that can use it go ahead. My last question is. how do people post their code without the spacing getting trown to wack

Share this post


Link to post
Share on other sites
Quote:
Original post by wizardpc
Also how can i post my code so it doesn't get the spacing all messed up?


[#source lang="C#"#]
Your code here!
[/source]

Just remove the hashes at the beginning and end!

For the lang= you can always put C++ or C instead, there are others - look at the Forum FAQ! It tells you enverything you'll ever need to know and more!

Hope that helped :)

~Will rate for cheese :)~

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!