Matrix fix

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Matrix fix

Post by chronologicaldot »

hm... Maybe I forgot to report this, as I couldn't find it in the forum-search.
When using CMatrix<f64>, an error arises in function CMatrix4<T>::getInverse(CMatrix4<T>& out). The line of code with the error is 1330 where it says: if( core::iszero ( d, FLT_MIN ) ).
The problem is that FLT_MIN is floating point and "d" is double, resulting in the compiler not knowing what iszero() to use (or at least it gave me grief, of all people). For that, I created iszeroT( const T a, const T tolerance = 0 ) and I cast the FLT_MIN to (T). Yeah, it's not exactly correct, but c++ doesn't have type checking.

Code: Select all

 
template<class T>
inline bool iszeroT( const T a, const T tolerance = 0 )
{
    return abs_(a) < tolerance;
}
 
As a proposed fix to the matrix problem, we could add an enum for a parameter that allows the user to set what tolerances they want to use when comparing values. The defaults will be float, but at least the user has more control over getting the correct value. Plus, a param for this enum could be placed at the end of the parameter list in the constructors, set to the default of float.

Code: Select all

 
enum EMatrixTolerance
{
EMTOL_NONE, // no tolerance
EMTOL_F32,
EMTOL_F64
} matrixTolerance;
 
// usage as in the problem I presented...
switch( matrixTolerance )
{
case EMTOL_NONE: if ( iszero( (s32)d ) ) return false; break;
case EMTOL_F32: if ( iszero( (f32)d, FLT_MIN ) return false; break;
case EMTOL_F64: if ( iszero( (f64)d, DBL_MIN ) return false; break;
}
 
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Matrix fix

Post by CuteAlien »

Thanks for the report. There is a relatec topic here: http://irrlicht.sourceforge.net/forum/v ... 02#p283502
I hope I figure out a good solution before Irrlicht 1.9 release.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply