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 <iostream>
00027 #include "vector.h"
00028
00029 namespace lux
00030 {
00031
00032 class Point {
00033 friend class boost::serialization::access;
00034 public:
00035
00036 Point(float _x=0, float _y=0, float _z=0)
00037 : x(_x), y(_y), z(_z) {
00038 }
00039
00040 Point(float v[3]) : x(v[0]), y(v[1]), z(v[2])
00041 {}
00042
00043 Point operator+(const Vector &v) const {
00044 return Point(x + v.x, y + v.y, z + v.z);
00045 }
00046
00047 Point &operator+=(const Vector &v) {
00048 x += v.x; y += v.y; z += v.z;
00049 return *this;
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; y -= v.y; z -= v.z;
00061 return *this;
00062 }
00063 Point &operator+=(const Point &p) {
00064 x += p.x; y += p.y; z += p.z;
00065 return *this;
00066 }
00067 Point operator+(const Point &p) const {
00068 return Point(x + p.x, y + p.y, z + p.z);
00069 }
00070 Point operator* (float f) const {
00071 return Point(f*x, f*y, f*z);
00072 }
00073 Point &operator*=(float f) {
00074 x *= f; y *= f; z *= f;
00075 return *this;
00076 }
00077 Point operator/ (float f) const {
00078 float inv = 1.f/f;
00079 return Point(inv*x, inv*y, inv*z);
00080 }
00081 Point &operator/=(float f) {
00082 float inv = 1.f/f;
00083 x *= inv; y *= inv; z *= inv;
00084 return *this;
00085 }
00086 float operator[](int i) const { return (&x)[i]; }
00087 float &operator[](int i) { return (&x)[i]; }
00088
00089 float x,y,z;
00090
00091 private:
00092 template<class Archive>
00093 void serialize(Archive & ar, const unsigned int version)
00094 {
00095 ar & x;
00096 ar & y;
00097 ar & z;
00098 }
00099 };
00100
00101
00102 inline Vector::Vector(const Point &p)
00103 : x(p.x), y(p.y), z(p.z) {
00104 }
00105
00106 inline ostream &operator<<(ostream &os, const Point &v) {
00107 os << v.x << ", " << v.y << ", " << v.z;
00108 return os;
00109 }
00110 inline Point operator*(float f, const Point &p) {
00111 return p*f;
00112 }
00113
00114 }
00115
00116
00117 #endif //LUX_POINT_H