本文整理汇总了C++中HeightMap类的典型用法代码示例。如果您正苦于以下问题:C++ HeightMap类的具体用法?C++ HeightMap怎么用?C++ HeightMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HeightMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void init(const HeightMap &hm, f32 scale, colour_func cf, IVideoDriver *driver)
{
Scale = scale;
const u32 mp = driver -> getMaximalPrimitiveCount();
Width = hm.width();
Height = hm.height();
const u32 sw = mp / (6 * Height); // the width of each piece
u32 i=0;
for(u32 y0 = 0; y0 < Height; y0 += sw)
{
u16 y1 = y0 + sw;
if (y1 >= Height)
y1 = Height - 1; // the last one might be narrower
addstrip(hm, cf, y0, y1, i);
++i;
}
if (i<Mesh->getMeshBufferCount())
{
// clear the rest
for (u32 j=i; j<Mesh->getMeshBufferCount(); ++j)
{
Mesh->getMeshBuffer(j)->drop();
}
Mesh->MeshBuffers.erase(i,Mesh->getMeshBufferCount()-i);
}
Mesh->recalculateBoundingBox();
}
示例2: init
void init(const HeightMap &hm, f32 scale, colour_func cf, IVideoDriver *driver)
{
Scale = scale;
const u32 mp = driver -> getMaximalPrimitiveCount();
Width = hm.width();
Height = hm.height();
const u32 sw = mp / (6 * Height); // the width of each piece
u32 i=0;
for(u32 y0 = 0; y0 < Height; y0 += sw)
{
u16 y1 = y0 + sw;
if (y1 >= Height)
y1 = Height - 1; // the last one might be narrower
addstrip(hm, cf, y0, y1, i);
++i;
}
if (i<Mesh->getMeshBufferCount())
{
// clear the rest
for (u32 j=i; j<Mesh->getMeshBufferCount(); ++j)
{
Mesh->getMeshBuffer(j)->drop();
}
Mesh->MeshBuffers.erase(i,Mesh->getMeshBufferCount()-i);
}
// set dirty flag to make sure that hardware copies of this
// buffer are also updated, see IMesh::setHardwareMappingHint
Mesh->setDirty();
Mesh->recalculateBoundingBox();
}
示例3: HeightMapSmoothCoastInDirection
/** Start at given point, move in given direction, find and Smooth coast in that direction */
static void HeightMapSmoothCoastInDirection(int org_x, int org_y, int dir_x, int dir_y)
{
const int max_coast_dist_from_edge = 35;
const int max_coast_Smooth_depth = 35;
int x, y;
int ed; // coast distance from edge
int depth;
height_t h_prev = 16;
height_t h;
assert(IsValidXY(org_x, org_y));
/* Search for the coast (first non-water tile) */
for (x = org_x, y = org_y, ed = 0; IsValidXY(x, y) && ed < max_coast_dist_from_edge; x += dir_x, y += dir_y, ed++) {
/* Coast found? */
if (_height_map.height(x, y) > 15) break;
/* Coast found in the neighborhood? */
if (IsValidXY(x + dir_y, y + dir_x) && _height_map.height(x + dir_y, y + dir_x) > 0) break;
/* Coast found in the neighborhood on the other side */
if (IsValidXY(x - dir_y, y - dir_x) && _height_map.height(x - dir_y, y - dir_x) > 0) break;
}
/* Coast found or max_coast_dist_from_edge has been reached.
* Soften the coast slope */
for (depth = 0; IsValidXY(x, y) && depth <= max_coast_Smooth_depth; depth++, x += dir_x, y += dir_y) {
h = _height_map.height(x, y);
h = min(h, h_prev + (4 + depth)); // coast softening formula
_height_map.height(x, y) = h;
h_prev = h;
}
}
示例4: TEST_F
TEST_F(Test_WorldTerrainNormalMap, slope45Degree)
{
const int hmSize = 2;
HeightMap hm;
hm.reserve(hmSize);
hm.set(0, 0, 1.0f);
hm.set(1, 0, 1.0f);
hm.set(0, 1, 0);
hm.set(1, 1, 0);
NormalMap nm;
nm.generate(hm);
//only two normals
EXPECT_EQ(nm.size(), 2);
//both normals should be pointing at an angle more downish
Vec3f n1 = nm.get(0);
Vec3f n2 = nm.get(0);
Vec3f outDown(0.0f, -.707107f, -.707107);
expectVec3fAreEqual(n1, outDown);
expectVec3fAreEqual(n2, outDown);
{
Vec3f p1(0, 1, 0);
Vec3f p2(1, 1, 0);
Vec3f p3(0, 0, 1);
}
}
示例5: initHeightMap
void initHeightMap ()
{
num_hm_elements = hm.sizeOfTriangleVertices()*2;
vec4 hm_elements [num_hm_elements];
hm.flattenTriangles (hm_elements);
// num_hm_elements = hm.getSize () * 2;
// vec4 hm_elements [num_hm_elements];
// hm.flatten (hm_elements);
// indices = new unsigned [ hm.sizeOfTriStripIndices () ];
// hm.flattenTriStripIndices (indices);
glGenVertexArrays(1, &hm_vao);
glBindVertexArray(hm_vao);
GLuint buffer;
glGenBuffers (1, &buffer);
glBindBuffer (GL_ARRAY_BUFFER, buffer);
glBufferData (GL_ARRAY_BUFFER, num_hm_elements*sizeof(vec4), hm_elements, GL_STATIC_DRAW);
glEnableVertexAttribArray ( vPosition );
glVertexAttribPointer ( vPosition, 4, GL_FLOAT, GL_FALSE, sizeof(vec4)*2, BUFFER_OFFSET(0) );
glEnableVertexAttribArray( vColor );
glVertexAttribPointer ( vColor, 4, GL_FLOAT, GL_FALSE, sizeof(vec4)*2, BUFFER_OFFSET(sizeof (vec4)));
}
示例6: HeightMap
// From ReferenceTarget
RefTargetHandle HeightMap::Clone(RemapDir& remap)
{
HeightMap* newob = new HeightMap();
//TODO: Make a copy all the data and also clone all the references
newob->ReplaceReference(0,pblock2->Clone(remap));
newob->ivalid.SetEmpty();
BaseClone(this, newob, remap);
return(newob);
}
示例7: BOOST_FIXTURE_TEST_CASE
BOOST_FIXTURE_TEST_CASE(HeightMapTest1, Test4x4HeightMap)
{
HeightMap hm;
hm.Swap(sample4x4);
BOOST_CHECK_EQUAL(hm.At(Point2d(1, 1)), 0.0f);
BOOST_CHECK_EQUAL(hm.At(Point2d(1, 2)), 1.0f);
BOOST_CHECK_EQUAL(hm.At(Point2d(1, 3)), 1.0f);
BOOST_CHECK_EQUAL(hm.GetSize(), 4u);
}
示例8: HeightMapCoastLines
/**
* This routine sculpts in from the edge a random amount, again a Perlin
* sequence, to avoid the rigid flat-edge slopes that were present before. The
* Perlin noise map doesnt know where we are going to slice across, and so we
* often cut straight through high terrain. the smoothing routine makes it
* legal, gradually increasing up from the edge to the original terrain height.
* By cutting parts of this away, it gives a far more irregular edge to the
* map-edge. Sometimes it works beautifully with the existing sea & lakes, and
* creates a very realistic coastline. Other times the variation is less, and
* the map-edge shows its cliff-like roots.
*
* This routine may be extended to randomly sculpt the height of the terrain
* near the edge. This will have the coast edge at low level (1-3), rising in
* smoothed steps inland to about 15 tiles in. This should make it look as
* though the map has been built for the map size, rather than a slice through
* a larger map.
*
* Please note that all the small numbers; 53, 101, 167, etc. are small primes
* to help give the perlin noise a bit more of a random feel.
*/
static void HeightMapCoastLines(uint8 water_borders)
{
int smallest_size = min(_settings_game.game_creation.map_x, _settings_game.game_creation.map_y);
const int margin = 4;
uint y, x;
double max_x;
double max_y;
/* Lower to sea level */
for (y = 0; y <= _height_map.size_y; y++) {
if (HasBit(water_borders, BORDER_NE)) {
/* Top right */
max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = 0; x < max_x; x++) {
_height_map.height(x, y) = 0;
}
}
if (HasBit(water_borders, BORDER_SW)) {
/* Bottom left */
max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45, 67) + 0.75) * 8);
max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) {
_height_map.height(x, y) = 0;
}
}
}
/* Lower to sea level */
for (x = 0; x <= _height_map.size_x; x++) {
if (HasBit(water_borders, BORDER_NW)) {
/* Top left */
max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = 0; y < max_y; y++) {
_height_map.height(x, y) = 0;
}
}
if (HasBit(water_borders, BORDER_SE)) {
/* Bottom right */
max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) {
_height_map.height(x, y) = 0;
}
}
}
}
示例9: imageToHeightMap_tilable
Liquid_StaticNoiseOverlay_Impl::Liquid_StaticNoiseOverlay_Impl(GLImage & noise, GLImage & mask, float refactionIndex, float noiseIntensity)
{
const int BORDER = 1; //without this border the bluring below would ruin the seamless nature of the image
HeightMap * noiseMap = imageToHeightMap_tilable(noise, BORDER);
//images have only 255 steps - make the steps smoother
noiseMap->blur(2);
//reduce intensity of water effect
noiseMap->scaleAll(noiseIntensity);
renderer = new StaticNoiseLiquidRefactionRenderer(refactionIndex, *noiseMap, BORDER);
//done with noiseMap
delete noiseMap;
//Split the mask into independent rectangles
ImageMask im(mask);
im.isolateMaskRegions(rects);
Rect4i imgRect(0, 0, im.width(), im.height());
int largestRectArea = 1;
for (int i = 0; i < rects.size(); i++)
{
Rect4i & rect = *rects.items()[i];
printf("Found rect ");
rect.debugPrint();
//UPDATE: this bugfix is now done in Java code
//bug workaround: For some reason certain widths of rectangles
// causes strange gray looking textures after uploading with glTexSubImage2D().
// I can avoid the issue by making sure width is an even multiple of 8. I picked
// 8 out of the blue and it seems to work even though I don't fully understand the problem.
//roundMaskRect(rect, imgRect, 8);
//printf("Rounded to ");
//rect.debugPrint();
masks.add(im.copySubrect(rect));
int area = rect.area();
if (area > largestRectArea)
largestRectArea = area;
}
fflush(stdout);
//Allocate a temporary pixel buffer to use in the update() call.
//It needs to be big enough to hold the largest MaskRect
tempBuf.allocateBlank(1, largestRectArea, 0);
}
示例10: addstrip
void addstrip(const HeightMap &hm, colour_func cf, u16 y0, u16 y1, u32 bufNum)
{
SMeshBuffer *buf = 0;
if (bufNum<Mesh->getMeshBufferCount())
{
buf = (SMeshBuffer*)Mesh->getMeshBuffer(bufNum);
}
else
{
// create new buffer
buf = new SMeshBuffer();
Mesh->addMeshBuffer(buf);
// to simplify things we drop here but continue using buf
buf->drop();
}
buf->Vertices.set_used((1 + y1 - y0) * Width);
u32 i=0;
for (u16 y = y0; y <= y1; ++y)
{
for (u16 x = 0; x < Width; ++x)
{
const f32 z = hm.get(x, y);
const f32 xx = (f32)x/(f32)Width;
const f32 yy = (f32)y/(f32)Height;
S3DVertex& v = buf->Vertices[i++];
v.Pos.set(x, Scale * z, y);
v.Normal.set(hm.getnormal(x, y, Scale));
v.Color=cf(xx, yy, z);
v.TCoords.set(xx, yy);
}
}
buf->Indices.set_used(6 * (Width - 1) * (y1 - y0));
i=0;
for(u16 y = y0; y < y1; ++y)
{
for(u16 x = 0; x < Width - 1; ++x)
{
const u16 n = (y-y0) * Width + x;
buf->Indices[i]=n;
buf->Indices[++i]=n + Width;
buf->Indices[++i]=n + Width + 1;
buf->Indices[++i]=n + Width + 1;
buf->Indices[++i]=n + 1;
buf->Indices[++i]=n;
++i;
}
}
buf->recalculateBoundingBox();
}
示例11: cache
void
HeightMapLoaderCache::Get(const Point2d & pos, const size_t sz, HeightMap & hm) const
{
Size2d point = Size2d::Cast(pos);
// special case of patch corner request
if (sz == 1)
{
if (point.x() == (partSize_ - 1))
--point.x();
if (point.y() == (partSize_ - 1))
--point.y();
Size2d cornerPos = point / (partSize_ - 1);
cornerPos *= (partSize_ - 1);
const auto patchFound = heightMapCache_.find(cornerPos);
if (patchFound == heightMapCache_.end())
{
basePtr_->Get(pos, sz, hm);
}
else
{
HeightMap::Container vec;
HeightMap::Value val = HeightMap::GetValueAt(pos - Point2d::Cast(cornerPos), patchFound->second, partSize_);
vec.push_back(val);
hm.Swap(vec);
}
}
else
{
if (sz != partSize_)
{
throw std::runtime_error("Sizes other than part size aren't supported by height map cache (Get)");
}
HeightMapCache::iterator found = heightMapCache_.find(point);
if (found == heightMapCache_.end())
{
basePtr_->Get(pos, sz, hm);
}
else
{
HeightMap::Container hmc = found->second;
hm.Swap(hmc);
}
}
}
示例12: BreadthFirstSearch
// In this method, breadth first traverse method is employed to construct
// a height map, and in order to increase searching rate, the upper and
// right direction are preferred in the process of traverse.
// This function requires the caller to ensure that maxtrix_[c.x][c.y] > 100.
HeightMap HeightMatrix::BreadthFirstSearch(Coordinate c)
{
HeightMap hm;
Direction four_directions[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
for (int i = 0; i < row_; ++i)
{
memset(visited_[i], 0, column_ * sizeof(bool));
}
std::queue<Coordinate> q;
if (!visited_[c.x][c.y])
{
q.push(c);
//visited_[c.x][c.y] = true;
Point p(c, IsCoordinateOnEdge(c), matrix_[c.x][c.y]);
hm.AddNewPoints(p);
}
while (!q.empty())
{
Coordinate tmp = q.front();
if (!visited_[tmp.x][tmp.y])
{
visited_[tmp.x][tmp.y] = true;
Point p(tmp, IsCoordinateOnEdge(tmp), matrix_[tmp.x][tmp.y]);
hm.AddNewPoints(p);
for (int i = 0; i < 4; ++i)
{
Coordinate next;
next.x = tmp.x + four_directions[i].x;
next.y = tmp.y + four_directions[i].y;
if (IsCoordinateInMatrix(next) && matrix_[next.x][next.y] >= 100)
{
q.push(next);
}
}
}
q.pop();
}
return hm;
}
示例13: main
int main() {
Serial::open();
Camera* camera = new Camera(HD720, 15.0);
ERRCODE code = camera->init(MODE::QUALITY, 0);
if (code != SUCCESS) {
cout << errcode2str(code) << endl;
delete camera;
return 1;
}
int width = camera->getImageSize().width;
int height = camera->getImageSize().height;
PointCloud *cloud = new PointCloud(width, height);
HeightMap *heightMap = new HeightMap(128, 128);
CloudViewer *viewer = new CloudViewer();
PathPlanner *planner = new PathPlanner(heightMap);
int key = ' ';
Mat depth, imLeft;
printf("LET'S GO!\n");
Serial::gas(0.25);
// application quits when user stikes 'q'
while (key != 'q') {
camera->setConfidenceThreshold(98); // parameter is reliability index ~[1,100] with 100 as no filtering
camera->grab(SENSING_MODE::RAW);
depth = camera->retrieveMeasure(MEASURE::DEPTH);
imLeft = camera->retrieveImage(SIDE::LEFT);
cloud->fill(imLeft.data, (float*) depth.data, camera->getParameters());
cloud->fillHeightMap(heightMap);
heightMap->calcSobel(0.6);
planner->calcEdges();
steerToward(planner->getTarget());
viewer->AddData(heightMap);
viewer->AddPlanner(planner);
viewer->AddData(cloud);
// Update the value of key so that we can quit when the user strikes 'q'
key = viewer->getKey();
}
printf("quitting\n");
delete camera;
delete cloud;
delete viewer;
return 0;
}
示例14: input
void Renderer::HeightMapOpenCallback(string param)
{
std::ifstream input(param, std::ios::binary);
std::replace(param.begin(), param.end(), '\\', '/');
string imageName = param.substr(param.find_last_of("/"));
saveFile("./data" + imageName, input);
input.close();
ofImage * newImage = new ofImage(imageName.substr(1));
HeightMap * hm = new HeightMap();
hm->Setup(newImage);
addVisibleShape(hm);
}
示例15: GetVectorAnchorPosition
void FieldCharacter::SetExtraHeightFromHeightMaps(vector<HeightMap *> *pHeightMapList)
{
extraHeight = 0;
Vector2 characterPosition = GetVectorAnchorPosition();
for (unsigned int i = 0; i < pHeightMapList->size(); i++)
{
HeightMap *pHeightMap = (*pHeightMapList)[i];
if (pHeightMap->IsPointInBoundingPolygon(characterPosition))
{
extraHeight += pHeightMap->GetHeightAtPoint(characterPosition);
}
}
}