// // point3d.cc // // A point in 3d space // // Copyright (C) J. Belson 1998.11.30 // #include #include "point3d.h" /** * Constructor */ point3d::point3d(float xx, float yy, float zz) { x = xx; y = yy; z = zz; } /** * Return coordinates of current point */ void point3d::get(float *xx, float *yy, float *zz) const { *xx = x; *yy = y; *zz = z; } /** * Set coordinates of current point */ void point3d::set(float xx, float yy, float zz) { x = xx; y = yy; z = zz; } /** * Set colour of this point */ void point3d::set_colour(uint8 red, uint8 green, uint8 blue) { col.r = red/255.0; col.g = green/255.0; col.b = blue/255.0; } /** * Set colour of this point */ void point3d::set_colour(const fcolour& c) { col = c; } /** * Get colour of this point */ fcolour point3d::get_colour(void) const { return col; } /** * Subtract a vector from this point */ vector3d point3d::operator-(const point3d& p) const { vector3d v(x - p.x, y - p.y, z - p.z); return v; } /** * Add a vector to this point */ point3d point3d::operator+(const vector3d& v) const { point3d p(x + v.i, y + v.j, z + v.k); return p; } /** * Apply scaling factor to this point */ point3d point3d::operator*(double f) { point3d p(x*f, y*f, z*f); return p; } /** * Assign to this point */ point3d point3d::operator=(const point3d& p) { x = p.x; y = p.y; z = p.z; col = p.col; return *this; } /** * Cast 'this' to point2d */ point3d::operator point2d() { point2d p; p.x = x; p.y = y; p.depth = z; p.col = col; return p; } /** * Write specified point coordinates to a stream. * @param str stream to write to * @param p point to operate on */ std::ostream& operator<<(std::ostream& str, const point3d& p) { str << std::setprecision(4); str << "(" << p.x << ", " << p.y << ", " << p.z << ")"; return str; }