   Finding Distance Between objects in 3D
  HiHow can we find the distance between two objects in 3D worldI m using this code to find difference between Player and the Enemy modelbut it never produces correct resultsint Enemy::GetDistance(CVector3 PlayerPos) { CVector3 distance;distance.x = PlayerPos.x - model.position.x ;distance.y = PlayerPos.y - model.position.y ;distance.z = PlayerPos.z - model.position.z ;int dist= (int)sqrt( distance.x*distance.x + distance.y*distance.y + distance.z*distance.z )  ;return dist;}Plz tell me the way of finding distance[Edited by - kicsit on April 22, 2005 6:49:28 PM]
 int dist= (double)sqrt( distance.x*distance.x + distance.y*distance.y + distance.z*distance.z ) > 40What's that > 40 doing at the end? If it's there, wouldn't your sqrt result be checked against 40 and return either a boolean value of 1 or 0 which gets stored in dist? Try removing the > 40.   ;#include <cmath>template <typename A, typename B> double distance(const A &a, const B &b) {  double temp(a.x-b.x), result(temp*temp);  temp=a.y-b.y; result += temp*temp;  temp=a.z-b.z; return std::sqrt(result + temp*temp); }