Bullet Collision Detection & Physics Library: btCGProjection.h Source File

Bullet Collision Detection & Physics Library

btCGProjection.h
Go to the documentation of this file.
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{
68public:
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 */
btMultiBodyConstraint.h
btMultiBodyLinkCollider.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
btSoftBody.h
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition btAlignedObjectArray.h:46
btCGProjection::setConstraints
virtual void setConstraints()=0
btCGProjection::m_dt
const btScalar & m_dt
Definition btCGProjection.h:73
btCGProjection::m_nodes
const btAlignedObjectArray< btSoftBody::Node * > * m_nodes
Definition btCGProjection.h:75
btCGProjection::m_softBodies
btAlignedObjectArray< btSoftBody * > & m_softBodies
Definition btCGProjection.h:72
btCGProjection::TVArrayStack
btAlignedObjectArray< btAlignedObjectArray< btVector3 > > TVArrayStack
Definition btCGProjection.h:70
btCGProjection::reinitialize
virtual void reinitialize(bool nodeUpdated)
Definition btCGProjection.h:94
btCGProjection::~btCGProjection
virtual ~btCGProjection()
Definition btCGProjection.h:82
btCGProjection::TVStack
btAlignedObjectArray< btVector3 > TVStack
Definition btCGProjection.h:69
btCGProjection::update
virtual btScalar update()=0
btCGProjection::btCGProjection
btCGProjection(btAlignedObjectArray< btSoftBody * > &softBodies, const btScalar &dt)
Definition btCGProjection.h:77
btCGProjection::TArrayStack
btAlignedObjectArray< btAlignedObjectArray< btScalar > > TArrayStack
Definition btCGProjection.h:71
btCGProjection::setIndices
virtual void setIndices(const btAlignedObjectArray< btSoftBody::Node * > *nodes)
Definition btCGProjection.h:98
btCGProjection::project
virtual void project(TVStack &x)=0
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
DeformableContactConstraint::m_static
btAlignedObjectArray< bool > m_static
Definition btCGProjection.h:29
DeformableContactConstraint::m_can_be_dynamic
btAlignedObjectArray< bool > m_can_be_dynamic
Definition btCGProjection.h:30
DeformableContactConstraint::DeformableContactConstraint
DeformableContactConstraint(const btSoftBody::RContact &rcontact)
Definition btCGProjection.h:32
DeformableContactConstraint::m_total_normal_dv
btAlignedObjectArray< btVector3 > m_total_normal_dv
Definition btCGProjection.h:27
DeformableContactConstraint::replace
void replace(const btSoftBody::RContact &rcontact)
Definition btCGProjection.h:51
DeformableContactConstraint::~DeformableContactConstraint
~DeformableContactConstraint()
Definition btCGProjection.h:61
DeformableContactConstraint::DeformableContactConstraint
DeformableContactConstraint()
Definition btCGProjection.h:37
DeformableContactConstraint::m_contact
btAlignedObjectArray< const btSoftBody::RContact * > m_contact
Definition btCGProjection.h:26
DeformableContactConstraint::append
void append(const btSoftBody::RContact &rcontact)
Definition btCGProjection.h:42
DeformableContactConstraint::m_total_tangent_dv
btAlignedObjectArray< btVector3 > m_total_tangent_dv
Definition btCGProjection.h:28
DeformableContactConstraint::m_node
const btSoftBody::Node * m_node
Definition btCGProjection.h:25
btSoftBody::Node
Definition btSoftBody.h:268
btSoftBody::RContact
Definition btSoftBody.h:342