00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _LUXRAYS_POINT_H
00023 #define _LUXRAYS_POINT_H
00024
00025 #include "luxrays/core/geometry/vector.h"
00026
00027 namespace luxrays {
00028
00029 class Point {
00030 public:
00031
00032
00033 Point(float _x = 0.f, float _y = 0.f, float _z = 0.f)
00034 : x(_x), y(_y), z(_z) {
00035 }
00036
00037 Point(float v[3]) : x(v[0]), y(v[1]), z(v[2]) {
00038 }
00039
00040 Point operator+(const Vector &v) const {
00041 return Point(x + v.x, y + v.y, z + v.z);
00042 }
00043
00044 Point & operator+=(const Vector &v) {
00045 x += v.x;
00046 y += v.y;
00047 z += v.z;
00048 return *this;
00049 }
00050
00051 Vector operator-(const Point &p) const {
00052 return Vector(x - p.x, y - p.y, z - p.z);
00053 }
00054
00055 Point operator-(const Vector &v) const {
00056 return Point(x - v.x, y - v.y, z - v.z);
00057 }
00058
00059 Point & operator-=(const Vector &v) {
00060 x -= v.x;
00061 y -= v.y;
00062 z -= v.z;
00063 return *this;
00064 }
00065
00066 Point & operator+=(const Point &p) {
00067 x += p.x;
00068 y += p.y;
00069 z += p.z;
00070 return *this;
00071 }
00072
00073 Point & operator-=(const Point &p) {
00074 x -= p.x;
00075 y -= p.y;
00076 z -= p.z;
00077 return *this;
00078 }
00079
00080 Point operator+(const Point &p) const {
00081 return Point(x + p.x, y + p.y, z + p.z);
00082 }
00083
00084 Point operator*(float f) const {
00085 return Point(f*x, f*y, f * z);
00086 }
00087
00088 Point & operator*=(float f) {
00089 x *= f;
00090 y *= f;
00091 z *= f;
00092 return *this;
00093 }
00094
00095 Point operator/(float f) const {
00096 float inv = 1.f / f;
00097 return Point(inv*x, inv*y, inv * z);
00098 }
00099
00100 Point & operator/=(float f) {
00101 float inv = 1.f / f;
00102 x *= inv;
00103 y *= inv;
00104 z *= inv;
00105 return *this;
00106 }
00107
00108 float operator[](int i) const {
00109 return (&x)[i];
00110 }
00111
00112 float &operator[](int i) {
00113 return (&x)[i];
00114 }
00115
00116
00117 float x, y, z;
00118 };
00119
00120 inline Vector::Vector(const Point &p)
00121 : x(p.x), y(p.y), z(p.z) {
00122 }
00123
00124 inline std::ostream & operator<<(std::ostream &os, const Point &v) {
00125 os << "Point[" << v.x << ", " << v.y << ", " << v.z << "]";
00126 return os;
00127 }
00128
00129 inline Point operator*(float f, const Point &p) {
00130 return p*f;
00131 }
00132
00133 inline float Distance(const Point &p1, const Point &p2) {
00134 return (p1 - p2).Length();
00135 }
00136
00137 inline float DistanceSquared(const Point &p1, const Point &p2) {
00138 return (p1 - p2).LengthSquared();
00139 }
00140
00141 }
00142
00143 #endif