Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
CollisionComponent.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 #include <ThirdParty/Box2D/Box2D/Box2D.h>
6 #include <ThirdParty/glm/glm/detail/type_vec2.hpp>
7 #include <ThirdParty/EASTL-master/include/EASTL/shared_ptr.h>
8 
9 namespace Engine
10 {
11  class TransformComponent;
12 
18  {
19  // Shortcuts
20  typedef eastl::shared_ptr<CollisionComponent> CollPtr;
21  friend class CollisionSystem;
22 
24  CollisionComponent(CollisionComponent& collisionComponent);
25  CollisionComponent(CollisionShapeType objectType, b2BodyType bodyType);
26 
27  void InitializeComponent() override;
28 
30 
31  void OnComponentAdded(eastl::weak_ptr<Component> addedComponent) override;
32  void OnComponentRemoved(eastl::weak_ptr<Component> removedComponent) override;
33 
34  eastl::weak_ptr<TransformComponent> GetTransformComponent() const;
35 
36  public:
37  // Type
42  void SetBodyType(b2BodyType bodyType);
43 
48  b2BodyType GetBodyType() const;
49 
50  // Shapes
55  void SetCircle(const float radius);
56 
61  float GetCircleRadius() const;
62 
68  void SetAABB(const float sizeX, const float sizeY);
69 
74  void SetAABB(const glm::vec2& size);
75 
80  glm::vec2 GetAABBSize() const;
81 
86  CollisionShapeType GetCollisionShapeType() const;
87 
88  // Layers
94  void SetCollisionLayer(CollisionLayer layer);
95 
100  CollisionLayer GetCollisionLayer() const;
101 
107  void SetDetectionLayers(CollisionLayer layers);
108 
113  CollisionLayer GetDetectionLayers() const;
114 
121  void SetIsSensor(bool isSensor);
122 
127  bool GetIsSensor() const;
132  template <typename archive>
133  void SaveComponent(archive ar);
134 
139  template<typename archive>
140  void LoadComponent(archive ar);
141  private:
142  // Body Construction Data
143  b2BodyDef bodyDef;
144  b2FixtureDef fixtureDef;
145  b2CircleShape circleShape;
146  b2PolygonShape boxShape;
147  // Body Data
148  b2Body* body;
149  CollisionShapeType shapeType;
150  b2Vec2 boxSize;
151 
152  eastl::weak_ptr<TransformComponent> transformComponent;
153  };
154 }
This is the base class for components. NOTE: only the Entity class is allowed to create this object...
Definition: Component.hpp:16
#define ENGINE_API
Definition: api.hpp:25
CollisionShapeType
Enum for available collision shapes
The Collision component is an entities link to the Collision System and allows for interaction with t...
The Collision System handles and stores run-time collision data using the Box2D library ...
CollisionLayer
Bitmask Enum that allows for layered collision checking