Implemented getHeight

This commit is contained in:
2016-05-26 13:21:14 +02:00
parent 56e174ae2f
commit 4c613b606a
6 changed files with 20 additions and 5 deletions
-1
View File
@@ -21,7 +21,6 @@ Entity::~Entity()
void Entity::draw()
{
rotation.y += 1;
if (model)
{
glPushMatrix();
+12 -2
View File
@@ -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)
+1 -1
View File
@@ -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<Vertex> vertices;
+5
View File
@@ -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(
+1
View File
@@ -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);
+1 -1
View File
@@ -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;
}