Made the flipped y-axis on terrain import optional.

Pass a final boolean argument to TerrainBlock::import to control
y-axis flipping. It is enabled by default, since this was the previous
default behavior.

This should be added as an option in the terrain import dialog - see
game/tools/worldEditor/gui/guiTerrainImportGui.gui
This commit is contained in:
Daniel Buckmaster 2013-03-21 09:22:07 +11:00
parent 256735e35c
commit 6ff1db6c0c
4 changed files with 48 additions and 18 deletions

View file

@ -683,7 +683,8 @@ void TerrainFile::setHeightMap( const Vector<U16> &heightmap, bool updateCollisi
void TerrainFile::import( const GBitmap &heightMap,
F32 heightScale,
const Vector<U8> &layerMap,
const Vector<String> &materials )
const Vector<String> &materials,
bool flipYAxis)
{
AssertFatal( heightMap.getWidth() == heightMap.getHeight(), "TerrainFile::import - Height map is not square!" );
AssertFatal( isPow2( heightMap.getWidth() ), "TerrainFile::import - Height map is not power of two!" );
@ -702,23 +703,48 @@ void TerrainFile::import( const GBitmap &heightMap,
{
const F32 toFixedPoint = ( 1.0f / (F32)U16_MAX ) * floatToFixed( heightScale );
const U16 *iBits = (const U16*)heightMap.getBits();
for ( U32 i = 0; i < mSize * mSize; i++ )
if ( flipYAxis )
{
U16 height = convertBEndianToHost( *iBits );
*oBits = (U16)mCeil( (F32)height * toFixedPoint );
++oBits;
++iBits;
for ( U32 i = 0; i < mSize * mSize; i++ )
{
U16 height = convertBEndianToHost( *iBits );
*oBits = (U16)mCeil( (F32)height * toFixedPoint );
++oBits;
++iBits;
}
}
else
{
for(S32 y = mSize - 1; y >= 0; y--) {
for(U32 x = 0; x < mSize; x++) {
U16 height = convertBEndianToHost( *iBits );
mHeightMap[x + y * mSize] = (U16)mCeil( (F32)height * toFixedPoint );
++iBits;
}
}
}
}
else
{
const F32 toFixedPoint = ( 1.0f / (F32)U8_MAX ) * floatToFixed( heightScale );
const U8 *iBits = heightMap.getBits();
for ( U32 i = 0; i < mSize * mSize; i++ )
if ( flipYAxis )
{
*oBits = (U16)mCeil( ((F32)*iBits) * toFixedPoint );
++oBits;
iBits += heightMap.getBytesPerPixel();
for ( U32 i = 0; i < mSize * mSize; i++ )
{
*oBits = (U16)mCeil( ((F32)*iBits) * toFixedPoint );
++oBits;
iBits += heightMap.getBytesPerPixel();
}
}
else
{
for(S32 y = mSize - 1; y >= 0; y--) {
for(U32 x = 0; x < mSize; x++) {
mHeightMap[x + y * mSize] = (U16)mCeil( ((F32)*iBits) * toFixedPoint );
iBits += heightMap.getBytesPerPixel();
}
}
}
}