Skylicht Engine
Loading...
Searching...
No Matches
CCollider.h
1/*
2!@
3MIT License
4
5Copyright (c) 2024 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Components/CComponentSystem.h"
28
29#ifdef USE_BULLET_PHYSIC_ENGINE
30#include <btBulletCollisionCommon.h>
31#endif
32
33#include "RenderMesh/CMesh.h"
34
35namespace Skylicht
36{
37 namespace Physics
38 {
46 class CCollider : public CComponentSystem
47 {
48 public:
54 { Box,
55 Sphere,
56 Plane,
57 Cylinder,
58 Capsule,
59 BvhMesh,
60 ConvexMesh,
61 Mesh,
62 Unknown,
63 };
64
65 protected:
66 EColliderType m_colliderType;
67
68 core::vector3df m_offset;
69
70 bool m_dynamicSupport;
71
72#ifdef USE_BULLET_PHYSIC_ENGINE
73 btCollisionShape* m_shape;
74#endif
75
76 public:
77 CCollider();
78
79 virtual ~CCollider();
80
81 virtual void initComponent();
82
88 {
89 return m_colliderType;
90 }
91
92#ifdef USE_BULLET_PHYSIC_ENGINE
97 virtual btCollisionShape* initCollisionShape() = 0;
98
102 virtual void dropCollisionShape();
103#endif
104
109
115
120 inline bool isDynamicSupport()
121 {
122 return m_dynamicSupport;
123 }
124
131
137
138 protected:
139
143 CMesh* generateMesh(IMesh* primitive, bool tangent);
144
148 CMesh* getPlane(const core::plane3df& plane, float sizeX, float sizeZ);
149
150 };
151 }
152}
Definition CMesh.h:75
Base class for all collision shapes.
Definition CCollider.h:47
EColliderType getColliderType()
Gets the type of the collider.
Definition CCollider.h:87
bool isDynamicSupport()
Checks if this collider type supports dynamic rigid bodies.
Definition CCollider.h:120
CMesh * generateMesh(const core::aabbox3df &maxBBox)
Generates a visual mesh representing the collision shape.
CMesh * getPlane(const core::plane3df &plane, float sizeX, float sizeZ)
Helper to generate a plane mesh.
void initRigidbody()
Triggers the initialization of the attached CRigidbody.
CMesh * generateMesh(IMesh *primitive, bool tangent)
Helper to generate a mesh from a primitive.
core::aabbox3df getBBox()
Gets the axis-aligned bounding box of the collider in world space.
void clampSize(core::vector3df &size)
Clamps the size vector to ensure no negative dimensions.
EColliderType
Supported collider types.
Definition CCollider.h:54
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
aabbox3d< f32 > aabbox3df
Typedef for a f32 3d bounding box.
Definition aabbox3d.h:351
plane3d< f32 > plane3df
Typedef for a f32 3d plane.
Definition plane3d.h:236