Cogs.Core
Extensions
Physics
Source
ConstraintSystem.h
1
#pragma once
2
#ifdef _WIN32
3
#pragma warning(push)
4
#pragma warning(disable: 4127)
// conditional expression is constant
5
#pragma warning(disable: 5033)
// 'register' is no longer a supported storage class
6
#endif
7
#include <btBulletDynamicsCommon.h>
8
#ifdef _WIN32
9
#pragma warning(pop)
10
#endif
11
12
13
#include "Systems/ComponentSystem.h"
14
#include "ConstraintComponent.h"
15
16
namespace
Cogs
17
{
18
namespace
Core
19
{
20
class
PhysicsManager;
21
22
struct
ConstraintData
23
{
24
template
<
typename
T,
typename
... Args>
25
T * createConstraint(Args && ... args)
26
{
27
constraint = std::make_unique<T>(std::forward<Args>(args)...);
28
29
return
static_cast<
T *
>
(constraint.get());
30
}
31
32
std::unique_ptr<btTypedConstraint> constraint;
33
34
glm::mat4 transform;
35
glm::mat4 targetTransform;
36
37
btRigidBody * rigidBody =
nullptr
;
38
btRigidBody * targetRigidBody =
nullptr
;
39
};
40
41
template
<
typename
T>
42
class
ConstraintSystem
:
public
ComponentSystemWithDataPool
<T, ConstraintData>
43
{
44
public
:
45
ConstraintSystem
(
Memory::Allocator
* allocator,
Cogs::SizeType
capacity) :
ComponentSystemWithDataPool<T, ConstraintData>
(allocator, capacity) {}
46
};
47
48
class
FixedConstraintSystem
:
public
ConstraintSystem
<FixedConstraintComponent>
49
{
50
public
:
51
FixedConstraintSystem
(
Memory::Allocator
* allocator,
Cogs::SizeType
capacity) :
ConstraintSystem
(allocator, capacity) {}
52
53
void
update
(
Context
*
context
)
final
;
54
55
void
destroyComponent
(
ComponentHandle
component)
final
;
56
};
57
58
class
HingeConstraintSystem
:
public
ConstraintSystem
<HingeConstraintComponent>
59
{
60
public
:
61
HingeConstraintSystem
(
Memory::Allocator
* allocator,
Cogs::SizeType
capacity) :
ConstraintSystem
(allocator, capacity) {}
62
63
void
update
(
Context
*
context
)
final
;
64
65
void
destroyComponent
(
ComponentHandle
component)
final
;
66
};
67
68
class
SpringConstraintSystem
:
public
ConstraintSystem
<SpringConstraintComponent>
69
{
70
public
:
71
SpringConstraintSystem
(
Memory::Allocator
* allocator,
Cogs::SizeType
capacity) :
ConstraintSystem
(allocator, capacity) {}
72
73
void
update
(
Context
*
context
)
final
;
74
75
void
destroyComponent
(
ComponentHandle
component)
final
;
76
};
77
78
class
GenericConstraintSystem
:
public
ConstraintSystem
<GenericConstraintComponent>
79
{
80
public
:
81
GenericConstraintSystem
(
Memory::Allocator
* allocator,
Cogs::SizeType
capacity) :
ConstraintSystem
(allocator, capacity) {}
82
83
void
update
(
Context
*
context
)
final
;
84
85
void
destroyComponent
(
ComponentHandle
component)
final
;
86
};
87
}
88
}
Cogs::Core::ComponentSystemBase::context
Context * context
Pointer to the Context instance the system lives in.
Definition:
ComponentSystem.h:136
Cogs::Core::ComponentSystemBase::update
void update()
Updates the system state to that of the current frame.
Definition:
ComponentSystem.h:65
Cogs::Core::ComponentSystemWithDataPool
Component system with parallel data per component stored in a pool similar to how the components them...
Definition:
ComponentSystem.h:365
Cogs::Core::ConstraintSystem
Definition:
ConstraintSystem.h:43
Cogs::Core::Context
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition:
Context.h:83
Cogs::Core::FixedConstraintSystem
Definition:
ConstraintSystem.h:49
Cogs::Core::FixedConstraintSystem::destroyComponent
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
Definition:
ConstraintSystem.cpp:87
Cogs::Core::GenericConstraintSystem
Definition:
ConstraintSystem.h:79
Cogs::Core::GenericConstraintSystem::destroyComponent
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
Definition:
ConstraintSystem.cpp:192
Cogs::Core::HingeConstraintSystem
Definition:
ConstraintSystem.h:59
Cogs::Core::HingeConstraintSystem::destroyComponent
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
Definition:
ConstraintSystem.cpp:120
Cogs::Core::SpringConstraintSystem
Definition:
ConstraintSystem.h:69
Cogs::Core::SpringConstraintSystem::destroyComponent
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
Definition:
ConstraintSystem.cpp:160
Cogs::Memory::Allocator
Base allocator implementation.
Definition:
Allocator.h:30
Cogs
Contains all Cogs related functionality.
Definition:
FieldSetter.h:23
Cogs::SizeType
ComponentIndex SizeType
Type used to track the size of pools.
Definition:
Component.h:19
Cogs::ComponentModel::ComponentHandle
Handle to a Component instance.
Definition:
Component.h:67
Cogs::Core::ConstraintData
Definition:
ConstraintSystem.h:23
Generated by
1.9.6