void TerrainImpl::getHeights(int x, int z, Brush& brush) const { // positions given are supposed to be the mid of the brush // so adjust accordingly x -= (int)brush.getWidth()/2; z -= (int)brush.getHeight()/2; // iterate over all fields of the brush array and fill them // if they lie within for (size_t i = 0; i < brush.getWidth(); ++i) { int posX = x + (int)i; for (size_t j = 0; j < brush.getHeight(); ++j) { int posZ = z + (int)j; if (posX < 0 || posX >= (int)mInfo->getWidth() || posZ < 0 || posZ >= (int)mInfo->getHeight()) { brush.at(i, j) = -1; continue; } brush.at(i, j) = mInfo->at(size_t(posX), size_t(posZ)); } } }
void SplattingManager::paint(uint textureNum, int x, int y, const Brush& brush, float intensity) { // positions given are supposed to be the mid of the brush // so adjust accordingly x -= (int)brush.getWidth()/2; y -= (int)brush.getHeight()/2; // iterate over all fields of the brush array and apply them to the map textures // if they lie within the bounds for (size_t i = 0; i < brush.getWidth(); ++i) { int posX = x + (int)i; if (posX < 0 || posX >= (int)mImpl->width) continue; for (size_t j = 0; j < brush.getHeight(); ++j) { int posY = y + (int)j; if (posY < 0 || posY >= (int)mImpl->height) continue; mImpl->paint(textureNum, (uint)posX, (uint)posY, brush.at(i, j) * intensity); } } // finally, update the textures mImpl->updateTextures(); }
void TerrainImpl::setHeights(int x, int z, const Brush& brush) { // positions given are supposed to be the mid of the brush // so adjust accordingly x -= (int)brush.getWidth()/2; z -= (int)brush.getHeight()/2; // iterate over all fields of the brush array and apply them to // the heightmap data if they lie within for (size_t i = 0; i < brush.getWidth(); ++i) { int posX = x + (int)i; if (posX < 0 || posX >= (int)mInfo->getWidth()) continue; for (size_t j = 0; j < brush.getHeight(); ++j) { int posZ = z + (int)j; if (posZ < 0 || posZ >= (int)mInfo->getHeight()) continue; float& height = mInfo->at(size_t(posX), size_t(posZ)); height = brush.at(i, j); if (height > 1) height = 1; if (height < 0) height = 0; } } updateTiles(x, z, x+(int)brush.getWidth(), z+(int)brush.getHeight()); }
void saveBrushToImage(const Brush& brush, Image& image) { // save brush as a 16bit grayscale image ushort* data = new ushort[brush.getWidth()*brush.getHeight()]; for (size_t x = 0; x < brush.getWidth(); ++x) for (size_t y = 0; y < brush.getHeight(); ++y) data[y*brush.getWidth() + x] = ushort(brush.at(x, y) * 0xffff); // pass the data to the image, image takes over ownership image.loadDynamicImage((uchar*)data, brush.getWidth(), brush.getHeight(), 1, PF_L16, true); }
void saveBrushToImage(const Brush& brush, Image& image) { // save brush as a 16bit grayscale image #if OGRE_VERSION_MINOR > 4 ushort* data = (ushort*)OGRE_ALLOC_T(uchar, brush.getWidth()*brush.getHeight()*sizeof(ushort), MEMCATEGORY_GENERAL); #else ushort* data = (ushort*)new uchar[brush.getWidth()*brush.getHeight()*sizeof(ushort)]; #endif for (size_t x = 0; x < brush.getWidth(); ++x) for (size_t y = 0; y < brush.getHeight(); ++y) data[y*brush.getWidth() + x] = ushort(brush.at(x, y) * 0xffff); // pass the data to the image, image takes over ownership image.loadDynamicImage((uchar*)data, brush.getWidth(), brush.getHeight(), 1, PF_L16, true); }