35 #include "LinearMath/btVector3.h"
36 #include "BulletDynamics/Dynamics/btRigidBody.h"
44 if(tagSearch.
matches(pair.getTags())) {
45 connectorInfo = createConnectorInfo(pair);
50 std::vector<tgConnectorInfo*> tgConnectorInfo::createConnectorInfos(
const tgPairs& pairs,
const tgTagSearch& tagSearch)
52 std::vector<tgConnectorInfo*> result;
53 for(
int i = 0; i < pairs.size(); i++) {
62 void tgConnectorInfo::chooseRigids(std::set<tgRigidInfo*> rigids)
67 if(getFromRigidInfo() == 0) {
68 tgRigidInfo* fromRigidInfo = chooseRigid(rigids, getFrom());
70 setFromRigidInfo(fromRigidInfo);
74 if(getToRigidInfo() == 0) {
75 tgRigidInfo* toRigidInfo = chooseRigid(rigids, getTo());
77 setToRigidInfo(toRigidInfo);
82 tgRigidInfo* tgConnectorInfo::chooseRigid(std::set<tgRigidInfo*> rigids,
const btVector3& v) {
84 std::set<tgRigidInfo*> candidateRigids = findRigidsContaining(rigids, v);
87 if (candidateRigids.size() == 1) {
89 chosenRigid = *(candidateRigids.begin());
91 else if (candidateRigids.size() > 1 ){
106 std::cout << std::endl <<
"WARNING: A connector is being created that has more than one potential connecting point. This behavior is not well defined. If your model does not behave as you expect, try moving these multiple rigid bodies apart by some distance, and having the connector attach to only one node." << std::endl
109 chosenRigid = findClosestCenterOfMass(candidateRigids, v);
111 else if (candidateRigids.size() == 0) {
113 std::cout << std::endl <<
"WARNING: A connector is being created without a connecting point on one end. This WILL cause the simulator to crash when its pointer to a tgRigidInfo is called, since no rigid body can be associated with this point, and so no tgRigidBody can be created." << std::endl << std::endl;
119 btRigidBody* tgConnectorInfo::getToRigidBody() {
121 if( getToRigidInfo() == NULL ){
122 std::cout << std::endl <<
"Error in tgConnectorInfo::getToRigidBody. "
123 <<
"The toRigidInfo for tgConnector with pair "
124 << getFrom() <<
", " << getTo() <<
" has not been assigned yet, "
125 <<
"but its getToRigidBody method is being called." << std::endl;
126 throw std::runtime_error(
"getToRigidInfo == NULL, cannot return rigid body.");
128 if( getToRigidInfo()->getRigidInfoGroup() == NULL ){
129 std::cout << std::endl <<
"Error in tgConnectorInfo::getToRigidBody. "
130 <<
"The toRigidInfo for tgConnector with pair "
131 << getFrom() <<
", " << getTo() <<
" has been assigned, but does "
132 <<
"not have a rigidInfoGroup from which to get a rigid body. "
134 throw std::runtime_error(
"getToRigidInfo()->getRigidInfoGroup() == NULL, cannot return rigid body.");
139 btRigidBody* tgConnectorInfo::getFromRigidBody() {
141 if( getFromRigidInfo() == NULL ){
142 std::cout << std::endl <<
"Error in tgConnectorInfo::getFromRigidBody. "
143 <<
"The fromRigidInfo for tgConnector with pair "
144 << getFrom() <<
", " << getTo() <<
" has not been assigned yet, "
145 <<
"but its getFromRigidBody method is being called." << std::endl;
146 throw std::runtime_error(
"getFromRigidInfo == NULL, cannot return rigid body.");
148 if( getFromRigidInfo()->getRigidInfoGroup() == NULL ){
149 std::cout << std::endl <<
"Error in tgConnectorInfo::getFromRigidBody. "
150 <<
"The fromRigidInfo for tgConnector with pair "
151 << getFrom() <<
", " << getTo() <<
" has been assigned, but does "
152 <<
"not have a rigidInfoGroup from which to get a rigid body. "
154 throw std::runtime_error(
"getFromRigidInfo()->getRigidInfoGroup() == NULL, cannot return rigid body.");
163 tgRigidInfo* tgConnectorInfo::findClosestCenterOfMass(std::set<tgRigidInfo*> rigids,
const btVector3& v) {
164 if (rigids.size() == 0) {
167 std::set<tgRigidInfo*>::iterator it;
171 for(; it != rigids.end(); ++it) {
181 std::set<tgRigidInfo*> tgConnectorInfo::findRigidsContaining(std::set<tgRigidInfo*> rigids,
const btVector3& toFind) {
182 std::set<tgRigidInfo*> found;
183 std::set<tgRigidInfo*>::iterator it;
184 for(it=rigids.begin(); it != rigids.end(); ++it) {
185 if ((*it)->containsNode(toFind)) {
193 bool tgConnectorInfo::rigidFoundIn(std::set<tgRigidInfo*> rigids,
tgRigidInfo* rigid) {
195 std::set<tgRigidInfo*>::iterator it;
196 for(it = rigids.begin(); it != rigids.end(); ++it) {
Contains the definition of class tgTagSearch.
Definition of abstract class tgRigidInfo.
virtual tgRigidInfo * getRigidInfoGroup()
Definition of class tgPair.
Definition of class tgPairs.
Definition of class tgConnectorInfo.
virtual btRigidBody * getRigidBody()
const bool matches(const tgTags &tags) const
virtual btVector3 getCenterOfMass() const =0