NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgGhostInfo.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 
26 // This module
27 #include "tgGhostInfo.h"
28 // This application
29 #include "tgGhostModel.h"
30 #include "tgcreator/tgNode.h"
31 #include "tgcreator/tgNodes.h"
32 #include "tgcreator/tgPair.h"
33 #include "tgcreator/tgPairs.h"
34 // The NTRT Core Libary
35 #include "core/tgBulletUtil.h"
36 #include "core/tgTagSearch.h"
37 #include "tgcreator/tgUtil.h"
38 #include "core/tgBulletUtil.h"
39 #include "core/tgWorld.h"
40 
41 
42 // The Bullet Physics library
43 #include "btBulletDynamicsCommon.h"
44 #include "BulletCollision/CollisionDispatch/btGhostObject.h"
45 #include "BulletDynamics/Dynamics/btDynamicsWorld.h"
46 
48  tgBoxInfo(config)
49 {}
50 
52  tgBoxInfo(config, tags)
53 {}
54 
55 tgGhostInfo::tgGhostInfo(const tgBox::Config& config, const tgPair& pair) :
56  tgBoxInfo(config, pair)
57 {}
58 
59 tgGhostInfo::tgGhostInfo(const tgBox::Config& config, tgTags tags, const tgPair& pair) :
60  tgBoxInfo(config, tags, pair)
61 {}
62 
64 {
65  return new tgGhostInfo(getConfig(), pair);
66 }
67 
68 
71 {
72  if(!getCollisionObject()) {
73 
74  // we want to do this based on group instead the rigid itself; otherwise we throw away autocompounding.
75  tgRigidInfo* rigid = getRigidInfoGroup();
76 
77  // If we're not using autocompounding, use the rigid body itself.
78  // NOTE: This means that auto-compounding can be silently skipped, which means that your parts may not be joined correctly. Do we want that?
79  if(rigid == 0) {
80  rigid = this;
81  }
82 
83  if (rigid->getCollisionObject() == NULL) // Init only if it doesn't have a btRigidBody (has already been initialized)
84  {
85 
86  btDynamicsWorld& m_dynamicsWorld = tgBulletUtil::worldToDynamicsWorld(world);
87 
88  btTransform transform = rigid->getTransform();
89  btCollisionShape* shape = rigid->getCollisionShape(world);
90 
91  // Dynamics world will own this
92  btPairCachingGhostObject* ghostObject = new btPairCachingGhostObject();
93 
94  ghostObject->setCollisionShape (shape);
95  ghostObject->setWorldTransform(transform);
96  ghostObject->setCollisionFlags (btCollisionObject::CF_NO_CONTACT_RESPONSE);
97 
98  // @todo look up what the second and third arguments of this are
99  m_dynamicsWorld.addCollisionObject(ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
100 
101  rigid->setCollisionObject(ghostObject);
102  }
103 
104  }
105 }
106 
107 tgModel* tgGhostInfo::createModel(tgWorld& world)
108 {
109  // @todo: handle tags -> model
110  // @todo: check to make sure the rigidBody has been built
111  // @todo: Do we need to use the group here?
112 
113  // Just in case it hasn't been done already...
114  initRigidBody(world);
115 
116  #if (0)
117  std::cout << "creating box with tags " << getTags() << std::endl;
118  #endif
119 
120  btPairCachingGhostObject* ghostObject = tgCast::cast<btCollisionObject, btPairCachingGhostObject> (getCollisionObject());
121 
122  tgGhostModel* slimer = new tgGhostModel(ghostObject, getTags());
123 
124  return slimer;
125 }
Contains the definition of class tgTagSearch.
Like tgBaseRigid, but uses btPairCachingGhostObject instead.
virtual tgRigidInfo * getRigidInfoGroup()
Definition: tgRigidInfo.h:149
static btDynamicsWorld & worldToDynamicsWorld(const tgWorld &world)
virtual btCollisionShape * getCollisionShape(tgWorld &world) const =0
Definition of class tgPair.
tgGhostInfo(const tgBox::Config &config)
Definition: tgGhostInfo.cpp:47
Definition of class tgPairs.
const tgBox::Config & getConfig() const
Definition: tgBoxInfo.h:107
Definition of class tgNodes.
Definition of class tgNode.
virtual void setCollisionObject(btCollisionObject *collisionObject)
Definition: tgRigidInfo.h:208
Definition: tgPair.h:48
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBulletUtil.
tgRigidInfo * createRigidInfo(const tgPair &pair)
Definition: tgGhostInfo.cpp:63
virtual void initRigidBody(tgWorld &world)
Definition: tgGhostInfo.cpp:70
virtual btTransform getTransform() const =0
virtual btCollisionObject * getCollisionObject()
Definition: tgRigidInfo.h:190
Rand seeding simular to the evolution and terrain classes.
Definition of abstract class tgGhostInfo.
Definition: tgTags.h:44