本文整理汇总了C++中Terrain::computeNormals方法的典型用法代码示例。如果您正苦于以下问题:C++ Terrain::computeNormals方法的具体用法?C++ Terrain::computeNormals怎么用?C++ Terrain::computeNormals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terrain
的用法示例。
在下文中一共展示了Terrain::computeNormals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadTerrain
Terrain* loadTerrain(const char* filename, float height) {
Image* image = loadBMP(filename);
Terrain* t = new Terrain(image->width, image->height);
for (int y = 0; y < image->height; y++) {
for (int x = 0; x < image->width; x++) {
unsigned char color =
(unsigned char)image->pixels[3 * (y * image->width + x)];
float h = height * ((color / 255.0f) - 0.5f);
t->setHeight(x, y, h);
}
}
delete image;
t->computeNormals();
return t;
}
示例2: loadTerrain
//Loads a terrain from a heightmap. The heights of the terrain range from
//-height / 2 to height / 2.
Terrain* loadTerrain(float width, float length) {
//Build basic terrain
Terrain* t = new Terrain(width, length);
for(int y = 0; y < length; y++) {
for(int x = 0; x < width; x++) {
float min = -2.0f;
float max = 3.0f;
float h = 1.0f;//min + (float)rand()/((float)RAND_MAX/(max-min));
t->setHeight(x, y, h);
}
}
//squareStep(Terrain* t, int xStart, int yStart, int d, float height)
int d = 4;
int h = 3;
for(int x = 0; x < t->length(); x += d) {
for(int y = 0; y < t->width(); y += d) {
//printf("Starting Squares\n");
squareStep( t, x, y, d, h);
//printf("Starting Diamonds\n");
diamondStep(t, x, y, d, h);
//d--;
//h--;
}
}
int numMount = rand() % 20 + 1;
printf ("Making %d mountains.\n", numMount);
for(int i = 0; i < numMount; i++) {
//buildMountain(t);
}
int numRivers = rand() % 3 + 1;
printf ("Making %d rivers.\n", numRivers);
for(int i = 0; i < numRivers; i++) {
//buildRiver(t);
}
int terPasses = 20;
printf ("Generating terrain.\n");
for (int i = 0; i < terPasses; i++) {
//buildTerrain(t);
}
t->computeNormals();
return t;
}
示例3: loadTerrain
//Loads a terrain from a heightmap. The heights of the terrain range from
//-height / 2 to height / 2.
Terrain* loadTerrain(const char* filename, float height) {
Image* image = loadBMP(filename);
int span=2;
Terrain* t = new Terrain(image->width*span, image->height*span);
for(int y = 0; y < image->height*span; y++) {
for(int x = 0; x < image->width*span; x++) {
unsigned char color =
(unsigned char)image->pixels[3 * ((y%image->height) * image->width + x%image->width)];
float h = height * ((color / 255.0f) - 0.5f);
if(h<0)
t->setHeight(x, y, 0);
else
t->setHeight(x, y, h);
}
}
delete image;
t->computeNormals();
return t;
}