diff --git a/Entity.cpp b/Entity.cpp index 156d3ef..d79b247 100644 --- a/Entity.cpp +++ b/Entity.cpp @@ -21,7 +21,6 @@ Entity::~Entity() void Entity::draw() { - rotation.y += 1; if (model) { glPushMatrix(); diff --git a/HeightMap.cpp b/HeightMap.cpp index a620a90..7bad77b 100644 --- a/HeightMap.cpp +++ b/HeightMap.cpp @@ -90,7 +90,7 @@ void HeightMap::Draw() glDisableClientState(GL_NORMAL_ARRAY); } -void HeightMap::GetHeigth(float x, float y) +float HeightMap::GetHeigth(float x, float y) { x /= scale; y /= scale; @@ -102,8 +102,18 @@ void HeightMap::GetHeigth(float x, float y) Vertex& a = vertices[index]; Vertex& b = vertices[index+1]; Vertex& c = vertices[index+3]; - //http://stackoverflow.com/questions/36090269/finding-height-of-point-on-height-map-triangles + 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 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; + + return z.y; } void HeightMap::SetTexture(const std::string &file) diff --git a/HeightMap.h b/HeightMap.h index 0cb4feb..a6066d8 100644 --- a/HeightMap.h +++ b/HeightMap.h @@ -18,7 +18,7 @@ public: ~HeightMap(); void Draw(); - void GetHeigth(float x, float z); + float GetHeigth(float x, float y); void SetTexture(const std::string &file); std::vector vertices; diff --git a/Vector.cpp b/Vector.cpp index 3d0c6b8..35a6d41 100644 --- a/Vector.cpp +++ b/Vector.cpp @@ -80,6 +80,11 @@ bool Vec3f::operator!=(const Vec3f & other) return x != other.x & y != other.y & z != other.z; } +Vec3f Vec3f::operator*(const float & other) +{ + return Vec3f(x*other, y*other, z*other); +} + Vec3f Vec3f::cross(const Vec3f & other) { return Vec3f( diff --git a/Vector.h b/Vector.h index 7f75b93..a032a68 100644 --- a/Vector.h +++ b/Vector.h @@ -23,6 +23,7 @@ public: Vec3f operator / (float value); bool operator ==(const Vec3f &other); bool operator !=(const Vec3f &other); + Vec3f operator *(const float &other); Vec3f cross(const Vec3f &other); diff --git a/World.cpp b/World.cpp index ed21010..61bc9eb 100644 --- a/World.cpp +++ b/World.cpp @@ -133,7 +133,7 @@ void World::update(float elapsedTime) { Vec3f difference = e->position - enemy->position; //zou misschien omgedraait moeten worden difference.Normalize(); - //difference = difference * (e->model->radius + 0.01f); + difference = difference * (e->model->radius + 0.01f); enemy->position = e->position + difference; break; }