#include "stdafx.h" #include "vect3usi.h" Vect3usi::Vect3usi(unsigned short z, unsigned short y, unsigned short x) { this->x = x; this->y = y; this->z = z; } Vect3usi::Vect3usi(void) { // Initialize to highest values (most likely to be wrong) this->x = 0xFFFF; this->y = 0xFFFF; this->z = 0xFFFF; } Vect3usi::~Vect3usi(void) { } unsigned int Vect3usi::get_dist_2_to(Vect3usi &dst) { int dm = (int)this->x - dst.x; unsigned int res = dm*dm; dm = (int)this->y - dst.y; res += (dm*dm); dm = (int)this->z - dst.z; res += (dm*dm); return res; } unsigned short Vect3usi::get_dist_man_to(Vect3usi &dst) { int dm = (int)this->x - dst.x; int res = (dm >= 0) ? (dm):(-dm); dm = (int)this->y - dst.y; res += ((dm >= 0) ? (dm):(-dm)); dm = (int)this->z - dst.z; res += ((dm >= 0) ? (dm):(-dm)); return (unsigned short)res; } void Vect3usi::get_unit_direction_to(Vect3usi &dst, char &rdz, char &rdy, char &rdx) { float dx = (float)dst.x - this->x; float dy = (float)dst.y - this->y; float dz = (float)dst.z - this->z; float denom = sqrt(dx*dx + dy*dy + dz*dz); dx /= denom; dy /= denom; dz /= denom; dx += (dx >= 0) ? 0.5f : -0.5f; dy += (dy >= 0) ? 0.5f : -0.5f; dz += (dz >= 0) ? 0.5f : -0.5f; rdx = (char)dx; rdy = (char)dy; rdz = (char)dz; }