Isis 3 Programmer Reference
BulletWorldManager.cpp
Go to the documentation of this file.
1 
25 #include "BulletWorldManager.h"
26 
27 #include <iostream>
28 #include <iomanip>
29 #include <numeric>
30 #include <sstream>
31 
32 #include <QMutexLocker>
33 
34 #include "FileName.h"
35 #include "IException.h"
36 #include "IString.h"
37 
38 using namespace std;
39 
40 namespace Isis {
41 
45  BulletWorldManager::BulletWorldManager() {
46  m_name = "Body-Fixed-Coordinate-System";
47  initWorld();
48  }
49 
50 
56  BulletWorldManager::BulletWorldManager(const QString &name) {
57  m_name = name;
58  initWorld();
59  }
60 
61 
65  BulletWorldManager::~BulletWorldManager() { }
66 
67 
73  QString BulletWorldManager::name() const {
74  return ( m_name );
75  }
76 
77 
83  int BulletWorldManager::size() const{
84  return ( m_world->getCollisionObjectArray().size() );
85  }
86 
87 
95  BulletTargetShape *BulletWorldManager::getTarget(const int &index) const {
96  btAssert( index < size() );
97  btAssert( index >= 0 );
98  return ( (BulletTargetShape *) (m_world->getCollisionObjectArray().at(index)->getUserPointer()) );
99  }
100 
101 
109  BulletTargetShape *BulletWorldManager::getTarget(const QString &name) const {
110 
111  QString v_name = name.toLower();
112  const btCollisionObjectArray &btobjects = m_world->getCollisionObjectArray();
113  for ( int i = 0 ; i < btobjects.size() ; i++ ) {
114  BulletTargetShape *target = (BulletTargetShape *) (btobjects[i]->getUserPointer());
115  if ( target->name().toLower() == v_name ) {
116  return (target);
117  }
118  }
119 
120  // Not found...
121  return (0);
122  }
123 
124 
130  void BulletWorldManager::addTarget(BulletTargetShape *target) {
131 
132  // May need to retain the target in a list for world destruction!!??
133  // CollisionBody is expected to contain a UserPointer that links back to
134  // target (BulletTargetShape or some other type).
135  m_world->addCollisionObject( target->body() );
136 
137  }
138 
139 
156  bool BulletWorldManager::raycast(const btVector3 &rayStart, const btVector3 &rayEnd,
157  btCollisionWorld::RayResultCallback &results ) const {
158  m_world->rayTest(rayStart, rayEnd, results);
159  return ( results.hasHit() );
160  }
161 
162 
168  const btCollisionWorld &BulletWorldManager::getWorld() const {
169  return ( *m_world );
170  }
171 
172 
178  void BulletWorldManager::initWorld() {
179  m_collision.reset( new btDefaultCollisionConfiguration() );
180  m_dispatcher.reset(new btCollisionDispatcher(m_collision.data()) );
181  m_broadphase.reset( new btDbvtBroadphase() ); // Could also be an AxisSweep
182  m_world.reset( new btCollisionWorld( m_dispatcher.data(), m_broadphase.data(), m_collision.data() ) );
183 
184  }
185 
186 } // namespace Isis
btCollisionObject * body() const
Return a pointer to the Bullet target object/shape.
Namespace for the standard library.
QString name() const
Return name of the target shape.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Bullet Target Shape for planetary bodies.