Implemented getHeight
This commit is contained in:
@@ -21,7 +21,6 @@ Entity::~Entity()
|
|||||||
|
|
||||||
void Entity::draw()
|
void Entity::draw()
|
||||||
{
|
{
|
||||||
rotation.y += 1;
|
|
||||||
if (model)
|
if (model)
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|||||||
+12
-2
@@ -90,7 +90,7 @@ void HeightMap::Draw()
|
|||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeightMap::GetHeigth(float x, float y)
|
float HeightMap::GetHeigth(float x, float y)
|
||||||
{
|
{
|
||||||
x /= scale;
|
x /= scale;
|
||||||
y /= scale;
|
y /= scale;
|
||||||
@@ -102,8 +102,18 @@ void HeightMap::GetHeigth(float x, float y)
|
|||||||
Vertex& a = vertices[index];
|
Vertex& a = vertices[index];
|
||||||
Vertex& b = vertices[index+1];
|
Vertex& b = vertices[index+1];
|
||||||
Vertex& c = vertices[index+3];
|
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)
|
void HeightMap::SetTexture(const std::string &file)
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ public:
|
|||||||
~HeightMap();
|
~HeightMap();
|
||||||
|
|
||||||
void Draw();
|
void Draw();
|
||||||
void GetHeigth(float x, float z);
|
float GetHeigth(float x, float y);
|
||||||
void SetTexture(const std::string &file);
|
void SetTexture(const std::string &file);
|
||||||
|
|
||||||
std::vector<Vertex> vertices;
|
std::vector<Vertex> vertices;
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ bool Vec3f::operator!=(const Vec3f & other)
|
|||||||
return x != other.x & y != other.y & z != other.z;
|
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)
|
Vec3f Vec3f::cross(const Vec3f & other)
|
||||||
{
|
{
|
||||||
return Vec3f(
|
return Vec3f(
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public:
|
|||||||
Vec3f operator / (float value);
|
Vec3f operator / (float value);
|
||||||
bool operator ==(const Vec3f &other);
|
bool operator ==(const Vec3f &other);
|
||||||
bool operator !=(const Vec3f &other);
|
bool operator !=(const Vec3f &other);
|
||||||
|
Vec3f operator *(const float &other);
|
||||||
|
|
||||||
Vec3f cross(const Vec3f &other);
|
Vec3f cross(const Vec3f &other);
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ void World::update(float elapsedTime)
|
|||||||
{
|
{
|
||||||
Vec3f difference = e->position - enemy->position; //zou misschien omgedraait moeten worden
|
Vec3f difference = e->position - enemy->position; //zou misschien omgedraait moeten worden
|
||||||
difference.Normalize();
|
difference.Normalize();
|
||||||
//difference = difference * (e->model->radius + 0.01f);
|
difference = difference * (e->model->radius + 0.01f);
|
||||||
enemy->position = e->position + difference;
|
enemy->position = e->position + difference;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user