39 |
|
#include "Vector.hpp" |
40 |
|
|
41 |
|
namespace oopse { |
42 |
+ |
|
43 |
+ |
/** |
44 |
+ |
* @class Vector3 Vector3.hpp "math/Vector3.hpp" |
45 |
+ |
* @brief |
46 |
+ |
*/ |
47 |
+ |
|
48 |
+ |
template<typename Real> |
49 |
+ |
class Vector3 : public Vector<Real, 3>{ |
50 |
+ |
public: |
51 |
+ |
typedef Real ElemType; |
52 |
+ |
typedef Real* ElemPoinerType; |
53 |
+ |
|
54 |
+ |
Vector3() : Vector<Real, 3>(){} |
55 |
+ |
|
56 |
+ |
/** Constructs and initializes a Vector3 from x, y, z coordinates */ |
57 |
+ |
inline Vector3( double x, double y, double z) { |
58 |
+ |
data_[0] = x; |
59 |
+ |
data_[1] = y; |
60 |
+ |
data_[2] = z; |
61 |
+ |
} |
62 |
|
|
63 |
+ |
/** Constructs and initializes from an array*/ |
64 |
+ |
inline Vector3(double* array) : Vector<Real, 3>(array) {} |
65 |
+ |
|
66 |
+ |
inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {} |
67 |
+ |
|
68 |
+ |
inline Vector3<Real>& operator = (const Vector<Real, 3>& v) { |
69 |
+ |
if (this == &v) { return *this; } |
70 |
+ |
Vector<Real, 3>::operator=(v); |
71 |
+ |
return *this; |
72 |
+ |
} |
73 |
+ |
|
74 |
|
/** |
75 |
< |
* @class Vector3 Vector3.hpp "math/Vector3.hpp" |
76 |
< |
* @brief |
75 |
> |
* Retunrs reference of the first element of Vector3. |
76 |
> |
* @return reference of the first element of Vector3 |
77 |
|
*/ |
78 |
+ |
inline Real& x() { return data_[0];} |
79 |
|
|
48 |
– |
template<typename Real> |
49 |
– |
class Vector3 : public Vector<Real, 3>{ |
50 |
– |
public: |
51 |
– |
|
52 |
– |
Vector3() : Vector<Real, 3>(){} |
53 |
– |
|
54 |
– |
/** Constructs and initializes a Vector3 from x, y, z coordinates */ |
55 |
– |
inline Vector3( double x, double y, double z) { |
56 |
– |
data_[0] = x; |
57 |
– |
data_[1] = y; |
58 |
– |
data_[2] = z; |
59 |
– |
} |
60 |
– |
|
61 |
– |
inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {} |
62 |
– |
|
63 |
– |
inline Vector3<Real>& operator = (const Vector<Real, 3>& v) { |
64 |
– |
if (this == &v) { return *this; } |
65 |
– |
Vector<Real, 3>::operator=(v); |
66 |
– |
return *this; |
67 |
– |
} |
68 |
– |
|
69 |
– |
/** |
70 |
– |
* Retunrs reference of the first element of Vector3. |
71 |
– |
* @return reference of the first element of Vector3 |
72 |
– |
*/ |
73 |
– |
inline double& x() { return data_[0];} |
74 |
– |
|
75 |
– |
/** |
76 |
– |
* Retunrs the first element of Vector3. |
77 |
– |
* @return the first element of Vector3 |
78 |
– |
*/ |
79 |
– |
inline double x() const { return data_[0];} |
80 |
– |
|
81 |
– |
/** |
82 |
– |
* Retunrs reference of the second element of Vector3. |
83 |
– |
* @return reference of the second element of Vector3 |
84 |
– |
*/ |
85 |
– |
inline double& y() { return data_[1];} |
86 |
– |
|
87 |
– |
/** |
88 |
– |
* Retunrs the second element of Vector3. |
89 |
– |
* @return c the second element of Vector3 |
90 |
– |
*/ |
91 |
– |
inline double y() const { return data_[1];} |
92 |
– |
|
93 |
– |
/** |
94 |
– |
* Retunrs reference of the third element of Vector3. |
95 |
– |
* @return reference of the third element of Vector3 |
96 |
– |
*/ |
97 |
– |
inline double& z() { return data_[2];} |
98 |
– |
|
99 |
– |
/** |
100 |
– |
* Retunrs the third element of Vector3. |
101 |
– |
* @return f the third element of Vector3 |
102 |
– |
*/ |
103 |
– |
inline double z() const { return data_[2];} |
104 |
– |
|
105 |
– |
}; |
106 |
– |
|
80 |
|
/** |
81 |
< |
* Returns the cross product of two Vectors |
82 |
< |
* @param v1 first vector |
110 |
< |
* @param v2 second vector |
111 |
< |
* @return the cross product of v1 and v2 |
112 |
< |
* @see #vector::dot |
81 |
> |
* Retunrs the first element of Vector3. |
82 |
> |
* @return the first element of Vector3 |
83 |
|
*/ |
84 |
< |
template<typename Real> |
85 |
< |
Vector3<Real> cross( const Vector3<Real>& v1, const Vector3<Real>& v2 ) { |
86 |
< |
Vector3<Real> result; |
87 |
< |
|
88 |
< |
result.x() = v1.y() * v2.z() - v1.z() * v2.y(); |
89 |
< |
result.y() = v1.z() * v2.x() - v1.x() * v2.z(); |
90 |
< |
result.z() = v1.x() * v2.y() - v1.y() * v2.x(); |
84 |
> |
inline Real x() const { return data_[0];} |
85 |
> |
|
86 |
> |
/** |
87 |
> |
* Retunrs reference of the second element of Vector3. |
88 |
> |
* @return reference of the second element of Vector3 |
89 |
> |
*/ |
90 |
> |
inline Real& y() { return data_[1];} |
91 |
> |
|
92 |
> |
/** |
93 |
> |
* Retunrs the second element of Vector3. |
94 |
> |
* @return c the second element of Vector3 |
95 |
> |
*/ |
96 |
> |
inline Real y() const { return data_[1];} |
97 |
> |
|
98 |
> |
/** |
99 |
> |
* Retunrs reference of the third element of Vector3. |
100 |
> |
* @return reference of the third element of Vector3 |
101 |
> |
*/ |
102 |
> |
inline Real& z() { return data_[2];} |
103 |
> |
|
104 |
> |
/** |
105 |
> |
* Retunrs the third element of Vector3. |
106 |
> |
* @return f the third element of Vector3 |
107 |
> |
*/ |
108 |
> |
inline Real z() const { return data_[2];} |
109 |
> |
|
110 |
> |
}; |
111 |
> |
|
112 |
> |
/** |
113 |
> |
* Returns the cross product of two Vectors |
114 |
> |
* @param v1 first vector |
115 |
> |
* @param v2 second vector |
116 |
> |
* @return the cross product of v1 and v2 |
117 |
> |
* @see #vector::dot |
118 |
> |
*/ |
119 |
> |
template<typename Real> |
120 |
> |
Vector3<Real> cross( const Vector3<Real>& v1, const Vector3<Real>& v2 ) { |
121 |
> |
Vector3<Real> result; |
122 |
> |
|
123 |
> |
result.x() = v1.y() * v2.z() - v1.z() * v2.y(); |
124 |
> |
result.y() = v1.z() * v2.x() - v1.x() * v2.z(); |
125 |
> |
result.z() = v1.x() * v2.y() - v1.y() * v2.x(); |
126 |
> |
|
127 |
> |
return result; |
128 |
> |
} |
129 |
> |
|
130 |
> |
typedef Vector3<double> Vector3d; |
131 |
|
|
132 |
< |
return result; |
133 |
< |
} |
134 |
< |
|
132 |
> |
const Vector3d V3Zero(0.0 , 0.0, 0.0); |
133 |
> |
const Vector3d V3X( 1.0, 0.0, 0.0 ) ; |
134 |
> |
const Vector3d V3Y( 0.0, 1.0, 0.0 ) ; |
135 |
> |
const Vector3d V3Z ( 0.0, 0.0, 1.0 ) ; |
136 |
> |
|
137 |
|
} |
138 |
|
|
127 |
– |
|
139 |
|
#endif |