Remove scale
This commit is contained in:
+2
-2
@@ -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);
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+10
-8
@@ -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];
|
||||
|
||||
+1
-2
@@ -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();
|
||||
|
||||
@@ -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<int, std::string>(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"])
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"world": {
|
||||
"heightmap": "worlds/hell.png",
|
||||
"texture": "worlds/helltexture.png",
|
||||
"scale": 1,
|
||||
"object-templates": [
|
||||
{
|
||||
"color": 25,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"world": {
|
||||
"heightmap": "worlds/hmcs.png",
|
||||
"texture": "worlds/hmcstexture.png",
|
||||
"scale": 2
|
||||
},
|
||||
"player": {
|
||||
"startposition": [ 100, 20, 100 ]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"world": {
|
||||
"heightmap": "worlds/small.png",
|
||||
"scale": 1,
|
||||
"object-templates": [
|
||||
{
|
||||
"color":100,
|
||||
|
||||
Reference in New Issue
Block a user