Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
v3d.h
1 #pragma once
2 
3 struct v3d
4 {
5  // +---------
6  // | Life-cyle
7  // +---------
8  // Constructors
9  inline v3d(); // DO NOTHING! (For immediate creation)
10 
11  // Set all coordinates to fValue
12  inline v3d( const double& x , const double& y , const double& z );
13  inline v3d( const v3d& P );
14  // Vector A to B = B-A
15  inline v3d(const v3d& A, const v3d& B,const asVector& v);
16 
17  // Vector A to B = (A+B)*0.5;
18  inline v3d(const v3d& A, const v3d& B, const asMiddle& m);
19 
20  // Set (constructors-like)
21  inline void Set( const double& fValue );
22  inline void Set( const double& x , const double& y , const double& z );
23  inline void Set( const v3d& V );
24  // Vector A to B = B-A
25  inline void Set( const v3d& A, const v3d& B);
26  //inline void Set( const Vector3D& P );
27 
28  // Assignement
29  inline v3d& operator =( const v3d& V );
30  inline v3d& operator =(const double& V);
31 
32  // +---------
33  // | Addition/Substraction
34  // +---------
35  // With another vector (Internal laws)
36  friend inline v3d operator + ( const v3d& U , const v3d& V );
37  friend inline v3d operator - ( const v3d& U , const v3d& V );
38 
39  // With assignement
40  inline v3d& operator += ( const v3d& V );
41  inline v3d& operator -= ( const v3d& V );
42 
43  // Unary
44  friend inline v3d operator - ( const v3d& V );
45 
46  Point3D to_v3f() { return Point3D{ float(x), float(y), float(z) }; }
47 
48  // +---------
49  // | Multiplication/Division
50  // +---------
51  // With a scalar (External laws)
52  friend inline v3d operator * ( const double& fValue , const v3d& V );
53  friend inline v3d operator * ( const v3d& V , const double& fValue );
54 
55  // Avoid using this, it's too ambiguous (dot, cross or hadamard)
56  friend inline v3d operator * ( v3d V , const v3d& W );
57 
58  // Same as a*b but the intent is more clear
59  friend inline v3d Hadamard(v3d a, const v3d& b);
60 
61  friend inline v3d operator / ( const double& fValue , const v3d& V );
62  friend inline v3d operator / ( const v3d& V , const double& fValue );
63 
64  friend inline v3d operator / ( v3d V , const v3d& W );
65 
66  // With assignement
67  inline v3d& operator *= ( const double& fValue );
68  inline v3d& operator /= ( const double& fValue );
69 
70  inline v3d& operator *= ( const v3d& p);
71  inline v3d& operator /= ( const v3d& p);
72 
73  // +---------
74  // | Euclidian operations
75  // +---------
76  friend inline double Norm( const v3d& P );
77  friend inline double NormSquare( const v3d& P );
78  friend inline double Dist( const v3d& P1, const v3d& P2 );
79  friend inline double DistSquare( const v3d& P1, const v3d& P2 );
80  friend inline double SegmentDist(const v3d& Pt1, const v3d& Pt2,const v3d& Pt3, const v3d& Pt4);
81  friend inline double PointToSegmentDist(const v3d& Pt, const v3d& Pt1,const v3d& Pt2,v3d& nearest,bool& insideSegment);
82 
83 
84 
85  // +---------
86  // | Cross product
87  // +---------
88  friend inline v3d operator ^ ( const v3d& U , const v3d& V );
89 
90  // With assignement
91  inline const v3d& operator ^= ( const v3d& V );
92  inline void CrossProduct( const v3d& V, const v3d& W );
93 
94  // +---------
95  // | Euclidian operations
96  // +---------
97  friend inline double Dot( const v3d& U , const v3d& V );
98 
99 
100 
101  // +---------
102  // | Affine operations
103  // +---------
104  friend inline v3d Mid( const v3d& P , const v3d& Q );
105  friend inline v3d Bary( const double& a , const v3d& P , const double& b , const v3d& Q );
106  friend inline v3d Lerp( const v3d& P , const v3d& Q, const double& t );
107  // Blend is the same as Lerp, but Blend is available and as the same prototype for Vector3D, Point2D, Quaternion... so
108  // it can be called in template methods
109  friend inline v3d Blend(const v3d& U , const v3d& V,double t)
110  {
111  return Lerp(U,V,t);
112  }
113 
114  // +---------
115  // | Utilities
116  // +---------
117  inline void Normalize();
118  inline v3d Normalized() const;
119  inline void ClampMax(const double v);
120  inline void ClampMin(const double v);
121 
122  friend inline bool operator< (const v3d& U, const v3d& V);
123  friend inline bool operator<=(const v3d& U, const v3d& V);
124  friend inline bool operator> (const v3d& U, const v3d& V);
125  friend inline bool operator>=(const v3d& U, const v3d& V);
126  friend inline bool operator==(const v3d& U, const v3d& V);
127  friend inline bool operator!=(const v3d& U, const v3d& V);
128  friend inline bool operator==(const v3d& a, const v3d& b);
129  friend inline bool operator!=(const v3d& a, const v3d& b);
130 
131 
132  friend inline v3d ProjectOnPlane(v3d q, v3d o, v3d n);
133 
134  // +---------
135  // | Acces Operators
136  // +---------
137  inline const double& operator[](int i) const;
138  inline double& operator[](int i);
139 
140  // +---------
141  // | Coordinates
142  // +---------
143 
144  union
145  {
146  struct
147  {
148  double x;
149  double y;
150  double z;
151  };
152  double data[3];
153  };
154 };
155 
156 
157 
operator<
bool operator<(const DrawableSorterItem &Item1, const DrawableSorterItem &Item2)
overload < operator for comparison
Definition: DrawableSorter.h:30