Changeset View
Changeset View
Standalone View
Standalone View
intern/elbeem/intern/ntl_vector3dim.h
| Context not available. | |||||
| // this serves as the main include file | // this serves as the main include file | ||||
| // for all kinds of stuff that might be required | // for all kinds of stuff that might be required | ||||
| // under windos there seem to be strange | // under windows there seem to be strange | ||||
| // errors when including the STL header too | // errors when including the STL header too | ||||
| // late... | // late... | ||||
| Context not available. | |||||
| #endif // WIN32 | #endif // WIN32 | ||||
| #endif // __APPLE_CC__ | #endif // __APPLE_CC__ | ||||
| // windos, hardcoded limits for now... | // windows, hardcoded limits for now... | ||||
| // for e.g. MSVC compiler... | // for e.g. MSVC compiler... | ||||
| // some of these defines can be needed | // some of these defines can be needed | ||||
| // for linux systems as well (e.g. FLT_MAX) | // for linux systems as well (e.g. FLT_MAX) | ||||
| Context not available. | |||||
| inline ntlVector3Dim<Scalar> getOrthogonalntlVector3Dim() const; | inline ntlVector3Dim<Scalar> getOrthogonalntlVector3Dim() const; | ||||
| // Project into a plane | // Project into a plane | ||||
| inline const ntlVector3Dim<Scalar>& projectNormalTo(const ntlVector3Dim<Scalar> &v); | inline const ntlVector3Dim<Scalar>& projectNormalTo(const ntlVector3Dim<Scalar> &v); | ||||
| // minimize | // minimize | ||||
| inline const ntlVector3Dim<Scalar> &minimize(const ntlVector3Dim<Scalar> &); | inline const ntlVector3Dim<Scalar> &minimize(const ntlVector3Dim<Scalar> &); | ||||
| // maximize | // maximize | ||||
| inline const ntlVector3Dim<Scalar> &maximize(const ntlVector3Dim<Scalar> &); | inline const ntlVector3Dim<Scalar> &maximize(const ntlVector3Dim<Scalar> &); | ||||
| // access operator | // access operator | ||||
| inline Scalar& operator[](unsigned int i); | inline Scalar& operator[](unsigned int i); | ||||
| // access operator | // access operator | ||||
| inline const Scalar& operator[](unsigned int i) const; | inline const Scalar& operator[](unsigned int i) const; | ||||
| protected: | protected: | ||||
| private: | private: | ||||
| Scalar value[3]; //< Storage of vector values | Scalar value[3]; //< Storage of vector values | ||||
| Context not available. | |||||
| { | { | ||||
| char buf[256]; | char buf[256]; | ||||
| snprintf(buf,256,globVecFormatStr,i[0],i[1],i[2]); | snprintf(buf,256,globVecFormatStr,i[0],i[1],i[2]); | ||||
| os << string(buf); | os << string(buf); | ||||
| //os << '[' << i[0] << ", " << i[1] << ", " << i[2] << ']'; | //os << '[' << i[0] << ", " << i[1] << ", " << i[2] << ']'; | ||||
| return os; | return os; | ||||
| } | } | ||||
| Context not available. | |||||
| \return A new vector with the product values | \return A new vector with the product values | ||||
| */ | */ | ||||
| /*template<class Scalar> | /*template<class Scalar> | ||||
| inline ntlVector3Dim<Scalar> | inline ntlVector3Dim<Scalar> | ||||
| ntlVector3Dim<Scalar>::operator^( const ntlVector3Dim<Scalar> &v ) const | ntlVector3Dim<Scalar>::operator^( const ntlVector3Dim<Scalar> &v ) const | ||||
| { | { | ||||
| return ntlVector3Dim<Scalar>(value[1]*v.value[2] - value[2]*v.value[1], | return ntlVector3Dim<Scalar>(value[1]*v.value[2] - value[2]*v.value[1], | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] = v.value[0]; | value[0] = v.value[0]; | ||||
| value[1] = v.value[1]; | value[1] = v.value[1]; | ||||
| value[2] = v.value[2]; | value[2] = v.value[2]; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] = s; | value[0] = s; | ||||
| value[1] = s; | value[1] = s; | ||||
| value[2] = s; | value[2] = s; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] += v.value[0]; | value[0] += v.value[0]; | ||||
| value[1] += v.value[1]; | value[1] += v.value[1]; | ||||
| value[2] += v.value[2]; | value[2] += v.value[2]; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] += s; | value[0] += s; | ||||
| value[1] += s; | value[1] += s; | ||||
| value[2] += s; | value[2] += s; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] -= v.value[0]; | value[0] -= v.value[0]; | ||||
| value[1] -= v.value[1]; | value[1] -= v.value[1]; | ||||
| value[2] -= v.value[2]; | value[2] -= v.value[2]; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0]-= s; | value[0]-= s; | ||||
| value[1]-= s; | value[1]-= s; | ||||
| value[2]-= s; | value[2]-= s; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] *= v.value[0]; | value[0] *= v.value[0]; | ||||
| value[1] *= v.value[1]; | value[1] *= v.value[1]; | ||||
| value[2] *= v.value[2]; | value[2] *= v.value[2]; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] *= s; | value[0] *= s; | ||||
| value[1] *= s; | value[1] *= s; | ||||
| value[2] *= s; | value[2] *= s; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| value[0] /= v.value[0]; | value[0] /= v.value[0]; | ||||
| value[1] /= v.value[1]; | value[1] /= v.value[1]; | ||||
| value[2] /= v.value[2]; | value[2] /= v.value[2]; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| template<class Scalar> | template<class Scalar> | ||||
| inline ntlVector3Dim<Scalar> cross(const ntlVector3Dim<Scalar> &t, const ntlVector3Dim<Scalar> &v) | inline ntlVector3Dim<Scalar> cross(const ntlVector3Dim<Scalar> &t, const ntlVector3Dim<Scalar> &v) | ||||
| { | { | ||||
| ntlVector3Dim<Scalar> cp( | ntlVector3Dim<Scalar> cp( | ||||
| ((t[1]*v[2]) - (t[2]*v[1])), | ((t[1]*v[2]) - (t[2]*v[1])), | ||||
| ((t[2]*v[0]) - (t[0]*v[2])), | ((t[2]*v[0]) - (t[0]*v[2])), | ||||
| ((t[0]*v[1]) - (t[1]*v[0])) ); | ((t[0]*v[1]) - (t[1]*v[0])) ); | ||||
| Context not available. | |||||
| Scalar sprod = dot(*this,v); | Scalar sprod = dot(*this,v); | ||||
| value[0]= value[0] - v.value[0] * sprod; | value[0]= value[0] - v.value[0] * sprod; | ||||
| value[1]= value[1] - v.value[1] * sprod; | value[1]= value[1] - v.value[1] * sprod; | ||||
| value[2]= value[2] - v.value[2] * sprod; | value[2]= value[2] - v.value[2] * sprod; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| Context not available. | |||||
| // ---- | // ---- | ||||
| // a 3D vector with double precision | // a 3D vector with double precision | ||||
| typedef ntlVector3Dim<double> ntlVec3d; | typedef ntlVector3Dim<double> ntlVec3d; | ||||
| // a 3D vector with single precision | // a 3D vector with single precision | ||||
| typedef ntlVector3Dim<float> ntlVec3f; | typedef ntlVector3Dim<float> ntlVec3f; | ||||
| // a 3D integer vector | // a 3D integer vector | ||||
| typedef ntlVector3Dim<int> ntlVec3i; | typedef ntlVector3Dim<int> ntlVec3i; | ||||
| // Color uses single precision fp values | // Color uses single precision fp values | ||||
| typedef ntlVec3f ntlColor; | typedef ntlVec3f ntlColor; | ||||
| Context not available. | |||||
| #ifdef PRECISION_GFX_DOUBLE | #ifdef PRECISION_GFX_DOUBLE | ||||
| #define GFX_PRECISION 2 | #define GFX_PRECISION 2 | ||||
| #else | #else | ||||
| // standard precision for graphics | // standard precision for graphics | ||||
| #ifndef GFX_PRECISION | #ifndef GFX_PRECISION | ||||
| #define GFX_PRECISION 1 | #define GFX_PRECISION 1 | ||||
| #endif | #endif | ||||
| #endif | #endif | ||||
| #endif | #endif | ||||
| #if GFX_PRECISION==1 | #if GFX_PRECISION==1 | ||||
| typedef float gfxReal; | typedef float gfxReal; | ||||
| #define GFX_REAL_MAX __FLT_MAX__ | #define GFX_REAL_MAX __FLT_MAX__ | ||||
| Context not available. | |||||
| typedef double gfxDouble; | typedef double gfxDouble; | ||||
| // a 3D vector for graphics output, typically float? | // a 3D vector for graphics output, typically float? | ||||
| typedef ntlVector3Dim<gfxReal> ntlVec3Gfx; | typedef ntlVector3Dim<gfxReal> ntlVec3Gfx; | ||||
| template<class T> inline ntlVec3Gfx vec2G(T v) { return ntlVec3Gfx(v[0],v[1],v[2]); } | template<class T> inline ntlVec3Gfx vec2G(T v) { return ntlVec3Gfx(v[0],v[1],v[2]); } | ||||
| Context not available. | |||||
| /************************************************************************* | /************************************************************************* | ||||
| Same as getNorm but doesnt sqrt | Same as getNorm but doesnt sqrt | ||||
| */ | */ | ||||
| template<class Scalar> | template<class Scalar> | ||||
| inline Scalar normNoSqrt( const VECTOR_TYPE &v) | inline Scalar normNoSqrt( const VECTOR_TYPE &v) | ||||
| Context not available. | |||||
| \return The value of the norm | \return The value of the norm | ||||
| */ | */ | ||||
| template<class Scalar> | template<class Scalar> | ||||
| inline Scalar normalize( VECTOR_TYPE &v) | inline Scalar normalize( VECTOR_TYPE &v) | ||||
| { | { | ||||
| Scalar norm; | Scalar norm; | ||||
| Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; | Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; | ||||
| if (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) { | if (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) { | ||||
| norm = 1.; | norm = 1.; | ||||
| } else if (l > VECTOR_EPSILON*VECTOR_EPSILON) { | } else if (l > VECTOR_EPSILON*VECTOR_EPSILON) { | ||||
| Context not available. | |||||
| Scalar fac = 1./norm; | Scalar fac = 1./norm; | ||||
| v[0] *= fac; | v[0] *= fac; | ||||
| v[1] *= fac; | v[1] *= fac; | ||||
| v[2] *= fac; | v[2] *= fac; | ||||
| } else { | } else { | ||||
| v[0]= v[1]= v[2]= 0; | v[0]= v[1]= v[2]= 0; | ||||
| norm = 0.; | norm = 0.; | ||||
| Context not available. | |||||
| \return The new reflected vector | \return The new reflected vector | ||||
| */ | */ | ||||
| template<class Scalar> | template<class Scalar> | ||||
| inline VECTOR_TYPE reflectVector(const VECTOR_TYPE &t, const VECTOR_TYPE &n) | inline VECTOR_TYPE reflectVector(const VECTOR_TYPE &t, const VECTOR_TYPE &n) | ||||
| { | { | ||||
| VECTOR_TYPE nn= (dot(t, n) > 0.0) ? (n*-1.0) : n; | VECTOR_TYPE nn= (dot(t, n) > 0.0) ? (n*-1.0) : n; | ||||
| return ( t - nn * (2.0 * dot(nn, t)) ); | return ( t - nn * (2.0 * dot(nn, t)) ); | ||||
| Context not available. | |||||
| * Taken from Glassner's book, section 5.2 (Heckberts method) | * Taken from Glassner's book, section 5.2 (Heckberts method) | ||||
| */ | */ | ||||
| template<class Scalar> | template<class Scalar> | ||||
| inline VECTOR_TYPE refractVector(const VECTOR_TYPE &t, const VECTOR_TYPE &normal, Scalar nt, Scalar nair, int &refRefl) | inline VECTOR_TYPE refractVector(const VECTOR_TYPE &t, const VECTOR_TYPE &normal, Scalar nt, Scalar nair, int &refRefl) | ||||
| { | { | ||||
| Scalar eta = nair / nt; | Scalar eta = nair / nt; | ||||
| Scalar n = -dot(t, normal); | Scalar n = -dot(t, normal); | ||||
| Context not available. | |||||
| template<class Scalar> | template<class Scalar> | ||||
| inline bool equal(const VECTOR_TYPE &v, const VECTOR_TYPE &c) | inline bool equal(const VECTOR_TYPE &v, const VECTOR_TYPE &c) | ||||
| { | { | ||||
| return (ABS(v[0]-c[0]) + | return (ABS(v[0]-c[0]) + | ||||
| ABS(v[1]-c[1]) + | ABS(v[1]-c[1]) + | ||||
| ABS(v[2]-c[2]) < VECTOR_EPSILON); | ABS(v[2]-c[2]) < VECTOR_EPSILON); | ||||
| } | } | ||||
| Context not available. | |||||