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