#include "../Graphix/Shader.h"
#include "../GLM.h"
+#include "../Events.h"
+#include "../Graphix/ViewPort.h"
+#include "Scene.h"
+#define TIME_TILL_MAX_MOVE 2
+#define TIME_TILL_DIRECTION_ROTATE 1
+
+#define SPEED_MOVE_NORMAL 1.5f
+#define MOVE_FASTER 2.5f
Marvin::Marvin(Shader* _shader, const mat4& _modelMat) :
-SceneObject(_shader, _modelMat, vec4(7.0f, 0.7f, 1.0f, 3.0f), "Player.dae", "model_player_2D.png")
+SceneObject(_shader, _modelMat, vec4(7.0f, 0.7f, 1.0f, 3.0f), "Player.dae", "model_player_2D.png"),
+move_delta(0)
{
collide_group = COL_MARVIN;
collide_with = COL_LEVEL | COL_ENEMY;
Marvin::~Marvin()
{
}
+
+
+void Marvin::update(float deltaT)
+{
+ ViewPort& viewPort(mainScene->getViewport());
+
+ // XYAchse um den Player
+ float rotatex = 0.002f*Events::getViewX();
+ float rotatey = 0.001f*Events::getViewY();
+ viewPort.rotateView(rotatex, rotatey);
+
+ //Jump
+ if (Events::getJump() && floorBound())
+ ySpeed += 5.5;
+
+ int move_x = Events::getMoveX();
+ int move_y = Events::getMoveY();
+ // MOVE Player
+ if (move_x)
+ move(SPEED_MOVE_NORMAL *move_x * deltaT * viewPort.rotateDirection(vec3(-1.f, 0.f, 0.f)));
+
+ if (move_y){
+ if (move_y > 0){
+ if (move_delta < TIME_TILL_MAX_MOVE)
+ move_delta += deltaT;
+ if (move_delta > TIME_TILL_MAX_MOVE)
+ move_delta = TIME_TILL_MAX_MOVE;
+ move(SPEED_MOVE_NORMAL * (MOVE_FASTER * move_delta / TIME_TILL_MAX_MOVE + 1) *move_y * deltaT * viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)));
+ }
+ else
+ move(SPEED_MOVE_NORMAL *move_y * deltaT * viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)));
+ }
+ else
+ {
+ move_delta = 0;
+ }
+
+ //Rotate Play in move direction
+ if (move_x || move_y)
+ turnTo(viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)), 3 * deltaT / TIME_TILL_DIRECTION_ROTATE);
+
+ SceneObject::update(deltaT);
+}
using std::set;
using std::stack;
-#define TIME_TILL_MAX_MOVE 2
-#define TIME_TILL_DIRECTION_ROTATE 1
-
-#define SPEED_MOVE_NORMAL 1.5f
-#define MOVE_FASTER 2.5f
-
#define timestep 0.01f
#define SCENE_SIZE 500.0
Scene::Scene(unsigned int x, unsigned int y, unsigned int width, unsigned int height, float fovy, float zNear, float zFar, vec3 pos, SceneObject* _lookat) :
viewPort(x, y, width, height, fovy, zNear, zFar),
-lookat(_lookat),
-move_delta(0)
+lookat(_lookat)
{
currenttime = 0.0f;
if (lookat != nullptr)
void Scene::update(float deltaT)
{
- vec3 pos;
- //Focus auf Player
-
- if (lookat != NULL){
- pos = lookat->getPosition();
- }
-
// XYAchse um den Player
- float rotatex = 0.002f*Events::getViewX();
- float rotatey = 0.001f*Events::getViewY();
- viewPort.rotateView(rotatex, rotatey);
+
if (!Events::getTimeShift())
{
- int move_x = Events::getMoveX();
- int move_y = Events::getMoveY();
+
//int shoot = Events::getAction1();
//int reset = Events::getAction2();
//Jump
- if (Events::getJump() && lookat->floorBound())
- lookat->ySpeed += 5.5;
+ //if (Events::getJump() && lookat->floorBound())
+ // lookat->ySpeed += 5.5;
//else if (!Events::isKHeld(SDLK_SPACE) && lookat->ySpeed>0)
// lookat->ySpeed = 0;
currenttime += deltaT;
-
-
- // MOVE Player
- if (move_x)
- lookat->move(SPEED_MOVE_NORMAL *move_x * deltaT * viewPort.rotateDirection(vec3(-1.f, 0.f, 0.f)));
-
- if (move_y){
- if (move_y > 0){
- if (move_delta < TIME_TILL_MAX_MOVE)
- move_delta += deltaT;
- if (move_delta > TIME_TILL_MAX_MOVE)
- move_delta = TIME_TILL_MAX_MOVE;
- lookat->move(SPEED_MOVE_NORMAL * (MOVE_FASTER * move_delta / TIME_TILL_MAX_MOVE + 1) *move_y * deltaT * viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)));
- }
- else
- lookat->move(SPEED_MOVE_NORMAL *move_y * deltaT * viewPort.rotateDirection(vec3(0.f, 0.f, -1.f)));
- }
- else
- {
- move_delta = 0;
- }
-
- //Rotate Play in move direction
-
- 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
//if (Events::getViewZ())
//{
contactManifold->refreshContactPoints(obA->getWorldTransform(), obB->getWorldTransform());
if (contactManifold->getNumContacts()>0)
- {
+ {
((SceneObject*)obA->getUserPointer())->collides((SceneObject*)obB->getUserPointer(), contactManifold);
((SceneObject*)obB->getUserPointer())->collides((SceneObject*)obA->getUserPointer(), contactManifold);
}
}
-
- //for (auto i = SceneObjects.begin(); i != SceneObjects.end(); ++i)
- //{
- // auto j = i;
- // for (j++; j != SceneObjects.end(); ++j)
- // {
- // SceneObject::checkCollision(*i, *j);
- // }
- //}
-
}
else
{
//bt_collision_world->addCollisionObject(*_add);
bt_collision_world->addCollisionObject(*_add,_add->getCollideGroup(),_add->getCollideWith());
-// _add->setMainScene(this);
+ _add->setMainScene(this);
}
void Scene::deleteObject(SceneObject* _del)
void Scene::setLookAt(SceneObject* _lookat)
{
lookat = _lookat;
+}
+
+ViewPort& Scene::getViewport()
+{
+ return viewPort;
}
\ No newline at end of file