Fix player height (not working with scale)
This commit is contained in:
+1
-1
@@ -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);
|
||||
|
||||
|
||||
+3
-9
@@ -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;
|
||||
}
|
||||
|
||||
+20
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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"])
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"world": {
|
||||
"heightmap": "worlds/small.png",
|
||||
"scale": 1
|
||||
},
|
||||
"player": {
|
||||
"startposition": [ 20, 5, 20 ]
|
||||
},
|
||||
"objects": [],
|
||||
"enemies": []
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"worlds": [
|
||||
"worlds/small.json",
|
||||
"worlds/ice.json",
|
||||
"worlds/fire.json"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user