#include "SFPoint3f.h" #include "SFString.h" #include using namespace X3DTK; using namespace std; const SFPoint3f SFPoint3f::null(0.0f, 0.0f, 0.0f); SFPoint3f::SFPoint3f() : x(0.0f), y(0.0f), z(0.0f) { } SFPoint3f::SFPoint3f(float x, float y, float z) { this->x = x; this->y = y; this->z = z; } SFPoint3f::SFPoint3f(const SFPoint3f &p) { x = p.x; y = p.y; z = p.z; } SFPoint3f &SFPoint3f::operator= (const SFPoint3f &v) { x = v.x; y = v.y; z = v.z; return *this; } SFPoint3f &SFPoint3f::operator+= (const SFVec3f &v) { x += v.x; y += v.y; z += v.z; return *this; } SFPoint3f &SFPoint3f::operator+= (const SFPoint3f &v) { x += v.x; y += v.y; z += v.z; return *this; } SFPoint3f &SFPoint3f::operator-= (const SFVec3f &v) { x -= v.x; y -= v.y; z -= v.z; return *this; } SFPoint3f::SFPoint3f(const SFString &s) { istringstream iss(s, istringstream::in); iss >> x >> y >> z; } SFPoint3f::SFPoint3f(const SFVec3f &V) { x = V.x; y = V.y; z = V.z; } // operations on points //overloading of the operators +, -, * namespace X3DTK { SFPoint3f operator+ (const SFPoint3f &v1, const SFVec3f &v2) { SFPoint3f res; res.x = v1.x + v2.x; res.y = v1.y + v2.y; res.z = v1.z + v2.z; return res; } SFPoint3f operator+ (const SFPoint3f &v1, const SFPoint3f &v2) { SFPoint3f res; res.x = v1.x + v2.x; res.y = v1.y + v2.y; res.z = v1.z + v2.z; return res; } SFPoint3f operator- (const SFPoint3f &v1, const SFVec3f &v2) { SFPoint3f res; res.x = v1.x - v2.x; res.y = v1.y - v2.y; res.z = v1.z - v2.z; return res; } SFVec3f operator- (const SFPoint3f &v1, const SFPoint3f &v2) { SFVec3f res; res.x = v1.x - v2.x; res.y = v1.y - v2.y; res.z = v1.z - v2.z; return res; } SFPoint3f operator* (const float a, const SFPoint3f &v) { SFPoint3f res; res.x = a * v.x; res.y = a * v.y; res.z = a * v.z; return res; } float distance(const SFPoint3f &A, const SFPoint3f &B) { return (A - B).norm(); } }