Merge branch 'developer' into heightmapTrees
# Conflicts: # CrystalPoint.cpp # HeightMap.cpp
This commit is contained in:
+11
-21
@@ -14,16 +14,14 @@
|
||||
#define BLUE 2
|
||||
#define ALPHA 3
|
||||
|
||||
HeightMap::HeightMap(const std::string &file, float scale, World* world)
|
||||
HeightMap::HeightMap(const std::string &file, World* world)
|
||||
{
|
||||
this->scale = scale;
|
||||
|
||||
int bpp;
|
||||
unsigned char* imgData = stbi_load(file.c_str(), &width, &height, &bpp, 4);
|
||||
|
||||
auto heightAt = [&](int x, int y)
|
||||
{
|
||||
return (imgData[(x + y * width) * 4 ] / 256.0f) * 100.0f;
|
||||
return (imgData[(x + y * width) * 4 ] / 256.0f) * 50.0f;
|
||||
};
|
||||
|
||||
auto valueAt = [&](int x, int y, int offset = 0)
|
||||
@@ -40,21 +38,9 @@ HeightMap::HeightMap(const std::string &file, float scale, World* world)
|
||||
Vec3f ba(1, heightAt(x + 1, y) - heightAt(x, y), 0);
|
||||
|
||||
|
||||
if ((valueAt(x, y, GREEN) >= 10) && (valueAt(x,y,GREEN) <= 100))
|
||||
if (valueAt(x, y, GREEN) > 0)
|
||||
{
|
||||
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)), Vec3f(x*scale, heightAt(x, y), y*scale), Vec3f(0, rand() % 360, 0), 1, true));
|
||||
}
|
||||
if (valueAt(x, y, GREEN) == 180 || valueAt(x, y, GREEN) == 190 || valueAt(x, y, GREEN) == 170 || valueAt(x, y, GREEN) == 250)
|
||||
{
|
||||
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)), Vec3f(x*scale, heightAt(x, y), y*scale), Vec3f(0, 0, 0), 1, true));
|
||||
}
|
||||
if ((valueAt(x, y, GREEN) >= 200) && (valueAt(x, y, GREEN) <= 240))
|
||||
{
|
||||
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)), Vec3f(x*scale, heightAt(x, y), y*scale), Vec3f(0, 0, 0), 1, false));
|
||||
}
|
||||
if (valueAt(x, y, GREEN) == 160)
|
||||
{
|
||||
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)), Vec3f(x*scale, heightAt(x, y), y*scale), Vec3f(0, 0, 0), 1, false));
|
||||
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, rand()%360, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
|
||||
}
|
||||
|
||||
Vec3f normal = ca.cross(ba);
|
||||
@@ -63,7 +49,7 @@ HeightMap::HeightMap(const std::string &file, float scale, World* world)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float h = heightAt(x + offsets[i][0], y + offsets[i][1]);
|
||||
vertices.push_back(Vertex{ (float)(x + offsets[i][0])*scale, h*scale, (float)(y + offsets[i][1])*scale,
|
||||
vertices.push_back(Vertex{ (float)(x + offsets[i][0]), h, (float)(y + offsets[i][1]),
|
||||
normal.x, normal.y, normal.z,
|
||||
(x + offsets[i][0]) / (float)height, (y + offsets[i][1]) / (float)width } );
|
||||
}
|
||||
@@ -121,13 +107,17 @@ void HeightMap::Draw()
|
||||
|
||||
float HeightMap::GetHeight(float x, float y)
|
||||
{
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
int ix = x;
|
||||
int iy = y;
|
||||
|
||||
int index = (ix + (width - 1) * iy) * 4;
|
||||
|
||||
if (index + 3 >= vertices.size())
|
||||
index = vertices.size() - 4;
|
||||
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
|
||||
Vertex& a = vertices[index];
|
||||
Vertex& b = vertices[index+1];
|
||||
Vertex& c = vertices[index+3];
|
||||
|
||||
Reference in New Issue
Block a user