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
struct SJoint
{
SJoint() :
Name(""), LocalMatrix(),
Children(), PositionKeys(), ScaleKeys(), RotationKeys(), Weights(),
UseAnimationFrom(0), LocalAnimatedMatrix_Animated(false),positionHint(-1),scaleHint(-1),rotationHint(-1)
SJoint() : UseAnimationFrom(0), LocalAnimatedMatrix_Animated(false),
positionHint(-1),scaleHint(-1),rotationHint(-1)
{
}

View File

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

View File

@ -148,6 +148,12 @@ namespace core
//! Rotate a vector by the rotation part of this matrix.
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
void transformVect( vector3df& vect) const;
@ -157,9 +163,6 @@ namespace core
//! An alternate transform vector method, writing into an array of 4 floats
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.
void translateVect( vector3df& vect ) const;
@ -475,8 +478,19 @@ namespace core
template <class T>
inline CMatrix4<T>& CMatrix4<T>::operator*=(const CMatrix4<T>& other)
{
CMatrix4<T> temp ( *this );
setbyproduct ( temp, other );
// do chacks on your own in order to avoid copy creation
if ( !other.isIdentity() )
{
if ( this->isIdentity() )
{
*this = other;
}
else
{
CMatrix4<T> temp ( *this );
setbyproduct_nocheck( temp, other );
}
}
return *this;
}
@ -798,9 +812,18 @@ namespace core
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
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[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
{
return core::equals(X, other.X) &&
core::equals(Y, other.Y) &&
core::equals(Z, other.Z);
return this->equals(other);
}
bool operator!=(const vector3d<T>& other) const
{
return !core::equals(X, other.X) ||
!core::equals(Y, other.Y) ||
!core::equals(Z, other.Z);
return !this->equals(other);
}
// functions
//! 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) &&
core::equals(Y, other.Y, tolerance) &&