#### Archived

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

# plane/point collision routine isn't working?

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

## Recommended Posts

here is my routine to return the height of the terrain at a particular floating point x,y:
vector vecSub(vector p1, vector p2)	//used in calculating the normal
{
vector t;
t.x = p1.x - p2.x;
t.y = p1.y - p2.y;
t.z = p1.z - p2.z;
return t;
}

float vecDot(vector p1, vector p2)	//dot product of two vectors
{
return ((p1.x * p2.x) + (p1.y * p2.y) + (p1.z * p2.z));
}

vector vecCross(vector p1, vector p2)	//cross product for calculating the normal
{
vector t;
t.x = p1.y * p2.z - p1.z * p2.y;
t.y = p1.z * p2.x - p1.x * p2.z;
t.z = p1.x * p2.y - p1.y * p2.x;
return t;
}

float checkHeight(float x, float y)
{
vector p1, p2, p3, p, n;
float k;
p.x = x;
p.y = y;
float h1, h2, h3, h4;
float checkx, checky;
int chkx, chky;
checkx = x;
checky = y;
chkx = int(checkx);
chky = int(checky);
if(chkx > checkx)	//make sure int(check) didn''t round up.
{
chkx--;
}
if(chky > checky)
{
chky--;
}
if((checkx - chkx) + ((checky + 1) - chkx) < 1)   //decide which triangle of the terrain square to use
{
h1 = float(terrain_HeightMap[chkx][chky]);
h3 = float(terrain_HeightMap[chkx][chky+1]);
h4 = float(terrain_HeightMap[chkx+1][chky+1]);
p1.x = checkx - chkx;
p1.y = checky - chky + 1;
p1.z = h4;
p2.x = checkx - chkx;
p2.y = checky - chky;
p2.z = h1;
p3.x = checkx - chkx + 1;
p3.y = checky - chky + 1;
p3.z = h3;
}
else
{
h1 = float(terrain_HeightMap[chkx][chky]);
h2 = float(terrain_HeightMap[chkx+1][chky]);
h3 = float(terrain_HeightMap[chkx][chky+1]);
p1.x = checkx - chkx + 1;
p1.y = checky - chky + 1;
p1.z = h3;
p2.x = checkx - chkx;
p2.y = checky - chky;
p2.z = h1;
p3.x = checkx - chkx + 1;
p3.y = checky - chky;
p3.z = h2;
}
n = vecCross(vecSub(p1,p2), vecSub(p3,p2));
k = vecDot(n, p);
return (-((p.x * n.x) + (p.y * n.y))/k) / n.z;
}

it doesn''t work, it just returns 0.

##### Share on other sites
i think i figured out why its not working, but i don''t know how to fix it. the line k = vecDot(n, p), there, p.z doesn''t have a value yet. so it turns out i need to solve down this crap even further, DOH!

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013377
×