NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgRigidInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
25 // This module
26 #include "tgRigidInfo.h"
27 // This application
28 #include "tgNode.h"
29 #include "tgNodes.h"
30 #include "tgPair.h"
31 #include "tgPairs.h"
32 // The NTRT Core Libary
33 #include "core/tgBulletUtil.h"
34 #include "core/tgTagSearch.h"
35 #include "tgUtil.h"
36 #include "core/tgWorld.h"
37 
38 tgRigidInfo* tgRigidInfo::createRigidInfo(const tgNode& node, const tgTagSearch& tagSearch)
39 {
40  // Our subclasses may not be able to create rigidInfos based on nodes. Also, the
41  // tags may not match our search. Make sure both work, or return 0.
42  tgRigidInfo* rigidInfo = 0;
43  if(tagSearch.matches(node.getTags())) {
44  rigidInfo = createRigidInfo(node);
45  }
46  return rigidInfo;
47 }
48 
49 std::vector<tgRigidInfo*> tgRigidInfo::createRigidInfos(const tgNodes& nodes, const tgTagSearch& tagSearch)
50 {
51  std::vector<tgRigidInfo*> result;
52  for(int i = 0; i < nodes.size(); i++) {
53  tgRigidInfo* r = createRigidInfo(nodes[i], tagSearch);
54  if(r != 0) {
55  r->addTags(nodes[i].getTags());
56  result.push_back(r);
57  }
58  }
59  return result;
60 }
61 
62 tgRigidInfo* tgRigidInfo::createRigidInfo(const tgPair& pair, const tgTagSearch& tagSearch)
63 {
64  // Our subclasses may not be able to create rigidInfos based on nodes. Also, the
65  // tags may not match our search. Make sure both work, or return 0.
66  tgRigidInfo* rigidInfo = 0;
67  if(tagSearch.matches(pair.getTags())) {
68  rigidInfo = createRigidInfo(pair);
69  }
70  return rigidInfo;
71 }
72 
73 std::vector<tgRigidInfo*> tgRigidInfo::createRigidInfos(const tgPairs& pairs, const tgTagSearch& tagSearch)
74 {
75  std::vector<tgRigidInfo*> result;
76  for(int i = 0; i < pairs.size(); i++) {
77  tgRigidInfo* r = createRigidInfo(pairs[i], tagSearch);
78  if(r != 0) {
79  result.push_back(r);
80  }
81  }
82  return result;
83 }
84 
85 
86 
87 void tgRigidInfo::initRigidBody(tgWorld& world)
88  {
89  if(!getRigidBody()) {
90 
91  // we want to do this based on group instead the rigid itself; otherwise we throw away autocompounding.
92  tgRigidInfo* rigid = getRigidInfoGroup();
93 
94  // If we're not using autocompounding, use the rigid body itself.
95  // NOTE: This means that auto-compounding can be silently skipped, which means that your parts may not be joined correctly. Do we want that?
96  if(rigid == 0) {
97  rigid = this;
98  }
99 
100  if (rigid->getRigidBody() == NULL) { // Init only if it doesn't have a btRigidBody (has already been initialized)
101 
102  double mass = rigid->getMass();
103  btTransform transform = rigid->getTransform();
104  btCollisionShape* shape = rigid->getCollisionShape(world);
105 
106  btRigidBody* body =
107  tgBulletUtil::createRigidBody(&tgBulletUtil::worldToDynamicsWorld(world),
108  mass,
109  transform,
110  shape);
111 
112  rigid->setRigidBody(body);
113  }
114  }
115  }
Contains the definition of class tgTagSearch $Id$.
Definition of abstract class tgRigidInfo.
virtual tgRigidInfo * getRigidInfoGroup()
Definition: tgRigidInfo.h:151
static btSoftRigidDynamicsWorld & worldToDynamicsWorld(tgWorld &world)
virtual btCollisionShape * getCollisionShape(tgWorld &world) const =0
Definition of class tgPair.
virtual btRigidBody * getRigidBody()
Definition: tgRigidInfo.h:174
Definition of class tgPairs.
Definition of class tgNodes.
virtual void setRigidBody(btRigidBody *rigidBody)
Definition: tgRigidInfo.h:191
Definition of class tgNode.
const bool matches(const tgTags &tags) const
Definition: tgTagSearch.h:61
Definition: tgPair.h:47
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBulletUtil.
Definition: tgNode.h:43
virtual double getMass() const =0
virtual btTransform getTransform() const =0
Contains the definition of class tgUtil and overloaded operator<<() free functions.