32 #ifndef Vector3_INCLUDE_ONCE 33 #define Vector3_INCLUDE_ONCE 43 template<
typename T_Scalar>
56 x() = (T_Scalar)other.x();
57 y() = (T_Scalar)other.y();
58 z() = (T_Scalar)other.z();
61 explicit Vector3(
const scalar_ptr_type& pval)
90 const T_Scalar&
x()
const {
return mScalar[0]; }
91 const T_Scalar&
y()
const {
return mScalar[1]; }
92 const T_Scalar&
z()
const {
return mScalar[2]; }
98 const T_Scalar&
r()
const {
return mScalar[0]; }
99 const T_Scalar&
g()
const {
return mScalar[1]; }
155 *
this = *
this + other;
160 *
this = *
this - other;
165 *
this = *
this * other;
170 *
this = *
this / other;
202 x() =
y() =
z() = val;
207 return x() == other.
x() &&
y() == other.
y() &&
z() == other.
z();
215 if (
x() != other.
x())
216 return x() < other.
x();
218 if (
y() != other.
y())
219 return y() < other.
y();
221 return z() < other.
z();
234 *
this *= (T_Scalar)(1.0/l);
265 #if VL_PIPELINE_PRECISION == 2 273 inline float dot(
const fvec3& v1,
const fvec3& v2) {
return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z(); }
274 inline double dot(
const dvec3& v1,
const dvec3& v2) {
return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z(); }
275 inline float dot(
const ivec3& v1,
const ivec3& v2) {
return (
float)(v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z()); }
276 inline float dot(
const uvec3& v1,
const uvec3& v2) {
return (
float)(v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z()); }
278 inline fvec3
cross(
const fvec3& v1,
const fvec3& v2)
281 t.
x() = v1.
y()*v2.
z() - v1.
z()*v2.
y();
282 t.
y() = v1.
z()*v2.
x() - v1.
x()*v2.
z();
283 t.
z() = v1.
x()*v2.
y() - v1.
y()*v2.
x();
287 inline dvec3
cross(
const dvec3& v1,
const dvec3& v2)
290 t.
x() = v1.
y()*v2.
z() - v1.
z()*v2.
y();
291 t.
y() = v1.
z()*v2.
x() - v1.
x()*v2.
z();
292 t.
z() = v1.
x()*v2.
y() - v1.
y()*v2.
x();
296 inline fvec3
min(
const fvec3& a,
const fvec3&
b)
298 return fvec3( a.
x() < b.
x() ? a.
x() : b.
x(),
299 a.
y() < b.
y() ? a.
y() : b.
y(),
300 a.
z() < b.
z() ? a.
z() : b.
z() );
302 inline fvec3
min(
const fvec3& a,
float b)
304 return fvec3( a.
x() < b ? a.
x() :
b,
305 a.
y() < b ? a.
y() :
b,
306 a.
z() < b ? a.
z() :
b );
308 inline dvec3
min(
const dvec3& a,
const dvec3&
b)
310 return dvec3( a.
x() < b.
x() ? a.
x() : b.
x(),
311 a.
y() < b.
y() ? a.
y() : b.
y(),
312 a.
z() < b.
z() ? a.
z() : b.
z() );
314 inline dvec3
min(
const dvec3& a,
double b)
316 return dvec3( a.
x() < b ? a.
x() :
b,
317 a.
y() < b ? a.
y() :
b,
318 a.
z() < b ? a.
z() :
b );
320 inline ivec3
min(
const ivec3& a,
const ivec3&
b)
322 return ivec3( a.
x() < b.
x() ? a.
x() : b.
x(),
323 a.
y() < b.
y() ? a.
y() : b.
y(),
324 a.
z() < b.
z() ? a.
z() : b.
z() );
326 inline ivec3
min(
const ivec3& a,
int b)
328 return ivec3( a.
x() < b ? a.
x() :
b,
329 a.
y() < b ? a.
y() :
b,
330 a.
z() < b ? a.
z() :
b );
332 inline uvec3
min(
const uvec3& a,
const uvec3&
b)
334 return uvec3( a.
x() < b.
x() ? a.
x() : b.
x(),
335 a.
y() < b.
y() ? a.
y() : b.
y(),
336 a.
z() < b.
z() ? a.
z() : b.
z() );
338 inline uvec3
min(
const uvec3& a,
unsigned int b)
340 return uvec3( a.
x() < b ? a.
x() :
b,
341 a.
y() < b ? a.
y() :
b,
342 a.
z() < b ? a.
z() :
b );
344 inline fvec3
max(
const fvec3& a,
const fvec3&
b)
346 return fvec3( a.
x() > b.
x() ? a.
x() : b.
x(),
347 a.
y() > b.
y() ? a.
y() : b.
y(),
348 a.
z() > b.
z() ? a.
z() : b.
z() );
350 inline fvec3
max(
const fvec3& a,
float b)
352 return fvec3( a.
x() > b ? a.
x() :
b,
353 a.
y() > b ? a.
y() :
b,
354 a.
z() > b ? a.
z() :
b );
356 inline dvec3
max(
const dvec3& a,
const dvec3&
b)
358 return dvec3( a.
x() > b.
x() ? a.
x() : b.
x(),
359 a.
y() > b.
y() ? a.
y() : b.
y(),
360 a.
z() > b.
z() ? a.
z() : b.
z() );
362 inline dvec3
max(
const dvec3& a,
double b)
364 return dvec3( a.
x() > b ? a.
x() :
b,
365 a.
y() > b ? a.
y() :
b,
366 a.
z() > b ? a.
z() :
b );
368 inline ivec3
max(
const ivec3& a,
const ivec3&
b)
370 return ivec3( a.
x() > b.
x() ? a.
x() : b.
x(),
371 a.
y() > b.
y() ? a.
y() : b.
y(),
372 a.
z() > b.
z() ? a.
z() : b.
z() );
374 inline ivec3
max(
const ivec3& a,
int b)
376 return ivec3( a.
x() > b ? a.
x() :
b,
377 a.
y() > b ? a.
y() :
b,
378 a.
z() > b ? a.
z() :
b );
380 inline uvec3
max(
const uvec3& a,
const uvec3&
b)
382 return uvec3( a.
x() > b.
x() ? a.
x() : b.
x(),
383 a.
y() > b.
y() ? a.
y() : b.
y(),
384 a.
z() > b.
z() ? a.
z() : b.
z() );
386 inline uvec3
max(
const uvec3& a,
unsigned int b)
388 return uvec3( a.
x() > b ? a.
x() :
b,
389 a.
y() > b ? a.
y() :
b,
390 a.
z() > b ? a.
z() :
b );
392 inline fvec3
clamp(
const fvec3&
x,
float minval,
float maxval) {
return min(
max(x,minval),maxval); }
393 inline fvec3
clamp(
const fvec3&
x,
const fvec3& minval,
const fvec3& maxval) {
return min(
max(x,minval),maxval); }
394 inline ivec3
clamp(
const ivec3&
x,
const ivec3& minval,
const ivec3& maxval) {
return min(
max(x,minval),maxval); }
395 inline dvec3
clamp(
const dvec3&
x,
double minval,
double maxval) {
return min(
max(x,minval),maxval); }
396 inline dvec3
clamp(
const dvec3&
x,
const dvec3& minval,
const dvec3& maxval) {
return min(
max(x,minval),maxval); }
397 inline ivec3
clamp(
const ivec3&
x,
int minval,
int maxval) {
return min(
max(x,minval),maxval); }
398 inline uvec3
clamp(
const uvec3&
x,
unsigned int minval,
unsigned int maxval) {
return min(
max(x,minval),maxval); }
399 inline uvec3
clamp(
const uvec3&
x,
const uvec3& minval,
const uvec3& maxval) {
return min(
max(x,minval),maxval); }
Vector3 & operator=(T_Scalar val)
float clamp(float x, float minval, float maxval)
bool operator==(const Vector3 &other) const
const Vector3 & normalize(T_Scalar *len=NULL)
Vector3(T_Scalar x, T_Scalar y, T_Scalar z)
Vector3< float > fvec3
A 3 components vector with float precision.
const T_Scalar & b() const
Vector3 & operator+=(T_Scalar val)
Vector3 & operator-=(const Vector3 &other)
const T_Scalar & z() const
Vector3 operator*(const Vector3 &other) const
Vector3 & operator*=(T_Scalar val)
bool operator!=(const Vector3 &other) const
Vector3 operator*(T_Scalar val) const
Vector3 operator-() const
Vector3< unsigned char > ubvec3
A 3 components vector with unsigned char precision.
fvec3 cross(const fvec3 &v1, const fvec3 &v2)
T_Scalar mScalar[scalar_count]
const T_Scalar & r() const
Vector3 & operator/=(const Vector3 &other)
Vector3 operator-(const Vector3 &other) const
Vector2< T_Scalar > xy() const
Visualization Library main namespace.
float dot(float a, float b)
Vector3< short > svec3
A 3 components vector with short precision.
Vector3 operator-(T_Scalar val) const
T_Scalar lengthSquared() const
The Vector3 class is a template class that implements a generic 3 components vector, see also vl::fvec3, vl::dvec3, vl::uvec3, vl::ivec3, vl::svec3, vl::usvec3, vl::bvec3, vl::ubvec3.
Vector3 operator/(const Vector3 &other) const
float max(float a, float b)
const T_Scalar & operator[](unsigned i) const
float min(float a, float b)
Vector3 operator/(T_Scalar val) const
T_Scalar * scalar_ptr_type
Vector3< double > dvec3
A 3 components vector with double precision.
Vector3 operator+(T_Scalar val) const
const T_Scalar & y() const
Vector3< unsigned int > uvec3
A 3 components vector with unsigned int precision.
const T_Scalar & s() const
const T_Scalar & p() const
Vector3< int > ivec3
A 3 components vector with int precision.
Vector3 & operator+=(const Vector3 &other)
The Vector2 class is a template class that implements a generic 2 components vector, see also vl::fvec2, vl::dvec2, vl::uvec2, vl::ivec2, vl::svec2, vl::usvec2, vl::bvec2, vl::ubvec2.
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
const T_Scalar & t() const
Vector3 & operator=(const Vector3 &other)
Vector3(const Vector3 &other)
Vector3(const scalar_ptr_type &pval)
bool operator<(const Vector3 &other) const
const T_Scalar & x() const
Vector2< T_Scalar > st() const
const T_Scalar * ptr() const
Vector3(const Vector2< T_Scalar > &v, T_Scalar z)
const T_Scalar & x() const
Vector3 operator+(const Vector3 &other) const
Vector3 & operator-=(T_Scalar val)
Vector3< unsigned short > usvec3
A 3 components vector with unsigned short precision.
T_Scalar & operator[](unsigned i)
Vector3 & operator/=(T_Scalar val)
static const int scalar_count
const T_Scalar & y() const
Vector3< char > bvec3
A 3 components vector with char precision.
const T_Scalar & g() const
Vector3 & operator*=(const Vector3 &other)