summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Components/CollisionComponents/collisioncomponent.h
blob: daef72392a3957715aeb1286c2c5b693b17ca77c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef COLLISIONCOMPONENT_H
#define COLLISIONCOMPONENT_H

#include "Game/Components/CollisionComponents/BoundingShape.h"
#include <map>
#include <string>
#include "Game/TypeMap.h"
#include "Graphics/modeltransform.h"
#include "glm/glm.hpp"
#include "Game/Components/Component.h"


class CollisionComponent : public Component
{
public:
    template <typename T>
    void addCollisionShape(std::shared_ptr<T> &&component){
        m_collision_shapes.put<T>(std::forward<std::shared_ptr<T>>(component));
    }

    template <typename T>
    bool hasCollisionShape(){
        return m_collision_shapes.contains<T>();
    }

    template <class T>
    T* getCollisionShape(){
        auto comp = m_collision_shapes.find<T>();
        assert(comp != m_collision_shapes.end());
        return static_cast<T*>(comp->second.get());
    }

    CollisionComponent(std::string shapeType, std::shared_ptr<ModelTransform> mt, const glm::vec3 &initial_pos, std::vector<glm::vec3> &obj_data);
    CollisionComponent(std::string shapeType, std::shared_ptr<ModelTransform> mt, const glm::vec3 &initial_pos);
    CollisionComponent(std::string shapeType, const std::vector<glm::vec3> &obj_data, const std::shared_ptr<ModelTransform> &mt,
                       bool isGround = false);

    bool isRigidBody();
    float getReboundVel();
    float getAcceleration();

private:
    TypeMap<std::shared_ptr<BoundingShape>> m_collision_shapes;
    bool m_isRigid = true;
    float m_rebound_vel = 0.f;
    float m_acceleration = 0.f;
};

#endif // COLLISIONCOMPONENT_H