]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
corrected Events (right Keys/Action)
authorPeter Schaefer <schaeferpm@gmail.com>
Sat, 4 Apr 2015 07:58:27 +0000 (09:58 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Sat, 4 Apr 2015 07:58:27 +0000 (09:58 +0200)
Weave/Events.cpp
Weave/Events.h
Weave/Graphix/Model.cpp
Weave/Graphix/Model.h
Weave/Graphix/Scene.cpp

index c6908aff7fb7ad119f7bc1da976d0bb8a8c7aa92..e7e6ea3423b09e80509e555b6516742d0da1b130 100644 (file)
@@ -7,7 +7,7 @@
 using std::cout;
 using std::endl;
 
-int returnSet(int& value, int action2 = 0);
+
 
 
 void Events::processEvents()
@@ -21,60 +21,50 @@ void Events::processEvents()
                        break;
                }
                case SDL_WINDOWEVENT:
-               {
                        switch (sdl_event.window.event)
                        {
                        case SDL_WINDOWEVENT_FOCUS_GAINED:
-                       {
                                window_focus = true;
                                Graphix::catchMouse();
                                break;
-                       }
                        case SDL_WINDOWEVENT_FOCUS_LOST:
-                       {
                                window_focus = false;
                                Graphix::freeMouse();
                                break;
-                       }
                        case SDL_WINDOWEVENT_RESIZED:
-                       {
                                Graphix::setWindowSize(sdl_event.window.data1, sdl_event.window.data2);
                                break;
-                       }
                        default:
                                break;
                        }
                        break;
-               }
-               case SDL_KEYDOWN:{
+               case SDL_KEYDOWN:
                        if (sdl_event.key.keysym.sym == SDLK_ESCAPE)
                        {
-                               quit = true;
+                               quit = true;    //TODO nicht gleich alles beenden bei Escape
+                               halt = true;
                        }
-                       key_held[sdl_event.key.keysym.sym]=true;
+                       if (!isKHeld(sdl_event.key.keysym.sym))
+                               KeyDown(sdl_event.key.keysym.sym);
+
+                       key_held[sdl_event.key.keysym.sym] = true;
                        break;
-               }
-               case SDL_KEYUP:{
+               case SDL_KEYUP:
+                       KeyUp(sdl_event.key.keysym.sym);
                        key_held[sdl_event.key.keysym.sym]=false;
-                       fKey(sdl_event.key.keysym.sym);
                        break;
-               }
-               case SDL_MOUSEMOTION:{
+               case SDL_MOUSEMOTION:
                        if (window_focus)
                                mousemotion(sdl_event.motion);
                        break;
-               }
-               case SDL_MOUSEBUTTONDOWN:{
-                       if (sdl_event.button.button == SDL_BUTTON_LEFT)
-                       {
-                               action1++;
-                       }
-                       if (sdl_event.button.button == SDL_BUTTON_RIGHT)
-                       {
-                               action2++;
-                       }
+               case SDL_MOUSEBUTTONDOWN:
+                       MouseDown(sdl_event.button.button);
+                       mouse_held[sdl_event.button.button] = true;
+                       break;
+               case SDL_MOUSEBUTTONUP:
+                       MouseUp(sdl_event.button.button);
+                       mouse_held[sdl_event.button.button] = false;
                        break;
-               }
                default:
                        break;
                }
@@ -89,8 +79,8 @@ void Events::mousemotion(SDL_MouseMotionEvent sdl_motion)
        //if (sdl_motion.x!=400 && sdl_motion.y!=200)
        { 
                
-       mouse_x = sdl_motion.xrel;
-       mouse_y = sdl_motion.yrel;
+       view_x = sdl_motion.xrel;
+       view_y = sdl_motion.yrel;
 
        SDL_WarpMouseInWindow(NULL, Graphix::getWindowWidth() / 2, Graphix::getWindowHeight() / 2);
 
@@ -98,7 +88,7 @@ void Events::mousemotion(SDL_MouseMotionEvent sdl_motion)
        }
 }
 
