[ADD] made collision work
This commit is contained in:
@@ -14,7 +14,9 @@ namespace entities
|
||||
{
|
||||
if (on_collide != nullptr)
|
||||
{
|
||||
on_collide(collision);
|
||||
|
||||
on_collide(collision);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "entity.h"
|
||||
#include "../collision/collision.h"
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace entities
|
||||
{
|
||||
@@ -16,7 +18,8 @@ namespace entities
|
||||
glm::vec3 min_xyz;
|
||||
glm::vec3 max_xyz;
|
||||
|
||||
void (*on_collide)(const collision::Collision& collision);
|
||||
//void (*on_collide)(const collision::Collision& collision);
|
||||
std::function<void(const collision::Collision&)> on_collide;
|
||||
|
||||
public:
|
||||
CollisionEntity(const models::TexturedModel& model, const glm::vec3& position, const glm::vec3& rotation,
|
||||
@@ -52,7 +55,7 @@ namespace entities
|
||||
*
|
||||
* @param function: A function pointer to a function with the collision behaviour
|
||||
*/
|
||||
void SetCollisionBehaviour(void (*function)(const collision::Collision& collision))
|
||||
void SetCollisionBehaviour(std::function<void(const collision::Collision&)> function)
|
||||
{ if (function != nullptr) { on_collide = function; } }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -10,11 +10,12 @@ namespace entities
|
||||
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)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
glm::vec3 MainCharacter::Move(GLFWwindow* window)
|
||||
{
|
||||
float movement_speed = -1.0f; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||
float movement_speed = -0.5f; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||
float down_speed = -1.0f; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED
|
||||
float side_speed = 0; //Side speed adjustment
|
||||
|
||||
@@ -65,4 +66,8 @@ namespace entities
|
||||
MoveCollisionBox();
|
||||
return glm::vec3(side_speed, down_speed, movement_speed );
|
||||
}
|
||||
|
||||
void MainCharacter::OnCollide(const collision::Collision& collision) {
|
||||
std::cout << "collide" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -32,5 +32,7 @@ namespace entities
|
||||
* @return: Vector with the adjusted side_speed, down_speed, and movement_speed
|
||||
*/
|
||||
glm::vec3 Move(GLFWwindow* window);
|
||||
|
||||
void OnCollide(const collision::Collision& collision) override;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user