From 3b26194bf96cf83e67691b9a8b1a02c51b86c8d0 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Tue, 14 Apr 2015 14:54:24 +0200 Subject: [PATCH] added PI in GLM capped Player movements (fix in all directions) switched to radiant fixed move undepending on deltaT fixed CULL_FACE + visNormals (shader) --- Weave/Events.cpp | 3 +++ Weave/Game.cpp | 4 ++-- Weave/Graphix/GLM.h | 7 +++++++ Weave/Graphix/Graphix.cpp | 2 +- Weave/Graphix/Scene.cpp | 16 ++++++++++------ Weave/Graphix/ViewPort.cpp | 8 ++++---- shader/basicTexture_VS.hlsl | 2 +- shader/lightingTexture_FS.hlsl | 10 +++++----- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Weave/Events.cpp b/Weave/Events.cpp index fe6d562..00d076c 100644 --- a/Weave/Events.cpp +++ b/Weave/Events.cpp @@ -3,6 +3,8 @@ #include "Graphix\Graphix.h" +#include "Graphix\GLM.h" + #include using std::cout; using std::endl; @@ -205,6 +207,7 @@ void Events::axis(int& axis, int keyUP, int keyDOWN) { axis = 0; } + axis = sign(axis); } int Events::getViewX() diff --git a/Weave/Game.cpp b/Weave/Game.cpp index 625d768..be0a8ef 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -82,12 +82,12 @@ Game::Game() : playing(true) // //cout << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << endl; //} //ein Gegner -// tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "duck.dae", "model_duck.png")); + tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "duck.dae", "model_duck.png")); //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(-1.f, 2.f, -2.f)), "../models/box/box.dae", "../Textures/sky_withstars.png")); //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, 3.f, -2.f)), "../models/cow/cow.dae", "../models/cow/texture.jpg")); // load LVL - tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "level_test.dae", "model_duck.png")); + //tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "level_test.dae", "model_duck.png")); //import("level_test.dae", tmp_Scene, shader1); diff --git a/Weave/Graphix/GLM.h b/Weave/Graphix/GLM.h index 94e6895..a334115 100644 --- a/Weave/Graphix/GLM.h +++ b/Weave/Graphix/GLM.h @@ -21,5 +21,12 @@ using glm::value_ptr; using glm::sign; +#define M_PI 3.14159265358979323846264338327950288 /* pi */ +#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ +#define M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ +#define M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ +#define M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ +#define M_D_R 57.2957795131 /* 180/pi */ + float VektorAbs(const vec3& vek); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index 1c3c149..b3b2d87 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -65,7 +65,7 @@ void Graphix::init() glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - //glEnable(GL_CULL_FACE); + glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); //glEnable(GL_BLEND); diff --git a/Weave/Graphix/Scene.cpp b/Weave/Graphix/Scene.cpp index 836913e..c6eff2c 100644 --- a/Weave/Graphix/Scene.cpp +++ b/Weave/Graphix/Scene.cpp @@ -79,16 +79,20 @@ void Scene::update(float deltaT) //int shoot = Events::getAction1(); //int reset = Events::getAction2(); - if (move_x) - lookat->move(0.03f *move_x * viewPort->rotateDirection(vec3(-1.f, 0.f, 0.f))); - if (move_y) - lookat->move(0.03f *move_y * viewPort->rotateDirection(vec3(0.f, 0.f, -1.f))); - // XYAchse um den Player - viewPort->rotateView(.3f*Events::getViewX(), .3f*Events::getViewY()); + viewPort->rotateView(0.005f*Events::getViewX(), 0.002f*Events::getViewY()); //int view_x = Events::getViewX(); //int view_y = Events::getViewY(); + if (move_x){ + //TODO vorwärts schneller gehen nach einer sekunde + lookat->move(3.f * deltaT *move_x * viewPort->rotateDirection(vec3(-1.f, 0.f, 0.f))); + } + if (move_y) + lookat->move(3.f *move_y * deltaT * viewPort->rotateDirection(vec3(0.f, 0.f, -1.f))); + + + //if ( view_x || view_y) //{ // //TODO Limit Rotation diff --git a/Weave/Graphix/ViewPort.cpp b/Weave/Graphix/ViewPort.cpp index 75c315b..3aab0ff 100644 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@ -5,8 +5,8 @@ #include "Shader.h" -#define VIEW_TOP_LIM 60.f -#define VIEW_BOT_LIM -30.f +#define VIEW_TOP_LIM 0.8f +#define VIEW_BOT_LIM -0.3f ViewPort::ViewPort(unsigned int _x, unsigned int _y, unsigned int _width, unsigned int _height, float fovy, float zNear, float zFar) : @@ -60,14 +60,14 @@ void ViewPort::rotateView(float angle_x, float angle_y){ view_angle_y = VIEW_BOT_LIM; //keine Ahnung warum hier noch durch 50 geteilt werden muss, sonst ists aber irgend wie falsch - view = translate(vec3(0.f, 0.f, -view_dist))*rotate(view_angle_y / 50, vec3(1.f, 0.f, 0.f))*rotate(view_angle_x / 50, vec3(0.f, 1.f, 0.f)); + view = translate(vec3(0.f, 0.f, -view_dist))*rotate(view_angle_y *(float)M_PI_4, vec3(1.f, 0.f, 0.f))*rotate(view_angle_x * (float)M_PI_4, vec3(0.f, 1.f, 0.f)); } } vec3 ViewPort::rotateDirection(const vec3 & direction) const{ - return glm::rotateY(direction,- view_angle_x / 50); + return glm::rotateY(direction, -view_angle_x * (float)M_PI_4); } unsigned int ViewPort::getXPos() const diff --git a/shader/basicTexture_VS.hlsl b/shader/basicTexture_VS.hlsl index 0b5bc86..3b2d055 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -31,7 +31,7 @@ void main() gl_Position = projection * view * world_position; worldNormal = (model * inv * vec4(normal, 0.0f)).xyz; - visNormal = (view * vec4(worldNormal, 0.0f)).z; +// visNormal = (view * vec4(worldNormal, 0.0f)).z; SpecularCosPoint1 = clamp(dot(vec3(0.0f, 0.0f, -1.0f), normalize((projection * view * vec4(reflect(-PointLightPosition1, worldNormal), 0.0f)).xyz)), 0, 1); diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index 9b56637..e36e627 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -10,11 +10,11 @@ uniform sampler2D ColorTexture; void main() { - if (visNormal < -0.2) - { - discard; - } - float specularConst = 5.0f; + //if (visNormal < -0.2) + //{ + // discard; + //} + float specularConst = 3.0f; vec3 normal = normalize(worldNormal); vec4 uvColor = texture(ColorTexture, fUVs); -- 2.47.3