]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
player rotates to view direction
authorPeter Schaefer <schaeferpm@gmail.com>
Tue, 14 Apr 2015 15:28:20 +0000 (17:28 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Tue, 14 Apr 2015 15:28:20 +0000 (17:28 +0200)
fixed move in view direction

Weave/Graphix/GLM.h
Weave/Graphix/Scene.cpp
Weave/Graphix/SceneObject.cpp
Weave/Graphix/SceneObject.h
Weave/Graphix/ViewPort.cpp

index a334115d468bc26352474229d901d82139c0a0e5..4cf11864be538eb18b52214f73c951f21254ae5d 100644 (file)
@@ -4,6 +4,7 @@
 #include "glm\gtx\transform.hpp"
 #include "glm\gtc\type_ptr.hpp"
 #include "glm\gtx\rotate_vector.hpp"
+#include "glm\gtx\vector_angle.hpp"
 
 using glm::vec3;
 using glm::mat4;
@@ -17,6 +18,9 @@ using glm::normalize;
 using glm::inverse;
 using glm::dot;
 
+using glm::angle;
+using glm::orientedAngle;
+
 using glm::value_ptr;
 
 using glm::sign;
index 31666711859bb28a3df5555ac93425cdd4ae6ca6..92259ff3bc18225c9fce6507dfa41f196193b3f8 100644 (file)
@@ -11,6 +11,7 @@
 #include "Shader.h"
 
 #define TIME_TILL_MAX_MOVE 2
+#define TIME_TILL_DIRECTION_ROTATE 1
 
 #define SPEED_MOVE_NORMAL 1.5f
 #define MOVE_FASTER 2.f
@@ -89,12 +90,11 @@ void Scene::update(float deltaT)
 
        // XYAchse um den Player
        viewPort->rotateView(0.005f*Events::getViewX(), 0.002f*Events::getViewY());
-       //int view_x = Events::getViewX();
-       //int view_y = Events::getViewY();
 
+       // MOVE Player
        if (move_x)
                lookat->move(SPEED_MOVE_NORMAL *move_x * deltaT * viewPort->rotateDirection(vec3(-1.f, 0.f, 0.f)));
-               //TODO vorwärts schneller gehen nach einer sekunde
+
        if (move_y){
                if (move_y > 0){
                        if (move_delta < TIME_TILL_MAX_MOVE)
@@ -111,14 +111,10 @@ void Scene::update(float deltaT)
                move_delta = 0;
        }
 
+       //Rotate Play in move direction
 
-
-
-       //if ( view_x || view_y)
-       //{
-       //      //TODO Limit Rotation
-       //      view = view * rotate(0.3f, vec3(view_y ,view_x, 0.f));
-       //}
+       if (move_x || move_y)
+               lookat->turnTo(viewPort->rotateDirection(vec3(0.f, 0.f, -1.f)),3*deltaT/TIME_TILL_DIRECTION_ROTATE);
                
 
        //// Zoom auf Player
index d8526c8c2e5f843e684cd0af14eff65a3e699e87..a0df5102a802cd8649dd9528f6cb91d2ebf11f5e 100644 (file)
@@ -100,18 +100,33 @@ void SceneObject::setModel(mat4& _model){
        model = _model;
 }
 
-void SceneObject::turn(float degree, vec3& axis){
+void SceneObject::turn(float angle, vec3& axis){
        //vec3  pos = getPosition();
        //model = rotate(degree, axis)*model;
        //model = model*translate(pos - getPosition());
-       model = model * rotate(degree, axis);
+       model = model * rotate(angle, axis);
+}
+
+void SceneObject::turnTo(vec3& direction, float speed){
+       vec3  pos = getPosition();
+       float perc = 1;
+       model = translate(-pos) * model;
+       float rot_angle = orientedAngle(normalize((vec3)(model * vec4(0.f, 0.f, 1.f, 1.f))), direction, vec3(0.f, 1.f, 0.f));
+
+       if (abs(rot_angle) / M_PI > speed)
+               perc = speed / abs(rot_angle) * M_PI;
+       
+               model = rotate(rot_angle *perc , vec3(0.f, 1.f, 0.f)) * model;
+       model = translate(pos) * model;
 }
 
 void SceneObject::move(vec3& dist){
-       model = model * translate(dist);
+       model = translate(dist) * model;
 }
 
 
+
+
 void SceneObject::setCollision(bool _col)
 {
        collision_ignore = !_col;
index ea431f3d6c5e24eb2677bff2e14837c228d70621..78e2799dcf186722e62a8a8f3f8d32fcb01752a1 100644 (file)
@@ -34,7 +34,8 @@ public:
        virtual vec3 getPosition() const;
 
        virtual void setModel(mat4&);
-       virtual void turn(float degree, vec3& axis);
+       virtual void turn(float angle, vec3& axis);
+       virtual void turnTo(vec3& direction, float speed = 1);
        virtual void move(vec3& dist);
 
        //virtual bool operator==(SceneObject);
index 3aab0ff9893f5203825cda871ea0c728a3353fd7..70e1ab184ab538509fc3862c7d19b91368a02ee9 100644 (file)
@@ -59,7 +59,6 @@ void ViewPort::rotateView(float angle_x, float angle_y){
                if (view_angle_y < VIEW_BOT_LIM)
                        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 *(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));
 
        }