Attempting setOption("BrushArray")

Falagard

05-04-2006 19:48:25

Tuan,

I'm trying to use setOption("BrushArray") to pass my own brush for deforming the terrain.

I'm loading an array of floats from a 16x16 bitmap I've created, using some code that I copied from the Data2D_HeightField class in PLM2.

When I set the array and then deform the terrain, it looks like something is wrong with the either the brusharray or the deform code - like it has flipped the z with the x perhaps?

Here's a screenshot:





And my code for loading the brush:


Image image;
image.load("16x16CircularBrush.bmp", "General");

const uint bpp = static_cast<uint>(PixelUtil::getNumElemBytes(image.getFormat()));

if(image.getWidth() != image.getHeight() || bpp > 4)
{
//do nothing
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid brush image.", "PagingLandscapeEditorPlugin");
}
else
{
double scale = 0;

switch (bpp)
{
case 1:
scale = 1024.0f / 255.0f;
break;
case 2:
scale = 1024.0f / 65535.0f;
break;
case 3:
scale = 1024.0f / 16777215.0f;
break;
case 4:
scale = 1024.0f / 16777215.0f;
break;
}

float height = 0.0f;
const uchar* const ogre_restrict imageData = image.getData();
size_t dataSize = image.getSize();
mBrushArray = new float[image.getWidth() * image.getHeight()];
uint j = 0;

for(uint srcPos = 0; srcPos < image.getWidth() * image.getHeight() * bpp; srcPos += bpp)
{
switch(bpp)
{
case 1:
height = imageData[srcPos] * scale;
break;
case 2:
case 3:
case 4:
{
#if OGRE_ENDIAN == ENDIAN_BIG
ushort val = imageData[srcPos] << 8;
val += imageData[srcPos + 1];
#else
ushort val = imageData[srcPos];
val += imageData[srcPos + 1] << 8;
#endif
height = ((float)(val)) * scale;
}
break;
}
mBrushArray[j++] = height;
}

const uint brushArrayWidth = static_cast<uint>(image.getWidth());
const uint brushArrayHeight = static_cast<uint>(image.getHeight());
mSceneMgr->setOption("BrushArrayHeight", &brushArrayHeight);
mSceneMgr->setOption("BrushArrayWidth", &brushArrayWidth);
mSceneMgr->setOption("BrushArray", mBrushArray);
float brushScale = 1.0;
mSceneMgr->setOption("BrushScale", &brushScale);

}


I've looked at the PagingLandscapeSceneManager::deform code, and it does loop through z first and then x, but it also seems to be running along strides of the data, and ... well I wanted to know if you know anything about that before I dive too deep.

Also, if I change the deform code, then the resizecrater code will have to be modified as well, since it must be generating a wierd brush?

Alternatively I could flip all the data of my brush before I pass it to the PLM2 but I'm not sure what I need to do, I attempted a quick test at it and it didn't work as I expected :-)

Clay

tuan kuranes

06-04-2006 09:18:05

Looks like a Bug (image shift). I'll look into that asap.

tuan kuranes

06-04-2006 09:33:23

ok. found. fixed in cvs.

Falagard

06-04-2006 13:48:41

Awesome, thanks

Falagard

07-04-2006 16:47:49

What was the fix for this? I've updated to latest anonymous cvs head and am not seeing changed files, and it doesn't seem to be fixed?
I assume it was changes to OgrePagingLandScapeSceneManager.cpp or am I wrong?

I was looking through the history of each file for changes ;-)

Is there a way to see a a change list for each commit?

tuan kuranes

07-04-2006 16:54:09

not seeing changed files
I changed many, many files ("savedeformation" option make me do that) so I guess anon cvs is still not updated.
Using Dev CVS you'll have direct acess.
Changes/patch are also automatically mailed into ogre-cvs mailing list