Is there a sample around anywhere for this?
I'm a bit new to 'scripting' in DBPro,in c++ i'm used to this kind of thing:
float cMesh::GetClosestHeight(float XPos, float YPos, float ZPos)
{
float YAbove, YBelow;
YAbove = GetHeightAbove(XPos, YPos, ZPos);
YBelow = GetHeightBelow(XPos, YPos, ZPos);
if(fabs(YAbove-YPos) < fabs(YBelow-YPos))
return YAbove;
return YBelow;
}
float cMesh::GetHeightBelow(float XPos, float YPos, float ZPos)
{
BOOL Hit;
float u, v, Dist;
DWORD FaceIndex;
D3DXIntersect(m_Mesh->m_Mesh,
&D3DXVECTOR3(XPos,YPos,ZPos),
&D3DXVECTOR3(0.0f, -1.0f, 0.0f),
&Hit, &FaceIndex, &u, &v, &Dist, NULL, NULL);
if(Hit == TRUE)
return YPos-Dist;
return YPos;
}
float cMesh::GetHeightAbove(float XPos, float YPos, float ZPos)
{
BOOL Hit;
float u, v, Dist;
DWORD FaceIndex;
D3DXIntersect(m_Mesh->m_Mesh,
&D3DXVECTOR3(XPos,YPos,ZPos),
&D3DXVECTOR3(0.0f, 1.0f, 0.0f),
&Hit, &FaceIndex, &u, &v, &Dist, NULL, NULL);
if(Hit == TRUE)
return YPos+Dist;
return YPos;
}
BOOL cMesh::CheckIntersect(float XStart, float YStart, float ZStart,
float XEnd, float YEnd, float ZEnd,
float *Length)
{
BOOL Hit;
float u, v, Dist;
float XDiff, YDiff, ZDiff, Size;
DWORD FaceIndex;
D3DXVECTOR3 vecDir;
XDiff = XEnd - XStart;
YDiff = YEnd - YStart;
ZDiff = ZEnd - ZStart;
D3DXVec3Normalize(&vecDir, &D3DXVECTOR3(XDiff, YDiff, ZDiff));
D3DXIntersect(m_Mesh->m_Mesh,
&D3DXVECTOR3(XStart,YStart,ZStart), &vecDir,
&Hit, &FaceIndex, &u, &v, &Dist, NULL, NULL);
if(Hit == TRUE) {
Size = (float)sqrt(XDiff*XDiff+YDiff*YDiff+ZDiff*ZDiff);
if(Dist > Size)
Hit = FALSE;
else {
if(Length != NULL)
*Length = Dist;
}
}
return Hit;
}
but i'm sure it will be slighly less code with DBPro
Thanks.