Beauty

22-01-2012 23:53:26

19 monts ago, user manski wrote about a bug (hidden in a topic as off-topic).

Later I added it to the bugtracker #2 Mogre.Math.Sin() has problems

Here the quote:

Now I checked the source code.

I don't see what's the problem. (On the other hand, I'm very very tired and unconcentrated now.)

The only crash possibility I see, if the Math constructor has trigTableSize = 0 as parameter.

On the other hand manski wrote about a

Maybe others have an idea how to fix the bug.

Here is the related code:

The related code in in file

The method SinTable is in file

Related code in the same file:

Later I added it to the bugtracker #2 Mogre.Math.Sin() has problems

Here the quote:

Specifically in my case (using Mogre 1.7.1 beta):`Mogre.Math.Sin(0.0f, true)`

throws a DivisionByZero exception but`Mogre.Math.Sin(0.0f, false)`

doesn't. The same is true for "Cos(0.0f, true)".

Update:Neither of both functions seem to work at all when using lookup tables - no matter what angle is specified.

Update2:Found out that one needs to create a newinstanceof "Mogre.Math" to initialize itsstatictrig table lookup functions to work. (WTF?) It's not done automatically for whatever reason.

Now I checked the source code.

I don't see what's the problem. (On the other hand, I'm very very tired and unconcentrated now.)

The only crash possibility I see, if the Math constructor has trigTableSize = 0 as parameter.

On the other hand manski wrote about a

*DivisionByZeroException*.Maybe others have an idea how to fix the bug.

Here is the related code:

The related code in in file

**MogreMath.h**`static inline Real Sin (Real fValue, bool useTables) `

{

return (!useTables) ? Real(System::Math::Sin(fValue)) : SinTable(fValue);

}

The method SinTable is in file

**MogreMath.cpp**`Real Math::SinTable (Real fValue)`

{

// Convert range to index values, wrap if required

int idx;

if (fValue >= 0)

{

idx = int(fValue * mTrigTableFactor) % mTrigTableSize;

}

else

{

idx = mTrigTableSize - (int(-fValue * mTrigTableFactor) % mTrigTableSize) - 1;

}

return mSinTable[idx];

}

Related code in the same file:

`Math::Math() // constructor`

{

msAngleUnit = AngleUnit::AU_DEGREE;

mTrigTableSize = 4096;

mTrigTableFactor = mTrigTableSize / Math::TWO_PI;

mSinTable = gcnew array<Real>(mTrigTableSize);

mTanTable = gcnew array<Real>(mTrigTableSize);

buildTrigTables();

}

Math::Math( unsigned int trigTableSize ) // constructor 2

{

msAngleUnit = AngleUnit::AU_DEGREE;

mTrigTableSize = trigTableSize;

mTrigTableFactor = mTrigTableSize / Math::TWO_PI;

mSinTable = gcnew array<Real>(mTrigTableSize);

mTanTable = gcnew array<Real>(mTrigTableSize);

buildTrigTables();

}

//---------------------------------------

void Math::buildTrigTables(void)

{

// Build trig lookup tables

// Could get away with building only PI sized Sin table but simpler this

// way. Who cares, it'll ony use an extra 8k of memory anyway and I like

// simplicity.

Real angle;

for (int i = 0; i < mTrigTableSize; ++i)

{

angle = Math::TWO_PI * i / mTrigTableSize;

mSinTable* = sin(angle);*

mTanTable* = tan(angle);*

}

}