Public Group

# Ray Intersecting Problem

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

## 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 on other sites
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++)
{

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 on other sites
Quote:
 Original post by wizardpcAlso how can i post my code so it doesn't get the spacing all messed up?

[#source lang="C#"#]
[/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 :)~

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634118
• Total Posts
3015609
×