//----------------------------------------------------------------------- void PagingLandScapeData2D_HeightFieldNTC::_load( ) { mImage = new Image(); mImage -> load( PagingLandScapeOptions::getSingleton().landscape_filename + "." + PagingLandScapeOptions::getSingleton().landscape_extension, PagingLandScapeOptions::getSingleton().groupName); //check to make sure it's 2^n size. if ( !_checkSize( mImage->getHeight() ) || !_checkSize( mImage->getWidth() ) ) { String err = "Error: Invalid heightmap size : " + StringConverter::toString( static_cast <uint> (mImage->getWidth() )) + "," + StringConverter::toString( static_cast <uint> (mImage->getHeight()) ) + ". Should be 2^n, 2^n"; OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, err, "PagingLandScapeData2D_HeightFieldNTC::_load" ); } mBpp = PixelUtil::getNumElemBytes (mImage->getFormat ()); if (mBpp != 1) { OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "Error: Image is not a grayscale image.(1 byte, 8 bits)", "PagingLandScapeData2D_HeightFieldNTC::_load" ); } mSize = static_cast <uint> (mImage->getWidth()); mMax = static_cast <uint> (mSize * mImage->getHeight() * mBpp + 1); mMaxArrayPos = static_cast <uint> (mSize * mImage->getHeight()); mHeightData = new Real[mMaxArrayPos]; uint j = 0; const double divider = 1.0 / 255; const Real scale = PagingLandScapeOptions::getSingleton().scale.y; uchar *data = mImage->getData(); mMaxheight = 0.0f; const uint bpp = static_cast <uint> (mBpp); for (uint i = 0; i < mMax - 1; i += bpp ) { const Real h = _decodeTC(data[ i + (mBpp - 1)] * divider)* scale; mMaxheight = std::max ( h, mMaxheight); mHeightData[j++] = h; } }
//----------------------------------------------------------------------- bool PagingLandScapeData2D_HeightFieldTC::_load(const unsigned int mX, const unsigned int mZ) { const String strFileName = mParent->getOptions()->LandScape_filename + "." + StringConverter::toString(mZ) + "." + StringConverter::toString(mX) + "."; String finalName = strFileName + "modif." + mParent->getOptions()->LandScape_extension; if (!(mParent->getOptions()->Deformable && ResourceGroupManager::getSingleton().resourceExists(mParent->getOptions()->groupName, finalName))) { finalName = strFileName + mParent->getOptions()->LandScape_extension; if (!ResourceGroupManager::getSingleton().resourceExists(mParent->getOptions()->groupName, finalName)) { LogManager::getSingleton().logMessage(LML_CRITICAL, String("PLSM2 : Cannot find map named ") + finalName); return false; } } mImage = new Image(); mImage->load (finalName, mParent->getOptions()->groupName); //check to make sure it's 2^n + 1 size. if (mImage->getWidth() != mImage->getHeight() || !_checkSize(mImage->getWidth())) { String err = "Error: Invalid heightmap size : " + StringConverter::toString(static_cast<int>(mImage->getWidth())) + "," + StringConverter::toString(static_cast<int>(mImage->getHeight())) + ". Should be 2^n+1, 2^n+1"; OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, err, "PagingLandScapeData2D_HeightField::_load"); } mBpp = PixelUtil::getNumElemBytes (mImage->getFormat ()); if (mBpp != 1) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Error: Image is not a gray image.(1 bytes, 8 bits)", "PagingLandScapeData2D_HeightField::_load"); } if (mSize != mImage->getWidth()) { OGRE_EXCEPT (Exception::ERR_INVALIDPARAMS, "Error: Declared World size <> Height Map Size.", "PagingLandScapeData2D_HeightField::_load"); } mXDimension = mImage->getWidth(); mZDimension = mImage->getHeight(); mMax = static_cast <unsigned int> (mSize * mImage->getHeight() + 1); mMaxArrayPos = mMax - 1; mHeightData = new Real[mMaxArrayPos]; unsigned int j = 0; const double divider = 1.0 / 255; const Real scale = mParent->getOptions()->scale.y; uchar *data = mImage->getData(); mMaxheight = 0.0f; for (unsigned int i = 0; i < mMax - 1; i++) { const Real h = _decodeTC(data[ i ] * divider)* scale; mMaxheight = std::max (h, mMaxheight); mHeightData[j++] = h; } return true; }