-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.h
224 lines (209 loc) · 4.2 KB
/
Point.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#ifndef POINT_H
#define POINT_H
#include <iostream>
#include "Vector.h"
template <class T>
class Point2
{
friend inline std::ostream &operator<<(std::ostream &stream, const Point2<T> &p)
{
return (stream << "(" << p.x << ", " << p.y << ")");
}
private:
T x, y;
public:
Point2(T _x = 0, T _y = 0) : x(_x), y(_y)
{
}
Point2(const Point2<T> &p) : x(p.x), y(p.y)
{
}
void set(T _x, T _y)
{
x = _x;
y = _y;
}
void set(const Point2<T> &p)
{
set(p.x, p.y);
}
Vector2<T> operator-(const Point2<T> &p) const
{
return Vector2<T>(x - p.x, y - p.y);
}
Point2<T> operator-(const Vector2<T> &v) const
{
return Point2<T>(x - v.getX(), y - v.getY());
}
Point2<T> &operator-=(const Vector2<T> &v)
{
return (*this = *this - v);
}
Point2<T> operator-() const
{
return Point2<T>(-x, -y);
}
Point2<T> operator+(const Vector2<T> &v) const
{
return Point2<T>(x + v.getX(), y + v.getY());
}
Point2<T> &operator+=(const Vector2<T> &v)
{
return (*this = *this + v);
}
Point2<T> &operator=(const Point2<T> &p)
{
set(p);
return *this;
}
bool operator==(const Point2<T> &p) const
{
return (x == p.x && y == p.y);
}
bool operator!=(const Point2<T> &p) const
{
return !(*this == p);
}
T getX() const
{
return x;
}
T getY() const
{
return y;
}
void setX(T x)
{
this->x = x;
}
void setY(T y)
{
this->y = y;
}
};
typedef Point2<GLfloat> Point2f;
typedef Point2<GLint> Point2i;
typedef Point2<GLdouble> Point2d;
typedef Point2<GLshort> Point2s;
inline void texCoord2f(const Point2f &p)
{
glTexCoord2f(p.getX(), p.getY());
}
inline void texCoord2i(const Point2i &p)
{
glTexCoord2i(p.getX(), p.getY());
}
inline void texCoord2d(const Point2d &p)
{
glTexCoord2d(p.getX(), p.getY());
}
inline void texCoord2s(const Point2s &p)
{
glTexCoord2s(p.getX(), p.getY());
}
template <class T>
class Point3
{
friend inline std::ostream &operator<<(std::ostream &stream, const Point3<T> &p)
{
return (stream << "(" << p.x << ", " << p.y << ", " << p.z << ")");
}
private:
T x, y, z;
public:
Point3(T _x = 0, T _y = 0, T _z = 0) : x(_x), y(_y), z(_z)
{
}
Point3(const Point3<T> &p) : x(p.x), y(p.y), z(p.z)
{
}
void set(T _x, T _y, T _z)
{
x = _x;
y = _y;
z = _z;
}
void set(const Point3<T> &p)
{
set(p.x, p.y, p.z);
}
Vector3<T> operator-(const Point3<T> &p) const
{
return Vector3<T>(x - p.x, y - p.y, z - p.z);
}
Point3<T> operator-() const
{
return Point3<T>(-x, -y, -z);
}
Point3<T> operator+(const Vector3<T> &v) const
{
return Point3<T>(x + v.getX(), y + v.getY(), z + v.getZ());
}
Point3<T> &operator+=(const Vector3<T> &v)
{
return (*this = *this + v);
}
Point3<T> &operator=(const Point3<T> &p)
{
set(p);
return *this;
}
bool operator==(const Point3<T> &p) const
{
return (x == p.x && y == p.y && z == p.z);
}
bool operator!=(const Point3<T> &p) const
{
return !(*this == p);
}
T getX() const
{
return x;
}
T getY() const
{
return y;
}
T getZ() const
{
return z;
}
void setX(T x)
{
this->x = x;
}
void setY(T y)
{
this->y = y;
}
void setZ(T z)
{
this->z = z;
}
operator Vector3<T>() const
{
return Vector3<T>(x, y, z);
}
operator Quaternion() const;
};
typedef Point3<GLfloat> Point3f;
typedef Point3<GLint> Point3i;
typedef Point3<GLdouble> Point3d;
typedef Point3<GLshort> Point3s;
inline void vertex3f(const Point3f &p)
{
glVertex3f(p.getX(), p.getY(), p.getZ());
}
inline void vertex3i(const Point3i &p)
{
glVertex3i(p.getX(), p.getY(), p.getZ());
}
inline void vertex3d(const Point3d &p)
{
glVertex3d(p.getX(), p.getY(), p.getZ());
}
inline void vertex3s(const Point3s &p)
{
glVertex3s(p.getX(), p.getY(), p.getZ());
}
#endif