-void Events::fKey(int _key)
+void Events::KeyDown(int _key)
 {
        switch (_key)
        {
@@ -132,6 +122,51 @@ void Events::fKey(int _key)
        case SDLK_F10:
                //???
                break;
+       case SDLK_SPACE:
+               jump++;
+               break;
+       case SDLK_LSHIFT:
+               timeshift = true;
+               break;
+       default:
+               break;
+       }
+}
+
+void Events::KeyUp(int _key)
+{
+       switch (_key)
+       {
+       case SDLK_LSHIFT:
+               timeshift = false;
+               break;
+       default:
+               break;
+       }
+}
+
+void Events::MouseDown(int _key)
+{
+       switch (_key)
+       {
+       case SDL_BUTTON_LEFT:
+               jump++;
+               break;
+       case SDL_BUTTON_RIGHT:
+               timeshift = true;
+               break;
+       default:
+               break;
+       }
+}
+
+void Events::MouseUp(int _key)
+{
+       switch (_key)
+       {
+       case SDL_BUTTON_RIGHT:
+               timeshift = false;
+               break;
        default:
                break;
        }
@@ -139,9 +174,8 @@ void Events::fKey(int _key)
 
 void Events::keymotion()
 {
-       axis(view_x, SDLK_w, SDLK_s);
-       axis(view_y, SDLK_a, SDLK_d);
-       axis(view_z, SDLK_e, SDLK_q);
+       axis(move_x, SDLK_w, SDLK_s);
+       axis(move_y, SDLK_a, SDLK_d);
 }
 
 void Events::padmotion()
@@ -174,45 +208,46 @@ void Events::axis(int& axis, int keyUP, int keyDOWN)
 
 int Events::getViewX()
 {
-       return view_x;
+       return returnSet(view_x);
 }
 
 int Events::getViewY()
 {
-       return view_y;
+       return returnSet(view_y);
 }
 
-int Events::getViewZ()
-{
-       return view_z;
-}
 
-int Events::getMouseX()
+int Events::getMoveX()
 {
-       return returnSet(mouse_x);
+       return move_x;
 }
 
-int Events::getMouseY()
+int Events::getMoveY()
 {
-       return returnSet(mouse_y);
+       return move_y;
 }
 
-int Events::getAction1()
+int Events::getJump()
 {
-       return returnSet(action1);
+       return returnSet(jump);
 }
 
-int Events::getAction2()
+bool Events::getTimeShift()
 {
-       return returnSet(action2);
+       return timeshift;
 }
 
-bool Events::isHeld(int const _key)
+bool Events::isKHeld(int const _key)
 {
        return key_held[_key];
 }
+bool Events::isMHeld(int const _key)
+{
+       return mouse_held[_key];
+}
+
 
-int returnSet(int& value, int action2)
+int Events::returnSet(int& value, int action2)
 {
        int tmp = value;
        value = action2;
@@ -225,15 +260,16 @@ map<int, bool> Events::pad_held;
 
 int Events::view_x = 0;
 int Events::view_y = 0;
-int Events::view_z = 0;
 
-int Events::mouse_x = 0;
-int Events::mouse_y = 0;
+int Events::move_x = 0;
+int Events::move_y = 0;
 
-int Events::action1 = 0;
-int Events::action2 = 0;
+int Events::jump = 0;
+bool Events::timeshift = false;
 
 bool Events::quit = false;
 
+bool Events::halt = false;
+
 bool Events::window_focus = true;
 
index 16d7248852d97eac63f0aabb681d9bb644c3b39f..b0158f53b342b80cbfb85c123219ce315266265b 100644 (file)
@@ -14,20 +14,21 @@ public:
        //virtual void keydown(SDL_Keycode sdl_event);
 
        bool static quit;
+       bool static halt;
 
        bool static window_focus;
 
        int static getViewX();
        int static getViewY();
-       int static getViewZ();
 
-       int static getMouseX();
-       int static getMouseY();
+       int static getMoveX();
+       int static getMoveY();
 
-       int static getAction1();
-       int static getAction2();
+       int static getJump();
+       bool static getTimeShift();
 
-       bool static isHeld(int const);
+       bool static isKHeld(int const);
+       bool static isMHeld(int const);
 
 private:
 
@@ -35,10 +36,16 @@ private:
        void static keymotion();
        void static padmotion();
 
-       void static fKey(int);
+       void static KeyDown(int);
+       void static KeyUp(int);
+
+       void static MouseDown(int);
+       void static MouseUp(int);
 
        void static axis(int&, int, int);
 
+       int static returnSet(int& value, int action2 = 0);
+
        //const Uint8* keymap;
        map<int, bool> static key_held;
        map<int, bool> static mouse_held;
@@ -46,13 +53,12 @@ private:
 
        int static view_x;
        int static view_y;
-       int static view_z;
 
-       int static mouse_x;
-       int static mouse_y;
+       int static move_x;
+       int static move_y;
 
-       int static action1;
-       int static action2;
+       int static jump;
+       bool static timeshift;
 
 
 };
index 5e977494562f7b7609f539fd3bfb26b12dc4da08..55de0107d57c9d24ccaa33f12cb89d41e38f07c1 100644 (file)
@@ -48,19 +48,19 @@ Model::~Model()
        
 }
 
