summaryrefslogtreecommitdiff
path: root/src/BulletSoftBody/btDeformableLagrangianForce.h
blob: ff75eeb1c1fe65efc6871ef8b9b4ceaf193355c3 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
//  btDeformableLagrangianForce.h
//  BulletSoftBody
//
//  Created by Xuchen Han on 7/1/19.
//

#ifndef BT_DEFORMABLE_LAGRANGIAN_FORCE_H
#define BT_DEFORMABLE_LAGRANGIAN_FORCE_H

#include "btSoftBody.h"
#include <unordered_map>
enum btDeformableLagrangianForceType
{
    BT_GRAVITY_FORCE = 1,
    BT_MASSSPRING_FORCE = 2
};

class btDeformableLagrangianForce
{
public:
//    using TVStack = btAlignedObjectArray<btVector3>;
    typedef btAlignedObjectArray<btVector3> TVStack;
    btAlignedObjectArray<btSoftBody *> m_softBodies;
    const std::unordered_map<btSoftBody::Node *, size_t>* m_indices;
    
    btDeformableLagrangianForce()
    {
    }
    
    virtual ~btDeformableLagrangianForce(){}
    
    virtual void addScaledImplicitForce(btScalar scale, TVStack& force) = 0;
    
    virtual void addScaledForceDifferential(btScalar scale, const TVStack& dv, TVStack& df) = 0;
    
    virtual void addScaledExplicitForce(btScalar scale, TVStack& force) = 0;
    
    virtual btDeformableLagrangianForceType getForceType() = 0;
    
    virtual void reinitialize(bool nodeUpdated)
    {
    }
    
    virtual int getNumNodes()
    {
        int numNodes = 0;
        for (int i = 0; i < m_softBodies.size(); ++i)
        {
            numNodes += m_softBodies[i]->m_nodes.size();
        }
        return numNodes;
    }
    
    virtual void addSoftBody(btSoftBody* psb)
    {
        m_softBodies.push_back(psb);
    }
    
    virtual void setIndices(const std::unordered_map<btSoftBody::Node *, size_t>* indices)
    {
        m_indices = indices;
    }
};
#endif /* BT_DEFORMABLE_LAGRANGIAN_FORCE */