本文整理汇总了C++中ogre::Image::getColourAt方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::getColourAt方法的具体用法?C++ Image::getColourAt怎么用?C++ Image::getColourAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Image
的用法示例。
在下文中一共展示了Image::getColourAt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateRelief
void ReliefApp::GenerateRelief()
{
//Get depth data
Ogre::TexturePtr depthTex = Ogre::TextureManager::getSingleton().createManual(
"DepthTexture", // name
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, // type
512, // width
512, // height
0, // number of mipmaps
//Ogre::PF_B8G8R8A8, // pixel format
Ogre::PF_FLOAT32_R,
Ogre::TU_RENDERTARGET
);
Ogre::RenderTarget* pTarget = depthTex->getBuffer()->getRenderTarget();
Ogre::Camera* pOrthCam = MagicCore::RenderSystem::GetSingleton()->GetMainCamera();
pOrthCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
pOrthCam->setOrthoWindow(3, 3);
pOrthCam->setPosition(0, 0, 3);
pOrthCam->lookAt(0, 0, 0);
pOrthCam->setAspectRatio(1.0);
pOrthCam->setNearClipDistance(0.5);
pOrthCam->setFarClipDistance(5);
Ogre::Viewport* pViewport = pTarget->addViewport(pOrthCam);
pViewport->setDimensions(0, 0, 1, 1);
MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "Depth", mpLightMesh);
MagicCore::RenderSystem::GetSingleton()->Update();
Ogre::Image img;
depthTex->convertToImage(img);
std::vector<double> heightField(512 * 512);
for(int x = 0; x < 512; x++)
{
for(int y = 0; y < 512; y++)
{
heightField.at(x * 512 + y) = (img.getColourAt(x, 511 - y, 0))[1];
}
}
Ogre::TextureManager::getSingleton().remove("DepthTexture");
//
MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::PlaneReliefFromHeightField(heightField, 511, 511);
//MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::CylinderReliefFromHeightField(heightField, 511, 511);
if (pReliefMesh != NULL)
{
delete mpLightMesh;
mpLightMesh = pReliefMesh;
mpLightMesh->UnifyPosition(2);
mpLightMesh->UpdateNormal();
}
MagicCore::RenderSystem::GetSingleton()->SetupCameraDefaultParameter();
MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "MyCookTorrance", mpLightMesh);
}
示例2: exploreCell
void GlobalMap::exploreCell(int cellX, int cellY)
{
float originX = static_cast<float>((cellX - mMinX) * mCellSize);
// NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
float originY = static_cast<float>(mHeight - (cellY + 1 - mMinY) * mCellSize);
if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
return;
Ogre::TexturePtr localMapTexture = Ogre::TextureManager::getSingleton().getByName("Cell_"
+ boost::lexical_cast<std::string>(cellX) + "_" + boost::lexical_cast<std::string>(cellY));
if (!localMapTexture.isNull())
{
int mapWidth = localMapTexture->getWidth();
int mapHeight = localMapTexture->getHeight();
mOverlayTexture->load();
mOverlayTexture->getBuffer()->blit(localMapTexture->getBuffer(), Ogre::Image::Box(0,0,mapWidth,mapHeight),
Ogre::Image::Box(static_cast<Ogre::uint32>(originX), static_cast<Ogre::uint32>(originY),
static_cast<Ogre::uint32>(originX + mCellSize), static_cast<Ogre::uint32>(originY + mCellSize)));
Ogre::Image backup;
std::vector<Ogre::uchar> data;
data.resize(mCellSize*mCellSize*4, 0);
backup.loadDynamicImage(&data[0], mCellSize, mCellSize, Ogre::PF_A8B8G8R8);
localMapTexture->getBuffer()->blitToMemory(Ogre::Image::Box(0,0,mapWidth,mapHeight), backup.getPixelBox());
for (int x=0; x<mCellSize; ++x)
for (int y=0; y<mCellSize; ++y)
{
assert (originX+x < mOverlayImage.getWidth());
assert (originY+y < mOverlayImage.getHeight());
assert (x < int(backup.getWidth()));
assert (y < int(backup.getHeight()));
mOverlayImage.setColourAt(backup.getColourAt(x, y, 0), static_cast<size_t>(originX + x), static_cast<size_t>(originY + y), 0);
}
}
}
示例3: initBlendMaps
void TerrainGeometryManager::initBlendMaps(int x, int z, Ogre::Terrain* terrain )
{
bool debugBlendMaps = BOPT("DebugBlendMaps", false);
int layerCount = terrain->getLayerCount();
for (int i = 1; i < layerCount; i++)
{
blendLayerInfo_t &bi = blendInfo[i];
if(bi.blendMapTextureFilename.empty()) continue;
Ogre::Image img;
//std::pair<uint8,uint8> textureIndex = terrain->getLayerBlendTextureIndex(i);
//uint8 bti = terrain->getBlendTextureIndex(i);
try
{
img.load(bi.blendMapTextureFilename, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
} catch(Exception &e)
{
LOG("Error loading blendmap: " + bi.blendMapTextureFilename + " : " + e.getFullDescription());
continue;
}
TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(i);
// resize that blending map so it will fit
Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize();
if (img.getWidth() != blendmapSize)
img.resize(blendmapSize, blendmapSize);
// now to the ugly part
float* ptr = blendmap->getBlendPointer();
for (Ogre::uint32 z = 0; z != blendmapSize; z++)
{
for (Ogre::uint32 x = 0; x != blendmapSize; x++)
{
Ogre::ColourValue c = img.getColourAt(x, z, 0);
float alpha = bi.alpha;
if (bi.blendMode == 'R')
*ptr++ = c.r * alpha;
else if (bi.blendMode == 'G')
*ptr++ = c.g * alpha;
else if (bi.blendMode == 'B')
*ptr++ = c.b * alpha;
else if (bi.blendMode == 'A')
*ptr++ = c.a * alpha;
}
}
blendmap->dirty();
blendmap->update();
}
if (debugBlendMaps)
{
for (int i = 1; i < layerCount; i++)
{
Ogre::TerrainLayerBlendMap* blendMap = terrain->getLayerBlendMap(i);
Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize();
Ogre::Image img;
unsigned short *idata = OGRE_ALLOC_T(unsigned short, blendmapSize * blendmapSize, Ogre::MEMCATEGORY_RESOURCE);
float scale = 65535.0f;
for (unsigned int x = 0; x < blendmapSize; x++)
for (unsigned int z = 0; z < blendmapSize; z++)
idata[x + z * blendmapSize] = (unsigned short)(blendMap->getBlendValue(x, blendmapSize - z) * scale);
img.loadDynamicImage((Ogre::uchar*)(idata), blendmapSize, blendmapSize, Ogre::PF_L16);
std::string fileName = "blendmap_layer_" + Ogre::StringConverter::toString(i) + ".png";
img.save(fileName);
OGRE_FREE(idata, Ogre::MEMCATEGORY_RESOURCE);
}
}
}
示例4: GetSceneManipulator
void
BrushSelector::buildPreviewBitmap( const Fairy::TextureInfo texInfo )
{
const Ogre::uchar BytePerPixel = 8;
// 读取原始image
Ogre::Image *oriImage = GetSceneManipulator()->getPreviewImage(texInfo.ownerTextureName);
// 源大纹理的大小
size_t oriImageHeight = oriImage->getHeight();
size_t oriImageWidth = oriImage->getWidth();
Ogre::uchar *oriImageData = oriImage->getData();
// 所选纹理的大小
size_t newImageWidth = texInfo.width*TexTileSize;
size_t newImageHeight = texInfo.height*TexTileSize;
// 分配一个足够大的空间来保存新建的image的数据
size_t newImagegetRowSpan = newImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节)
Ogre::uchar *newImageData = OGRE_ALLOC_T(Ogre::uchar, oriImageHeight*newImagegetRowSpan, Ogre::MEMCATEGORY_GENERAL);//new Ogre::uchar[newImageHeight*newImagegetRowSpan];
Ogre::uchar *newImageDataPointer = newImageData;
// 得知起始像素点
size_t startPoint = ( oriImageWidth * texInfo.topCorner + texInfo.leftCorner )
* TexTileSize * oriImage->getBPP()/BytePerPixel;
Ogre::uchar *oriImagedataPointer = oriImageData + startPoint;
// 把所选的纹理的数据提取出来,并创建一个新的image
for ( Ogre::uint i=0; i<newImageHeight; ++i )
{
memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan);
newImageDataPointer += newImagegetRowSpan;
oriImagedataPointer += oriImage->getRowSpan();
}
Ogre::Image newImage;
newImage.loadDynamicImage(newImageData,newImageWidth,newImageHeight,1,oriImage->getFormat(),true);
// 如果所选纹理大于64*64,就先resize
if ( texInfo.width > 1 || texInfo.height > 1 )
newImage.resize(mPreviewImageWidth, mPreviewImageHeight);
// 如果有alpha,要与黑白图进行混合
if ( newImage.getHasAlpha() )
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
float alphaValue = col.a;
unsigned char r = col.r*255 * alphaValue + mBlackWhitePreviewImage.GetRed(i,j) * ( 1.0f - alphaValue);
unsigned char g = col.g*255 * alphaValue + mBlackWhitePreviewImage.GetGreen(i,j) * ( 1.0f - alphaValue);
unsigned char b = col.b*255 * alphaValue + mBlackWhitePreviewImage.GetBlue(i,j) * ( 1.0f - alphaValue);
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
// 设置到缩略图控件中
mBrushesPreview->SetBitmap(mCurrentPreviewImage);
}
// 没有alpha,就直接拷贝数据
else
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
unsigned char r = col.r*255;
unsigned char g = col.g*255;
unsigned char b = col.b*255;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
mBrushesPreview->SetBitmap(mCurrentPreviewImage);
}
}
示例5: init
//.........这里部分代码省略.........
setPhysicGUI();
// ------------------------
// Start Bullet
initWorld();
// ------------------------
// Add the ground
// 0.1, 0.8
//addStaticPlane(0.3, 0.8);
{
Ogre::ConfigFile config;
config.loadFromResourceSystem(terrain_cfg, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, "=", true);
unsigned page_size = Ogre::StringConverter::parseUnsignedInt(config.getSetting("PageSize"));
Ogre::Vector3 terrainScale(Ogre::StringConverter::parseReal(config.getSetting("PageWorldX")) / (page_size - 1),
Ogre::StringConverter::parseReal(config.getSetting("MaxHeight")),
Ogre::StringConverter::parseReal(config.getSetting("PageWorldZ")) / (page_size - 1));
Ogre::String terrainfileName = config.getSetting("Heightmap.image");
float *heights = new float[page_size*page_size];
Ogre::Image terrainHeightMap;
terrainHeightMap.load(terrainfileName, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
for (unsigned y = 0; y < page_size; ++y)
{
for (unsigned x = 0; x < page_size; ++x)
{
Ogre::ColourValue color = terrainHeightMap.getColourAt(x, y, 0);
heights[x + y * page_size] = color.r;
}
}
mTerrainShape = new HeightmapCollisionShape(page_size,
page_size,
terrainScale,
heights,
true);
RigidBody *defaultTerrainBody = new RigidBody("Terrain",
mWorld);
const float terrainBodyRestitution = 0.1f;
const float terrainBodyFriction = 0.8f;
Ogre::Vector3 terrainShiftPos( (terrainScale.x * (page_size - 1) / 2), \
0,
(terrainScale.z * (page_size - 1) / 2));
terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;
Ogre::SceneNode* pTerrainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
defaultTerrainBody->setStaticShape (pTerrainNode, mTerrainShape, terrainBodyRestitution, terrainBodyFriction, terrainShiftPos);
mBodies.push_back(defaultTerrainBody);
mShapes.push_back(mTerrainShape);
}
示例6: getPreviewImage
void
MaterialPreviewDialog::buildPreviewBitmap( const Ogre::String &texName )
{
const Ogre::uchar BytePerPixel = 8;
// 读取原始image
Ogre::Image *oriImage = getPreviewImage(texName);
// 源大纹理的大小
size_t oriImageHeight = oriImage->getHeight();
size_t oriImageWidth = oriImage->getWidth();
Ogre::uchar *oriImageData = oriImage->getData();
// 分配一个足够大的空间来保存新建的image的数据
size_t newImagegetRowSpan = oriImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节)
Ogre::uchar *newImageData = OGRE_ALLOC_T(Ogre::uchar, oriImageHeight*newImagegetRowSpan, Ogre::MEMCATEGORY_GENERAL);//new Ogre::uchar[oriImageHeight*newImagegetRowSpan];
Ogre::uchar *newImageDataPointer = newImageData;
Ogre::uchar *oriImagedataPointer = oriImageData;
// 把所选的纹理的数据提取出来,并创建一个新的image
for ( Ogre::uint i=0; i<oriImageHeight; ++i )
{
memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan);
newImageDataPointer += newImagegetRowSpan;
oriImagedataPointer += oriImage->getRowSpan();
}
Ogre::Image newImage;
newImage.loadDynamicImage(newImageData,oriImageWidth,oriImageHeight,1,oriImage->getFormat(),true);
// 如果所选纹理大于64*64,就先resize
if ( oriImageWidth > mPreviewImageWidth || oriImageHeight > mPreviewImageHeight )
newImage.resize(mPreviewImageWidth, mPreviewImageHeight);
// 如果有alpha,要与黑白图进行混合
if ( newImage.getHasAlpha() )
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
float alphaValue = col.a;
unsigned char r = col.r*255 * alphaValue;
unsigned char g = col.g*255 * alphaValue;
unsigned char b = col.b*255 * alphaValue;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
}
// 没有alpha,就直接拷贝数据
else
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
unsigned char r = col.r*255;
unsigned char g = col.g*255;
unsigned char b = col.b*255;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
}
}