-void Model::useModel(Shader* _shader)
-{
-       uint vao=-1;
-       auto i = shader_map.find(*_shader);
-       if (i == shader_map.end())
-               vao = bindShader(_shader);
-       else
-               vao = i->second;
-
-       glBindVertexArray(vao);
-       _shader->useShader();
-
-}
+//void Model::useModel(Shader* _shader)
+//{
+//     uint vao=-1;
+//     auto i = shader_map.find(*_shader);
+//     if (i == shader_map.end())
+//             vao = bindShader(_shader);
+//     else
+//             vao = i->second;
+//
+//     glBindVertexArray(vao);
+//     _shader->useShader();
+//
+//}
 
 void Model::useModel(Shader* _shader) const
 {
index 943532337aabbaf01e41f5e05639539174dbf7cb..f1af0d1d428db3f0654d0cc858050e22b34856a2 100644 (file)
@@ -18,7 +18,7 @@ public:
 
        virtual ~Model();
 
-       void useModel(Shader* shader);
+//     void useModel(Shader* shader);
        void useModel(Shader* shader) const;
        void drawModel() const;
        unsigned int bindShader(Shader* shader);
index 2ab84d1eb6fc3a3ee015763de939f897930cd262..6e441d7a675a64880aeda7c902c335853957442e 100644 (file)
@@ -79,10 +79,10 @@ void Scene::update(float deltaT)
        {
                Message::error("GameOver");
        }
-       int move_x = Events::getMouseX();
-       int move_y = Events::getMouseY();
-       int shoot = Events::getAction1();
-       int reset = Events::getAction2();
+       int move_x = Events::getMoveX();
+       int move_y = Events::getMoveY();
+       //int shoot = Events::getAction1();
+       //int reset = Events::getAction2();
 
        //cout << move_x << "      " << move_y << endl;
 
@@ -90,13 +90,13 @@ void Scene::update(float deltaT)
                lookat->turn(0.3f *move_x, vec3(0.f, 1.f, 0.f));
        if (move_y)
                lookat->turn(0.3f *move_y, vec3(1.f, 0.f, 0.f));
-       if (shoot)
-       {
-               vec3 direction = lookat->push(vec3(0.f, 0.f, shoot*0.1f));
-               //SceneObjects->push_back(self->copy();)
-       }
-       if (reset)
-               lookat->stop();
+       //if (shoot)
+       //{
+       //      vec3 direction = lookat->push(vec3(0.f, 0.f, shoot*0.1f));
+       //      //SceneObjects->push_back(self->copy();)
+       //}
+       //if (reset)
+       //      lookat->stop();
 
        // XYAchse um den Player
        if (Events::getViewX() || Events::getViewY())
@@ -112,16 +112,16 @@ void Scene::update(float deltaT)
        }
                
 
-       // Zoom auf Player
-       if (Events::getViewZ())
-       {
-       //      float dist = 0;
-       //      if (lookat!=NULL)
-       //              dist = VektorAbs(getViewerPos() - lookat->getPosition());
-       //      if (true)
-               view = translate( vec3(0.f,0.f,(float)(5*deltaT *sign(Events::getViewZ()))))*view;
-               //view = view*scale(vec3((float)(1 + deltaT * sign(Events::getViewZ()))));
-       }
+       //// Zoom auf Player
+       //if (Events::getViewZ())
+       //{
+       ////    float dist = 0;
+       ////    if (lookat!=NULL)
+       ////            dist = VektorAbs(getViewerPos() - lookat->getPosition());
+       ////    if (true)
+       //      view = translate( vec3(0.f,0.f,(float)(5*deltaT *sign(Events::getViewZ()))))*view;
+       //      //view = view*scale(vec3((float)(1 + deltaT * sign(Events::getViewZ()))));
+       //}
 
        if (lookat != NULL)
                pos = lookat->getPosition();