Some new convenience functions and fixes for template usage.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@946 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2007-09-12 17:46:58 +00:00
parent 8772a2cd8d
commit 17ed8d5b60
4 changed files with 62 additions and 22 deletions

View File

@ -123,10 +123,8 @@ namespace scene
//! Joints //! Joints
struct SJoint struct SJoint
{ {
SJoint() : SJoint() : UseAnimationFrom(0), LocalAnimatedMatrix_Animated(false),
Name(""), LocalMatrix(), positionHint(-1),scaleHint(-1),rotationHint(-1)
Children(), PositionKeys(), ScaleKeys(), RotationKeys(), Weights(),
UseAnimationFrom(0), LocalAnimatedMatrix_Animated(false),positionHint(-1),scaleHint(-1),rotationHint(-1)
{ {
} }

View File

@ -17,6 +17,7 @@
#define floorf(X) (f32)floor(X) #define floorf(X) (f32)floor(X)
#define powf(X,Y) (f32)pow(X,Y) #define powf(X,Y) (f32)pow(X,Y)
#define fmodf(X,Y) (f32)fmod(X,Y) #define fmodf(X,Y) (f32)fmod(X,Y)
#define fabsf(X) (f32)fabs(X)
#endif #endif
namespace irr namespace irr
@ -111,18 +112,40 @@ namespace core
return min_ (max_(value,low), high); return min_ (max_(value,low), high);
} }
//! returns if a float equals the other one, taking floating //! returns if a equals b, taking possible rounding errors into account
//! point rounding errors into account
inline bool equals(const f32 a, const f32 b, const f32 tolerance = ROUNDING_ERROR_32) inline bool equals(const f32 a, const f32 b, const f32 tolerance = ROUNDING_ERROR_32)
{ {
return (a + tolerance >= b) && (a - tolerance <= b); return (a + tolerance >= b) && (a - tolerance <= b);
} }
//! returns if a float equals zero, taking floating //! returns if a equals b, taking possible rounding errors into account
//! point rounding errors into account inline bool equals(const s32 a, const s32 b, const s32 tolerance = 0)
{
return (a + tolerance >= b) && (a - tolerance <= b);
}
//! returns if a equals b, taking possible rounding errors into account
inline bool equals(const u32 a, const u32 b, const u32 tolerance = 0)
{
return (a + tolerance >= b) && (a - tolerance <= b);
}
//! returns if a equals zero, taking rounding errors into account
inline bool iszero(const f32 a, const f32 tolerance = ROUNDING_ERROR_32) inline bool iszero(const f32 a, const f32 tolerance = ROUNDING_ERROR_32)
{ {
return fabs ( a ) <= tolerance; return fabsf ( a ) <= tolerance;
}
//! returns if a equals zero, taking rounding errors into account
inline bool iszero(const s32 a, const s32 tolerance = 0)
{
return ( a & 0x7ffffff ) <= tolerance;
}
//! returns if a equals zero, taking rounding errors into account
inline bool iszero(const u32 a, const u32 tolerance = 0)
{
return a <= tolerance;
} }
inline s32 s32_min ( s32 a, s32 b) inline s32 s32_min ( s32 a, s32 b)

View File

@ -148,6 +148,12 @@ namespace core
//! Rotate a vector by the rotation part of this matrix. //! Rotate a vector by the rotation part of this matrix.
void rotateVect( vector3df& vect ) const; void rotateVect( vector3df& vect ) const;
//! An alternate transform vector method, writing into a second vector
void rotateVect(vector3df& out,const core::vector3df& in) const;
//! An alternate transform vector method, writing into an array of 3 floats
void rotateVect(T *out,const core::vector3df &in) const;
//! Transforms the vector by this matrix //! Transforms the vector by this matrix
void transformVect( vector3df& vect) const; void transformVect( vector3df& vect) const;
@ -157,9 +163,6 @@ namespace core
//! An alternate transform vector method, writing into an array of 4 floats //! An alternate transform vector method, writing into an array of 4 floats
void transformVect(T *out,const core::vector3df &in) const; void transformVect(T *out,const core::vector3df &in) const;
//! An alternate transform vector method, writing into an array of 3 floats
void rotateVect(T *out,const core::vector3df &in) const;
//! Translate a vector by the translation part of this matrix. //! Translate a vector by the translation part of this matrix.
void translateVect( vector3df& vect ) const; void translateVect( vector3df& vect ) const;
@ -475,8 +478,19 @@ namespace core
template <class T> template <class T>
inline CMatrix4<T>& CMatrix4<T>::operator*=(const CMatrix4<T>& other) inline CMatrix4<T>& CMatrix4<T>::operator*=(const CMatrix4<T>& other)
{ {
CMatrix4<T> temp ( *this ); // do chacks on your own in order to avoid copy creation
setbyproduct ( temp, other ); if ( !other.isIdentity() )
{
if ( this->isIdentity() )
{
*this = other;
}
else
{
CMatrix4<T> temp ( *this );
setbyproduct_nocheck( temp, other );
}
}
return *this; return *this;
} }
@ -798,9 +812,18 @@ namespace core
vect.Z = tmp.X*M[2] + tmp.Y*M[6] + tmp.Z*M[10]; vect.Z = tmp.X*M[2] + tmp.Y*M[6] + tmp.Z*M[10];
} }
//! An alternate transform vector method, writing into a second vector
template <class T>
inline void CMatrix4<T>::rotateVect(core::vector3df& out, const core::vector3df& in) const
{
out.X = in.X*M[0] + in.Y*M[4] + in.Z*M[8];
out.Y = in.X*M[1] + in.Y*M[5] + in.Z*M[9];
out.Z = in.X*M[2] + in.Y*M[6] + in.Z*M[10];
}
//! An alternate transform vector method, writing into an array of 3 floats //! An alternate transform vector method, writing into an array of 3 floats
template <class T> template <class T>
inline void CMatrix4<T>::rotateVect(T *out,const core::vector3df &in) const inline void CMatrix4<T>::rotateVect(T *out, const core::vector3df& in) const
{ {
out[0] = in.X*M[0] + in.Y*M[4] + in.Z*M[8]; out[0] = in.X*M[0] + in.Y*M[4] + in.Z*M[8];
out[1] = in.X*M[1] + in.Y*M[5] + in.Z*M[9]; out[1] = in.X*M[1] + in.Y*M[5] + in.Z*M[9];

View File

@ -55,22 +55,18 @@ namespace core
bool operator==(const vector3d<T>& other) const bool operator==(const vector3d<T>& other) const
{ {
return core::equals(X, other.X) && return this->equals(other);
core::equals(Y, other.Y) &&
core::equals(Z, other.Z);
} }
bool operator!=(const vector3d<T>& other) const bool operator!=(const vector3d<T>& other) const
{ {
return !core::equals(X, other.X) || return !this->equals(other);
!core::equals(Y, other.Y) ||
!core::equals(Z, other.Z);
} }
// functions // functions
//! returns if this vector equals the other one, taking floating point rounding errors into account //! returns if this vector equals the other one, taking floating point rounding errors into account
bool equals(const vector3d<T>& other, const f32 tolerance = ROUNDING_ERROR_32 ) const bool equals(const vector3d<T>& other, const T tolerance = (T)ROUNDING_ERROR_32 ) const
{ {
return core::equals(X, other.X, tolerance) && return core::equals(X, other.X, tolerance) &&
core::equals(Y, other.Y, tolerance) && core::equals(Y, other.Y, tolerance) &&