1 |
|
---|
2 | #ifndef _POINT_H_
|
---|
3 | #define _POINT_H_
|
---|
4 |
|
---|
5 | #include "lwo.h"
|
---|
6 | #include "Vector3.h"
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 | class Point3 {
|
---|
11 | public:
|
---|
12 | inline Point3() {}
|
---|
13 |
|
---|
14 | inline Point3(float nx, float ny, float nz) : x(nx), y(ny), z(nz) {}
|
---|
15 |
|
---|
16 | inline Point3& operator =(const Vector3& v)
|
---|
17 | {
|
---|
18 | x = v.x;
|
---|
19 | y = v.y;
|
---|
20 | z = v.z;
|
---|
21 | return (*this);
|
---|
22 | }
|
---|
23 |
|
---|
24 | inline Point3& operator *=(float t)
|
---|
25 | {
|
---|
26 | x *= t;
|
---|
27 | y *= t;
|
---|
28 | z *= t;
|
---|
29 | return (*this);
|
---|
30 | }
|
---|
31 |
|
---|
32 | inline Point3& operator /=(float t)
|
---|
33 | {
|
---|
34 | float f = 1.0F / t;
|
---|
35 | x *= f;
|
---|
36 | y *= f;
|
---|
37 | z *= f;
|
---|
38 | return (*this);
|
---|
39 | }
|
---|
40 |
|
---|
41 | inline bool operator == ( const Point3& p ) const
|
---|
42 | {
|
---|
43 | return ( x == p.x && y == p.y && z == p.z );
|
---|
44 | }
|
---|
45 |
|
---|
46 | inline bool operator != ( const Point3& p ) const
|
---|
47 | {
|
---|
48 | return ( x != p.x || y != p.y || z != p.z );
|
---|
49 | }
|
---|
50 |
|
---|
51 | inline Point3 operator -(void) const
|
---|
52 | {
|
---|
53 | return (Point3(-x, -y, -z));
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Sum of point and vector (direction) is a point
|
---|
57 | inline Point3 operator +(const Vector3& v) const
|
---|
58 | {
|
---|
59 | return (Point3(x + v.x, y + v.y, z + v.z));
|
---|
60 | }
|
---|
61 |
|
---|
62 | // Difference of point and vector (direction) is a point
|
---|
63 | inline Point3 operator -(const Vector3& v) const
|
---|
64 | {
|
---|
65 | return (Point3(x - v.x, y - v.y, z - v.z));
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Difference between to points is a vector (direction)
|
---|
69 | inline Vector3 operator -(const Point3& p) const
|
---|
70 | {
|
---|
71 | return (Vector3(x - p.x, y - p.y, z - p.z));
|
---|
72 | }
|
---|
73 |
|
---|
74 | inline Point3 operator *(float t) const
|
---|
75 | {
|
---|
76 | return (Point3(x * t, y * t, z * t));
|
---|
77 | }
|
---|
78 |
|
---|
79 | inline Point3 operator /(float t) const
|
---|
80 | {
|
---|
81 | float f = 1.0F / t;
|
---|
82 | return (Point3(x * f, y * f, z * f));
|
---|
83 | }
|
---|
84 |
|
---|
85 | // Dot product
|
---|
86 | inline float operator *(const Vector3& v) const
|
---|
87 | {
|
---|
88 | return (x * v.x + y * v.y + z * v.z);
|
---|
89 | }
|
---|
90 |
|
---|
91 | float x, y, z;
|
---|
92 | };
|
---|
93 |
|
---|
94 | #endif // _POINT_H_
|
---|
95 |
|
---|