[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / BulletSoftBody / btCGProjection.h
1 /*
2  Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
3  
4  Bullet Continuous Collision Detection and Physics Library
5  Copyright (c) 2019 Google Inc. http://bulletphysics.org
6  This software is provided 'as-is', without any express or implied warranty.
7  In no event will the authors be held liable for any damages arising from the use of this software.
8  Permission is granted to anyone to use this software for any purpose,
9  including commercial applications, and to alter it and redistribute it freely,
10  subject to the following restrictions:
11  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13  3. This notice may not be removed or altered from any source distribution.
14  */
15
16 #ifndef BT_CG_PROJECTION_H
17 #define BT_CG_PROJECTION_H
18
19 #include "btSoftBody.h"
20 #include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
21 #include "BulletDynamics/Featherstone/btMultiBodyConstraint.h"
22
23 struct DeformableContactConstraint
24 {
25         const btSoftBody::Node* m_node;
26         btAlignedObjectArray<const btSoftBody::RContact*> m_contact;
27         btAlignedObjectArray<btVector3> m_total_normal_dv;
28         btAlignedObjectArray<btVector3> m_total_tangent_dv;
29         btAlignedObjectArray<bool> m_static;
30         btAlignedObjectArray<bool> m_can_be_dynamic;
31
32         DeformableContactConstraint(const btSoftBody::RContact& rcontact) : m_node(rcontact.m_node)
33         {
34                 append(rcontact);
35         }
36
37         DeformableContactConstraint() : m_node(NULL)
38         {
39                 m_contact.push_back(NULL);
40         }
41
42         void append(const btSoftBody::RContact& rcontact)
43         {
44                 m_contact.push_back(&rcontact);
45                 m_total_normal_dv.push_back(btVector3(0, 0, 0));
46                 m_total_tangent_dv.push_back(btVector3(0, 0, 0));
47                 m_static.push_back(false);
48                 m_can_be_dynamic.push_back(true);
49         }
50
51         void replace(const btSoftBody::RContact& rcontact)
52         {
53                 m_contact.clear();
54                 m_total_normal_dv.clear();
55                 m_total_tangent_dv.clear();
56                 m_static.clear();
57                 m_can_be_dynamic.clear();
58                 append(rcontact);
59         }
60
61         ~DeformableContactConstraint()
62         {
63         }
64 };
65
66 class btCGProjection
67 {
68 public:
69         typedef btAlignedObjectArray<btVector3> TVStack;
70         typedef btAlignedObjectArray<btAlignedObjectArray<btVector3> > TVArrayStack;
71         typedef btAlignedObjectArray<btAlignedObjectArray<btScalar> > TArrayStack;
72         btAlignedObjectArray<btSoftBody*>& m_softBodies;
73         const btScalar& m_dt;
74         // map from node indices to node pointers
75         const btAlignedObjectArray<btSoftBody::Node*>* m_nodes;
76
77         btCGProjection(btAlignedObjectArray<btSoftBody*>& softBodies, const btScalar& dt)
78                 : m_softBodies(softBodies), m_dt(dt)
79         {
80         }
81
82         virtual ~btCGProjection()
83         {
84         }
85
86         // apply the constraints
87         virtual void project(TVStack& x) = 0;
88
89         virtual void setConstraints() = 0;
90
91         // update the constraints
92         virtual btScalar update() = 0;
93
94         virtual void reinitialize(bool nodeUpdated)
95         {
96         }
97
98         virtual void setIndices(const btAlignedObjectArray<btSoftBody::Node*>* nodes)
99         {
100                 m_nodes = nodes;
101         }
102 };
103
104 #endif /* btCGProjection_h */