From 2946ba6fb014e1458c650618c0e3c31018136816 Mon Sep 17 00:00:00 2001 From: XProger Date: Sat, 20 Aug 2016 15:35:08 +0300 Subject: [PATCH] - fix light position - upscale to original world size --- src/game.h | 27 ++++----------------------- src/level.h | 13 ++++++------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/game.h b/src/game.h index 5dc2bb9..73aa714 100644 --- a/src/game.h +++ b/src/game.h @@ -18,7 +18,7 @@ struct Camera { if (Input::down[ikD]) v = v + dir.cross(vec3(0, 1, 0)); if (Input::down[ikA]) v = v - dir.cross(vec3(0, 1, 0)); - pos = pos + v.normal() * (Core::deltaTime); + pos = pos + v.normal() * (Core::deltaTime * 2048.0f); if (Input::down[ikMouseL]) { vec2 delta = Input::mouse.pos - Input::mouse.start.L; @@ -40,11 +40,6 @@ struct Camera { Core::mProj = mat4(fov, (float)Core::width / (float)Core::height, znear, zfar); Core::mViewProj = Core::mProj * Core::mView; - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf((GLfloat*)&Core::mProj); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf((GLfloat*)&Core::mView); } }; @@ -59,10 +54,10 @@ namespace Game { level = new Level("data\\LEVEL3A.PHD"); camera.fov = 90.0f; - camera.znear = 0.1f; - camera.zfar = 1000.0f; + camera.znear = 0.1f * 2048.0f; + camera.zfar = 1000.0f * 2048.0f; // camera.pos = vec3(-10, -2, 26); - camera.pos = vec3(-13.25f, 0.42f, 38.06f); + camera.pos = vec3(-13.25f, 0.42f, 38.06f) * 2048.0f; // camera.pos = vec3(-36, -1, 2); camera.angle = vec3(0); } @@ -80,26 +75,12 @@ namespace Game { } void render() { -// Core::clear(vec4(0.1f, 0.4f, 0.4f, 0.0)); Core::clear(vec4(0.0f, 0.0f, 0.0f, 0.0)); Core::setViewport(0, 0, Core::width, Core::height); Core::setBlending(bmAlpha); camera.setup(); - /* - Debug::Draw::begin(); - glDisable(GL_TEXTURE_2D); - Debug::Draw::axes(10); - glEnable(GL_TEXTURE_2D); - */ - vec3 pos = Core::mView.inverse().getPos(); - GLfloat p[4] = { pos.x, pos.y, pos.z, 1.0f }; - glLightfv(GL_LIGHT0, GL_POSITION, p); - glEnable(GL_DEPTH_TEST); - level->render(); - - //Debug::Draw::end(); } /* diff --git a/src/level.h b/src/level.h index 26474b8..56386e6 100644 --- a/src/level.h +++ b/src/level.h @@ -43,6 +43,7 @@ const char SHADER[] = \ " light += uAmbient;\n"\ " color.xyz *= light;\n"\ " color.xyz = pow(color.xyz, vec3(1.0/2.2));\n"\ + " //color.xyz = normalize(vLightVec) * 0.5 + 0.5;\n"\ " gl_FragColor = color;\n"\ " }\n"\ "#endif"; @@ -448,7 +449,7 @@ struct Level { return NULL; } - #define SCALE (1.0f / 1024.0f / 2.0f) + //#define SCALE (1.0f / 1024.0f / 2.0f) void renderRoom(int index) { TR::Room &room = level.rooms[index]; @@ -683,7 +684,7 @@ struct Level { if (idx > -1) { TR::Room::Light &light = level.rooms[room].lights[idx]; float c = level.rooms[room].lights[idx].Intensity / 8191.0f; - Core::lightPos = vec3(-light.x, -light.y, light.z); + Core::lightPos = vec3(-light.x, -light.y, light.z);// * SCALE; Core::lightColor = vec4(c, c, c, 0.0f); } else { Core::lightPos = vec3(0.0f); @@ -1000,15 +1001,13 @@ struct Level { glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.9f); - glEnable(GL_TEXTURE_2D); - glEnable(GL_NORMALIZE); - glEnable(GL_COLOR_MATERIAL); - //glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); Core::setCulling(cfFront); Core::mModel.identity(); - Core::mModel.scale(vec3(-SCALE, -SCALE, SCALE)); +// Core::mModel.scale(vec3(-SCALE, -SCALE, SCALE)); + Core::mModel.scale(vec3(-1, -1, 1)); Core::color = vec4(1.0f); Core::ambient = vec3(0.0f);