diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index f74432d..585f463 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -23,5 +23,7 @@ namespace entities this->rotation.y += rotation.y; this->rotation.z += rotation.z; } + + } diff --git a/src/entities/Entity.h b/src/entities/Entity.h index 3fd3c2b..6a041bc 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -40,7 +40,7 @@ namespace entities inline glm::vec3 GetPosition() const { return position; } inline void SetPosition(const ::glm::vec3& position) { this->position = position; } inline glm::vec3 GetRotation() const { return rotation; } - inline void SetRotation(const ::glm::vec3& rotation) { this->rotation = rotation; } + void SetRotation(const ::glm::vec3& rotation) { this->rotation = rotation; } inline float GetScale() const { return scale; } inline void SetScale(const float scale) { this->scale = scale; } }; diff --git a/src/entities/main_character.cpp b/src/entities/main_character.cpp index 9c8f587..3f55076 100644 --- a/src/entities/main_character.cpp +++ b/src/entities/main_character.cpp @@ -7,11 +7,10 @@ #include"../renderEngine/loader.h" namespace entities { - float movement_speed; - float down_speed; - float side_speed; + int movement_speed, down_speed, side_speed; bool is_playing; + MainCharacter::MainCharacter(const models::TexturedModel& model, const glm::vec3& position, const glm::vec3& rotation, float scale, const collision::Box& bounding_box) : CollisionEntity(model, position, rotation, scale, bounding_box) @@ -25,11 +24,12 @@ namespace entities computervision::HandDetectRegion* reg_up = regions.at(1); computervision::HandDetectRegion* reg_right = regions.at(2); - if (is_playing) { - movement_speed = -0.5f; //Forward speed adjustment, bee is moving at a standard speedrate - down_speed = -1.0f; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED - side_speed = 0; //Side speed adjustment + double delta_time = UpdateDelta(); + if (is_playing) { + movement_speed = -15; //Forward speed adjustment, bee is moving at a standard speedrate + down_speed = -50; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED + side_speed = 0; //Side speed adjustment //For gameplay with use of keyboard keys: W, A, S, D //W: Go forward //A: Go left @@ -37,10 +37,12 @@ namespace entities //D: Go right //TODO Implement CV actions //top right + SetRotation(glm::vec3(0, 90, 0)); if (reg_up->IsHandPresent() && reg_left->IsHandPresent()) { side_speed += SIDE_SPEED; - down_speed += UP_SPEED; + down_speed += UP_SPEED/2; + SetRotation(glm::vec3(10, 90, 0)); } //right if (reg_left->IsHandPresent()) @@ -50,8 +52,9 @@ namespace entities //top left if (reg_up->IsHandPresent() && reg_right->IsHandPresent()) { - down_speed += UP_SPEED; + down_speed += UP_SPEED/2; side_speed -= SIDE_SPEED; + SetRotation(glm::vec3(10, 90, 0)); } //left if (reg_right->IsHandPresent()) @@ -65,7 +68,8 @@ namespace entities SetRotation(glm::vec3(10, 90, 0)); } } - IncreasePosition(glm::vec3(side_speed, down_speed, movement_speed)); + IncreasePosition(glm::vec3(side_speed*delta_time, down_speed*delta_time, movement_speed*delta_time)); + std::cout << "delta time char: "<< delta_time << std::endl; //Use only for binding bee to house, such that it doesn't go outside of the room. //TODO delete when boundingbox is implemented! @@ -87,4 +91,14 @@ namespace entities is_playing = false; std::cout << "collision" << std::endl; } + + double MainCharacter::UpdateDelta() + { + double current_time = glfwGetTime(); + static double last_frame_time = current_time; + double delt_time = current_time - last_frame_time; + last_frame_time = current_time; + return delt_time; + } + } \ No newline at end of file diff --git a/src/entities/main_character.h b/src/entities/main_character.h index c068f8a..589536a 100644 --- a/src/entities/main_character.h +++ b/src/entities/main_character.h @@ -10,8 +10,8 @@ namespace entities * This class contains the information about the player model */ class MainCharacter : public CollisionEntity { - const float SIDE_SPEED = 0.8f; //Standard movement speed for left/right movement - const float UP_SPEED = 2.0f; //Standard movement speed for up movement + const int SIDE_SPEED = 40; //Standard movement speed for left/right movement + const int UP_SPEED = 100; //Standard movement speed for up movement public: /* * @brief: Constructor for the main character model @@ -35,5 +35,7 @@ namespace entities void Move(std::vector regions); void OnCollide(const collision::Collision& collision) override; + + double UpdateDelta(); }; } diff --git a/src/scenes/in_Game_Scene.cpp b/src/scenes/in_Game_Scene.cpp index 5630bcb..05c0bc9 100644 --- a/src/scenes/in_Game_Scene.cpp +++ b/src/scenes/in_Game_Scene.cpp @@ -62,7 +62,7 @@ namespace scene score = 0; } /** - * temporary!!!! + * temporary? * just to make some bounding boxes */ collision::Box create_bounding_box(glm::vec3 size, glm::vec3 pos, int scale) {