|
发表于 2010-2-21 09:15:00
|
显示全部楼层
Re:cegui圆形地图
正好也在找这个东西的做法,按照你的说法也做了一下,效率很低,没法用,做地图的放大,缩小效果也很差。代码贴给你好了。
void cSamllMapPanel: oad(const char *fileName)
{
WindowManager& winMgr = WindowManager::getSingleton();
//放大
Window* wndButton =
winMgr.getWindow( "samllMap/BigIt" );
wndButton->subscribeEvent(
FrameWindow::EventMouseClick,
Event::Subscriber(&cSamllMapPanel::handleMaxButton, this));
//缩小
wndButton =
winMgr.getWindow("samllMap/smallIt");
wndButton->subscribeEvent(
FrameWindow::EventMouseClick,
Event::Subscriber(&cSamllMapPanel::handleMinButton, this));
//大地图
wndButton =
winMgr.getWindow("samllMap/BigMap");
wndButton->subscribeEvent(
FrameWindow::EventMouseClick,
Event::Subscriber(&cSamllMapPanel::handleBigMapButton, this));
//left
wndButton =
winMgr.getWindow("samllMap/Left");
wndButton->subscribeEvent(
FrameWindow::EventMouseClick,
Event::Subscriber(&cSamllMapPanel::handleLeftButton, this));
//right
wndButton =
winMgr.getWindow("samllMap/Right");
wndButton->subscribeEvent(
FrameWindow::EventMouseClick,
Event::Subscriber(&cSamllMapPanel::handleRightButton, this));
Window* pWin= m_pkWindow->getChildRecursive("samllMap/mapFrame");
//创建带遮罩的图像
CEGUI::Texture& tex = System::getSingletonPtr()->getRenderer()->createTexture();
tex.loadFromFile("smallMapMask.tga", "imagesets");
CEGUI::Imageset& imSet = CEGUI::ImagesetManager::getSingleton().create("smallMap1Mask",tex);
if ( !imSet.isImageDefined("full_image") )
{
CEGUI::Size sz = imSet.getTexture()->getSize();
imSet.defineImage("full_image",CEGUI: oint(0,0),sz,CEGUI::Point(0,0) );
}
pWin->setProperty("Image","set:smallMap1Mask image:full_image");
{
//读取真正的地图纹理
CEGUI::Texture& tex = System::getSingletonPtr()->getRenderer()->createTexture();
tex.loadFromFile("smallMap.tga", "imagesets");
CEGUI::Imageset& imSet = CEGUI::ImagesetManager::getSingleton().create("smallMap1",tex);
if ( !imSet.isImageDefined("full_image") )
{
CEGUI::Size sz = imSet.getTexture()->getSize();
imSet.defineImage("full_image",CEGUI::Point(0,0),sz,CEGUI::Point(0,0) );
}
}
//填充地图到带遮罩的纹理文件中去
colorMap ccm;
ccm = Getd3dTex("smallMap1","full_image");
FillImageSetWithColorMap(ccm,(CEGUI: irect3D9Texture *)imSet.getTexture());
}
void cSamllMapPanel::FillImageSetWithColorMap(colorMap &c,CEGUI::Direct3D9Texture* tex,float fScale)
{
LPDIRECT3DTEXTURE9 d3dT = tex->getDirect3D9Texture();
D3DLOCKED_RECT rect;
CEGUI::Size sz = tex->getSize();
HRESULT hr = d3dT->LockRect(0,&rect,0,D3DLOCK_DISCARD);
uint32* dst = static_cast<uint32*>(rect.pBits);
int yDraw=0;
yDraw = min(sz.d_height,c.size());
for (uint i = 0; i < yDraw; ++i)
{
//根据插值大小得到列,放大一张图片是图片变粗糙,则有些列的像素相同
//所有一张图片则需要从更大的空间获取像素
fScale = 1.0/fScale;
int col = (int)(fScale * i);
if(col>c.size())
{
col = c.size() - 1;
}
lineColor lc = c.at(col);
int xDraw = min(sz.d_width,lc.size());
for (uint j = 0; j < xDraw; ++j)
{
int row = (int)(fScale*j);
if (row>lc.size())
{
row = lc.size() - 1;
}
unsigned int color = lc.at(row);
uchar r = static_cast<uchar>(color & 0xFF);
uchar g = static_cast<uchar>((color >> 8) & 0xFF);
uchar b = static_cast<uchar>((color >> 16) & 0xFF);
uchar a = static_cast<uchar>((color >> 24) & 0xFF);
uchar selfA = static_cast<uchar>(( dst[j]>>24) & 0xFF);
dst[j] = D3DCOLOR_ARGB(selfA, b, g, r);
}
dst += rect.Pitch / sizeof(ulong);
}
d3dT->UnlockRect(0);
}
可以看我的blog里更加详细的,放大,缩小,平移等等。http://songxiaoyu8.blog.163.com/blog/static/20818128201012191258533 |
|