#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;
using glm::inverse;
using glm::dot;
+using glm::angle;
+using glm::orientedAngle;
+
using glm::value_ptr;
using glm::sign;
#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
// 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)
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
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;
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);
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));
}