Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

GeomUtilities.h
1 #pragma once
2 
3 // -- Code from Sketchup SDK sample --
4 
5 //This module defines geometric classes that are usefull in processing
6 //the objects coming from Sketchup.
7 
8 
9 //Utility Methods-------------------------------------
10 const double DivideByZeroTol = 1.0e-10;
11 const double DivideByZeroTolSq = DivideByZeroTol * DivideByZeroTol;
12 
13 const double EqualTol = 1.0e-3;
14 const double EqualTolSq = EqualTol * EqualTol;
15 
16 inline bool AreEqual(double val1, double val2, double tol = EqualTol)
17 {
18  double diff = val1 - val2;
19  return diff <= tol && diff >= -tol;
20 }
21 
22 
23 //Vector Class----------------------------------------
24 class CVector3d
25 {
26 public:
27 
28  CVector3d(): m_x(0.0), m_y(0.0), m_z(0.0) {}
29  CVector3d(double x, double y, double z): m_x(x), m_y(y), m_z(z) {}
30  CVector3d(CComPtr<ISkpVector3d> vec);
31  ~CVector3d() {}
32 
33  void SetDirection(double x, double y, double z){m_x=x; m_y=y; m_z=z;}
34 
35  double X() const {return m_x;}
36  double Y() const {return m_y;}
37  double Z() const {return m_z;}
38 
39  void SetX(double x) { m_x = x; }
40  void SetY(double y) { m_y = y; }
41  void SetZ(double z) { m_z = z; }
42 
43  CVector3d operator+(const CVector3d& vec) const;
44  CVector3d operator-(const CVector3d& vec) const;
45  void operator+=(const CVector3d& vec);
46  void operator-=(const CVector3d& vec);
47 
48  CVector3d operator*(double scale) const;
49  CVector3d operator/(double scale) const;
50  void operator*=(double scale);
51  void operator/=(double scale);
52 
53  bool operator==(const CVector3d& vec) const;
54  bool operator!=(const CVector3d& vec) const;
55 
56 protected:
57 
58  double m_x;
59  double m_y;
60  double m_z;
61 
62 };
63 
64 
65 //Point Class----------------------------------------
66 class CPoint3d
67 {
68 public:
69 
70  CPoint3d(): m_x(0.0), m_y(0.0), m_z(0.0) {}
71  CPoint3d(double x, double y, double z): m_x(x), m_y(y), m_z(z) {}
72  CPoint3d(CComPtr<ISkpPoint3d> point);
73  ~CPoint3d() {}
74 
75  void SetLocation(double x, double y, double z){m_x=x; m_y=y; m_z=z;}
76 
77  double X() const {return m_x;}
78  double Y() const {return m_y;}
79  double Z() const {return m_z;}
80 
81  void SetX(double x) { m_x = x; }
82  void SetY(double y) { m_y = y; }
83  void SetZ(double z) { m_z = z; }
84 
85  void operator+=(const CVector3d &vec);
86  void operator-=(const CVector3d &vec);
87 
88  CPoint3d operator+(const CVector3d& vec) const;
89  CPoint3d operator+(const CPoint3d& pt) const;
90  CPoint3d operator-(const CVector3d& vec) const;
91  CVector3d operator-(const CPoint3d& pt) const;
92 
93  CPoint3d operator* (double scale) const {return CPoint3d (m_x * scale, m_y * scale, m_z * scale);}
94  void operator*= (double scale) {*this = *this * scale;}
95  CPoint3d operator/ (double invScale) const {return *this * (1.0 / invScale);}
96  void operator/= (double invScale) {*this = *this / invScale;}
97 
98 protected:
99 
100  double m_x;
101  double m_y;
102  double m_z;
103 
104 };
105 
106 
107 //Transformation Class--------------------------------
109 {
110 public:
111 
112  CTransform();
113  CTransform(double m[16]);
114  ~CTransform(void);
115 
116  void SetMatrix(double m[16]);
117  void SetToIdenity();
118 
119  CPoint3d operator* (const CPoint3d& pt) const;
120  CVector3d operator* (const CVector3d& vec) const;
121  CTransform operator* (const CTransform& t) const;
122 
123 
124 
125 protected: // data
126 
127  double m_t[16];
128 
129 };
130 
Definition: GeomUtilities.h:66
Definition: GeomUtilities.h:108
Definition: GeomUtilities.h:24