Eldritch
28-04-2007 09:00:31
I want to be able to read the data from a loaded texture to build myself a navigation map from that texture. Here is the code I use, but it does not work:
I am not entirely sure I am doing it correctly from the beginning. I want to check each pixel for their color value. If it is white, then it will be blocked, otherwise it will be walkable. Am I on the right path here or totally in the blue?
public void Load(string strFilename)
{
m_ptrMap = TextureManager.Singleton.Load
(
strFilename,
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME
);
m_uiWidth = m_ptrMap.Width;
m_uiHeight = m_ptrMap.Height;
m_bNavData = new bool[m_uiWidth, m_uiHeight];
HardwarePixelBufferSharedPtr buf = m_ptrMap.GetBuffer();
unsafe
{
buf.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
PixelBox pixelBox = buf.CurrentLock;
uint* pSrc = (uint*)pixelBox.data;
for (int i = 0; i < m_uiWidth; i++)
{
for (int j = 0; j < m_uiHeight; j++)
{
uint R = (uint)(*pSrc++);
uint G = (uint)(*pSrc++);
uint B = (uint)(*pSrc++);
if ((R + G + B) / 3 >= 250)
m_bNavData[i, j] = false;
else
m_bNavData[i, j] = true;
}
}
}
buf.Unlock();
buf.Dispose();
m_ptrMap.Dispose();
}
I am not entirely sure I am doing it correctly from the beginning. I want to check each pixel for their color value. If it is white, then it will be blocked, otherwise it will be walkable. Am I on the right path here or totally in the blue?