LightWrap++
AC++wrapperfortheLightWave3DSDK
point3d.h
Go to the documentation of this file.
1 #ifndef Point3_H
2 #define Point3_H
3 
4 #include <lwpp/Vector3d.h>
5 
6 #ifdef _DEBUG
7 #ifdef _MSWIN
8 #pragma warning (push,1)
9 #include <Windows.h>
10 #include <ostream>
11 #include <sstream>
12 #include <string>
13 #pragma warning (pop)
14 #pragma warning(disable : 4996)
15 #pragma warning(disable : 4530)
16 #else // OSX
17 #include <ostream>
18 #include <sstream>
19 #include <string>
20 #endif // _MSWIN
21 #endif // _DEBUG
22 
23 namespace lwpp
24 {
28 
29  template <typename T>
30  class Point3 {
31  public:
32  double x, y, z;
33  public:
35 
38  explicit Point3 (T n = 0.0) : x(n), y(n), z(n) {}
40 
45  Point3 (T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
47 
50  Point3 (const T n[3]) : x(n[0]), y(n[1]), z(n[2]) {}
52  explicit Point3 (const Vector3<T> &v) : x(v.x), y(v.y), z(v.z) {}
53  T *asLWVector() {return &x;}
54 
56  Point3 operator+(const Vector3<T> &v) const
57  {
58  return Point3(x + v.x, y + v.y, z + v.z);
59  }
61  {
62  x += v.x;
63  y += v.y;
64  z += v.z;
65  return *this;
66  }
68  Point3 operator-(const Vector3<T> &v) const
69  {
70  return Point3(x - v.x, y - v.y, z - v.z);
71  }
73  {
74  x -= v.x;
75  y -= v.y;
76  z -= v.z;
77  return *this;
78  }
79 
81  Vector3<T> operator-(const Point3 &p) const
82  {
83  return Vector3<T>(x - p.x, y - p.y, z - p.z);
84  }
85 
86  Point3 &operator*=(const T d)
87  {
88  x *= d; y *= d; z*= d;
89  return *this;
90  }
91 
93  {
94  x *= v.x;
95  y *= v.y;
96  z *= v.z;
97  return *this;
98  }
99 
100  Point3 operator*(const T d) const
101  {
102  return Point3(x * d, y * d, z * d);
103  }
104 
105  Point3 operator/(const T d) const
106  {
107  assert (1 != 0);
108  double id = 1.0 / d;
109  return (*this * id);
110  }
111 
112  Point3 &operator/=(const T d)
113  {
114  assert (1 != 0);
115  double id = 1.0 / d;
116  *this *= id;
117  return *this;
118  }
120  {
121  x /= v.x;
122  y /= v.y;
123  z /= v.z;
124  return *this;
125  }
126  inline T Magnitude() const {return sqrt(Sqr(x) + Sqr(y) + Sqr(z));}
127 
128  };
135  template <typename T>
136  inline T Distance(const Point3<T> &p1, const Point3<T> &p2)
137  {
138  return (p1 - p2).Magnitude();
139  }
140 
141  template<typename T>
142  inline Vector3<T>::Vector3 (const Point3<T> &p) : x(p.x), y(p.y), z(p.z) {}
143 }
144 
145 
146 #ifdef _DEBUG
147  template<typename T>
148  inline std::ostream &operator<<(std::ostream &os, const lwpp::Vector3<T> &t)
149  {
150  //t.m->Print(os);
151  os << " <" << t.x << "," << t.y << "," << t.z << "> ";
152  return os;
153  }
154 
155  template<typename T>
156  inline std::ostream &operator<<(std::ostream &os, const lwpp::Point3<T> &t)
157  {
158  //t.m->Print(os);
159  os << " <" << t.x << "," << t.y << "," << t.z << "> ";
160  return os;
161  }
162 
163 #endif // _DEBUG
164 
165 #endif // Point3_H