I noticed a very strange thing in my application. There are two static const integers in my World class:
class World
{
public:
static const int CHUNK_SIZE_X = 32;
private:
static const int SHIFT_X;
};
The constant SHIFT_X is initialised in the corresponding *.cpp file:
const int World::SHIFT_X = Ogre::Math::Log2(World::CHUNK_SIZE_X);
Now the strange thing is that the value in SHIFT_X is 4 instead of 5. If I call Ogre::Math::Log2(32) from within an arbitrary method it correctly computes 5.
What the hell is going on here? I also need to say that this only happens under Windows 7 (with Visual Studio Express 10). My application also runs under GNU/Linux (Debian Squeeze) and there everything works fine.
Ogre::Math::Log2returns aRealwhich is actually afloatand you are trying to store it as an int. Therefore if the value returned was 4.9999999999999998 it would still end up with 4 after the conversion. If you would like to continue using anintinstead of afloatyou should round the value.