diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 826ad4a..45c6cd5 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -78,7 +78,7 @@ void CrystalPoint::update() if (player->rotation.x < -90) player->rotation.x = -90; - float speed = 2; + float speed = 1; Vec3f oldPosition = player->position; if (keyboardState.keys['a']) player->setPosition(0, deltaTime*speed, false); @@ -91,7 +91,7 @@ void CrystalPoint::update() if (!worldhandler->isPlayerPositionValid()) player->position = oldPosition; - player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f; + player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 0.7f; worldhandler->update(deltaTime); diff --git a/Entity.cpp b/Entity.cpp index d79b247..4be3945 100644 --- a/Entity.cpp +++ b/Entity.cpp @@ -31,7 +31,7 @@ void Entity::draw() glRotatef(rotation.y, 0, 1, 0); glRotatef(rotation.z, 0, 0, 1); glScalef(scale, scale, scale); - glTranslatef(-model->center.x, 0, -model->center.z); +//collision gaat hierdoor kapot glTranslatef(-model->center.x, 0, -model->center.z); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); diff --git a/HeightMap.cpp b/HeightMap.cpp index f6752a6..5494253 100644 --- a/HeightMap.cpp +++ b/HeightMap.cpp @@ -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) @@ -41,7 +39,7 @@ HeightMap::HeightMap(const std::string &file, float scale, World* world) 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)); + world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)), Vec3f(x, heightAt(x, y), y), Vec3f(0, rand()%360, 0), 1, true)); } Vec3f normal = ca.cross(ba); @@ -50,7 +48,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 } ); } @@ -108,13 +106,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]; diff --git a/HeightMap.h b/HeightMap.h index 0f3a141..fe2e963 100644 --- a/HeightMap.h +++ b/HeightMap.h @@ -14,9 +14,8 @@ private: int width; GLuint imageIndex; - int scale; public: - HeightMap(const std::string &file, float scale, World* world); + HeightMap(const std::string &file, World* world); ~HeightMap(); void Draw(); diff --git a/World.cpp b/World.cpp index 1a9e533..5bbc272 100644 --- a/World.cpp +++ b/World.cpp @@ -27,24 +27,20 @@ World::World(const std::string &fileName) if (v["world"]["object-templates"].isNull()) std::cout << "Invalid world file: object templates - " << fileName << "\n"; - float scale = 1.0f; - if (!v["world"]["scale"].isNull()) - scale = v["world"]["scale"].asFloat(); - //Load object templates for (auto objt : v["world"]["object-templates"]) { objecttemplates.push_back(std::pair(objt["color"], objt["file"])); } - heightmap = new HeightMap(v["world"]["heightmap"].asString(), scale, this); + heightmap = new HeightMap(v["world"]["heightmap"].asString(), this); if(!v["world"]["texture"].isNull()) heightmap->SetTexture(v["world"]["texture"].asString()); - 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; + player->position.x = v["player"]["startposition"][0].asFloat(); + player->position.y = v["player"]["startposition"][1].asFloat(); + player->position.z = v["player"]["startposition"][2].asFloat(); for (auto object : v["objects"]) diff --git a/worlds/fire.json b/worlds/fire.json index 5d1368a..884df5a 100644 --- a/worlds/fire.json +++ b/worlds/fire.json @@ -2,7 +2,6 @@ "world": { "heightmap": "worlds/hell.png", "texture": "worlds/helltexture.png", - "scale": 1, "object-templates": [ { "color": 25, diff --git a/worlds/ice.json b/worlds/ice.json index 44b0137..70cb5b9 100644 --- a/worlds/ice.json +++ b/worlds/ice.json @@ -2,7 +2,6 @@ "world": { "heightmap": "worlds/hmcs.png", "texture": "worlds/hmcstexture.png", - "scale": 2 }, "player": { "startposition": [ 100, 20, 100 ] diff --git a/worlds/small.json b/worlds/small.json index bd9ab49..d548c08 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -1,7 +1,6 @@ { "world": { "heightmap": "worlds/small.png", - "scale": 1, "object-templates": [ { "color":100,