Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
UVWPoint.h
Go to the documentation of this file.
1//! @file UVWPoint.h
2//! @brief CUVWPoint is a point that have u, v, w coordinates
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_UVWPOINT_H__87AE9F02_44D4_11D3_A382_B19716B5FB20__INCLUDED_)
7#define AFX_UVWPOINT_H__87AE9F02_44D4_11D3_A382_B19716B5FB20__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "Point.h"
14#include "3DVector.h"
15
16BEGIN_MOOTOOLS_NAMESPACE
17
18//! @class CUVWPoint
19//! @brief CUVWPoint is a point that have u, v, w for handling object texturing.
20class DLL_3DFUNCTION CUVWPoint : public CPt
21{
22public:
23 real u, v, w;
24
25 CUVWPoint();
26 CUVWPoint(real u, real v, real w);
27
28 void Init(real u, real v, real w);
29
30 // Access operators
31 real& operator[](int i);
32 const real& operator[](int i) const;
33 real* ValPtr();
34
35 void GetUVCoordinate(float& u, float& v);
36
37 virtual void To4DPoint(C4DPoint& pt) const;
38 virtual CPt& operator=(const C4DPoint& pt);
39 virtual void Serialize(CXArchive& ar);
40 virtual CPt& operator=(const CPt& refpoint); // virtual copy operator (must be defined to allow low level copy)
41
42 CUVWPoint& operator=(const CUVWPoint& coord);
43 bool operator==(const CUVWPoint& coord) const;
44 CUVWPoint operator-(const CUVWPoint& uvw) const;
45 CUVWPoint operator+(const CUVWPoint& uvw) const;
46 void operator-=(const CUVWPoint& uvw);
47 void operator+=(const CUVWPoint& uvw);
48
49 void operator*=(const real& weight);
50
51 operator C3DVector() const;
52 operator C3DPoint() const;
53 static C3DVector Vector(const CUVWPoint& A, const CUVWPoint& B); // Return AB vector from UVW
54
55 void GetFloat2(float *values2f) const; // Get point and fill 3 floats
56 void SetFloat2(const float *values2f); // Set point from 2 floats
57 void GetDouble2(double *values2d) const; // Get point and fill 2 doubles
58 void SetDouble2(const double *values2d); // Set point from 2 doubles
59 void GetFloat3(float *values3f) const; // Get point and fill 3 floats
60 void SetFloat3(const float *values3f); // Set point from 3 floats
61 void GetDouble3(double *values3d) const; // Get point and fill 3 doubles
62 void SetDouble3(const double *values3d); // Set point from 3 doubles
63
64#ifdef _DEBUG
65 virtual void Dump() const;
66 bool IsKindOf(unsigned int classid) const;
67 virtual unsigned int ClassID() const;
68#endif
69};
70
71template <> class CHashMethods<CUVWPoint>
72{
73public:
74 static inline bool HashCompare(const CUVWPoint& pt1, const CUVWPoint& pt2)
75 {
76 if (pt1.u != pt2.u || pt1.v != pt2.v || pt1.w != pt2.w)
77 return false;
78
79 return true;
80 }
81
82 static inline unsigned int HashValue(const CUVWPoint& hash)
83 {
84 return CHashMethods<real>::HashValue(hash.u + hash.v + hash.w);
85 }
86};
87
88//////////////////////////////////////////////////////////
89// CUVWPoint implementation
90inline C3DVector CUVWPoint::Vector(const CUVWPoint& pt1, const CUVWPoint& pt2)
91{
92 C3DVector vector;
93 vector.x = pt2.u - pt1.u;
94 vector.y = pt2.v - pt1.v;
95 vector.z = pt2.w - pt1.w;
96 return vector;
97}
98
99inline CUVWPoint::CUVWPoint()
100{
101 u = 0.0f;
102 v = 0.0f;
103 w = 0.0f;
104}
105
106inline CUVWPoint::CUVWPoint(real u, real v, real w)
107{
108 this->u = u;
109 this->v = v;
110 this->w = w;
111}
112
113inline void CUVWPoint::Init(real u, real v, real w)
114{
115 this->u = (real)u;
116 this->v = (real)v;
117 this->w = (real)w;
118}
119
120// Access operators
121inline real& CUVWPoint::operator[](int i)
122{
123 return (&u)[i];
124}
125
126inline const real& CUVWPoint::operator[](int i) const
127{
128 return (&u)[i];
129}
130
131inline real* CUVWPoint::ValPtr()
132{
133 return(&u);
134}
135
136inline CUVWPoint& CUVWPoint::operator=(const CUVWPoint& coord)
137{
138 CPt::operator=(coord);
139 u = coord.u;
140 v = coord.v;
141 w = coord.w;
142
143 return *this;
144}
145
146inline CPt& CUVWPoint::operator=(const CPt& refpoint)
147{
148 XASSERT(refpoint.IsKindOf(CUVWPoint::ClassID()));
149
150 this->u = ((CUVWPoint&)refpoint).u;
151 this->v = ((CUVWPoint&)refpoint).v;
152 this->w = ((CUVWPoint&)refpoint).w;
153
154 return CPt::operator=(refpoint);
155}
156
157inline bool CUVWPoint::operator==(const CUVWPoint& coord) const
158{
159 if (u != coord.u)
160 return false;
161
162 if (v != coord.v)
163 return false;
164
165 if (w != coord.w)
166 return false;
167
168 return true;
169}
170
171inline CUVWPoint CUVWPoint::operator-(const CUVWPoint& uvw) const
172{
173 return CUVWPoint(u - uvw.u, v - uvw.v, w - uvw.w);
174}
175
176inline CUVWPoint CUVWPoint::operator+(const CUVWPoint& uvw) const
177{
178 return CUVWPoint(u + uvw.u, v + uvw.v, w + uvw.w);
179}
180
181inline void CUVWPoint::operator-=(const CUVWPoint& uvw)
182{
183 u -= uvw.u;
184 v -= uvw.v;
185 w -= uvw.w;
186}
187
188inline void CUVWPoint::operator+=(const CUVWPoint& uvw)
189{
190 u += uvw.u;
191 v += uvw.v;
192 v += uvw.w;
193}
194
195inline void CUVWPoint::operator*=(const real& weight)
196{
197 u *= weight;
198 v *= weight;
199 w *= weight;
200}
201
202inline CUVWPoint::operator C3DVector() const
203{
204 return C3DVector(u, v, w);
205}
206
207inline CUVWPoint::operator C3DPoint() const
208{
209 return C3DPoint(u, v, w);
210}
211
212inline void CUVWPoint::GetFloat2(float *values2f) const
213{
214 values2f[0] = u;
215 values2f[1] = v;
216}
217
218inline void CUVWPoint::SetFloat2(const float *values2f)
219{
220 u = values2f[0];
221 v = values2f[1];
222 w = (real)0.0;
223}
224
225inline void CUVWPoint::GetDouble2(double *values2d) const
226{
227 values2d[0] = u;
228 values2d[1] = v;
229}
230
231inline void CUVWPoint::SetDouble2(const double *values2d)
232{
233 u = (real)values2d[0];
234 v = (real)values2d[1];
235 w = (real)0.0;
236}
237
238inline void CUVWPoint::GetFloat3(float *values3f) const
239{
240 values3f[0] = u;
241 values3f[1] = v;
242 values3f[1] = w;
243}
244
245inline void CUVWPoint::SetFloat3(const float *values3f)
246{
247 u = values3f[0];
248 v = values3f[1];
249 w = values3f[2];
250}
251
252inline void CUVWPoint::GetDouble3(double *values3d) const
253{
254 values3d[0] = u;
255 values3d[1] = v;
256 values3d[1] = w;
257}
258
259inline void CUVWPoint::SetDouble3(const double *values3d)
260{
261 u = (real)values3d[0];
262 v = (real)values3d[1];
263 w = (real)values3d[2];
264}
265
266END_MOOTOOLS_NAMESPACE
267
268#endif // !defined(AFX_UVWPOINT_H__87AE9F02_44D4_11D3_A382_B19716B5FB20__INCLUDED_)
CPt class is the base class for different class of points (C3DPoint, CUVWPoint...)
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition 4DPoint.h:17
Definition Hash.h:146
CPt base only contains some flags that are used by the derived class.
Definition Point.h:60
CUVWPoint is a point that have u, v, w for handling object texturing.
Definition UVWPoint.h:21
Definition XArchive.h:17