diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index ad61da7..826ad4a 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -91,7 +91,7 @@ void CrystalPoint::update() if (!worldhandler->isPlayerPositionValid()) player->position = oldPosition; - player->position.y = worldhandler->getHeight(player->position.x, player->position.z); + player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f; worldhandler->update(deltaTime); diff --git a/HeightMap.cpp b/HeightMap.cpp index 018ad4d..042c229 100644 --- a/HeightMap.cpp +++ b/HeightMap.cpp @@ -73,9 +73,6 @@ void HeightMap::Draw() glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, imageIndex); - //glDisable(GL_TEXTURE_2D); - - glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); //glEnableClientState(GL_COLOR_ARRAY); @@ -105,15 +102,12 @@ float HeightMap::GetHeight(float x, float y) Vertex& b = vertices[index+1]; Vertex& c = vertices[index+3]; - float lowervalue = ((b.y - c.y)*(a.x - c.x) + (c.x - b.x)*(a.y - c.y)); - - float labda1 = ((b.y - c.y)*(x - c.x) + (c.x - b.x)*(y - c.y)) / lowervalue; - + float lowervalue = ((b.z - c.z)*(a.x - c.x) + (c.x - b.x)*(a.z - c.z)); + float labda1 = ((b.z - c.z)*(x - c.x) + (c.x - b.x)*(y - c.z)) / lowervalue; float labda2 = ((c.y - a.y)*(x - c.x) + (a.x - c.x)*(y - c.y)) / lowervalue; - float labda3 = 1 - labda1 - labda2; - Vec3f z = Vec3f(a.x, a.y, a.z) * labda1 + Vec3f(b.x, b.y, b.z) * labda2 + Vec3f(c.x, c.y, c.z) * labda3; + Vertex z = a * labda1 + b * labda2 + c * labda3; return z.y; } diff --git a/Vertex.cpp b/Vertex.cpp index 9e4aa85..8afd8a1 100644 --- a/Vertex.cpp +++ b/Vertex.cpp @@ -17,3 +17,23 @@ Vertex::Vertex(float x, float y, float z, float nx, float ny, float nz, float tx Vertex::~Vertex() { } + +Vertex Vertex::operator/(float &other) +{ + return Vertex(x / other, y / other, z / other, normalX, normalY, normalZ, texX, texY); +} + +Vertex Vertex::operator*(Vertex & other) +{ + return Vertex(x*other.x, y*other.y, z*other.z, normalX, normalY, normalZ, texX, texY); +} + +Vertex Vertex::operator*(float & other) +{ + return Vertex(x*other, y*other, z*other, normalX, normalY, normalZ, texX, texY); +} + +Vertex Vertex::operator+(Vertex & other) +{ + return Vertex(x+other.x, y+other.y, z+other.z, normalX, normalY, normalZ, texX, texY); +} diff --git a/Vertex.h b/Vertex.h index 7edbc50..3411000 100644 --- a/Vertex.h +++ b/Vertex.h @@ -15,5 +15,10 @@ public: float texX; float texY; + + Vertex operator/(float &other); + Vertex operator*(Vertex &other); + Vertex operator*(float &other); + Vertex operator+(Vertex &other); }; diff --git a/World.cpp b/World.cpp index 35cea9f..a2d54ad 100644 --- a/World.cpp +++ b/World.cpp @@ -34,9 +34,9 @@ World::World(const std::string &fileName) if(!v["world"]["texture"].isNull()) heightmap->SetTexture(v["world"]["texture"].asString()); - player->position.x = v["player"]["startposition"][0].asFloat(); - player->position.y = v["player"]["startposition"][1].asFloat(); - player->position.z = v["player"]["startposition"][2].asFloat(); + player->position.x = v["player"]["startposition"][0].asFloat()*scale; + player->position.y = v["player"]["startposition"][1].asFloat()*scale; + player->position.z = v["player"]["startposition"][2].asFloat()*scale; for (auto object : v["objects"]) diff --git a/worlds/small.json b/worlds/small.json new file mode 100644 index 0000000..e69e432 --- /dev/null +++ b/worlds/small.json @@ -0,0 +1,11 @@ +{ + "world": { + "heightmap": "worlds/small.png", + "scale": 1 + }, + "player": { + "startposition": [ 20, 5, 20 ] + }, + "objects": [], + "enemies": [] +} \ No newline at end of file diff --git a/worlds/small.png b/worlds/small.png new file mode 100644 index 0000000..fd75ea1 Binary files /dev/null and b/worlds/small.png differ diff --git a/worlds/worlds.json b/worlds/worlds.json index 085ff36..f1f5747 100644 --- a/worlds/worlds.json +++ b/worlds/worlds.json @@ -1,5 +1,6 @@ { "worlds": [ + "worlds/small.json", "worlds/ice.json", "worlds/fire.json" ]