Isis 3 Programmer Reference
BulletWorldManager.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #include "BulletWorldManager.h"
9 
10 #include <iostream>
11 #include <iomanip>
12 #include <numeric>
13 #include <sstream>
14 
15 #include <QMutexLocker>
16 
17 #include "FileName.h"
18 #include "IException.h"
19 #include "IString.h"
20 
21 using namespace std;
22 
23 namespace Isis {
24 
28  BulletWorldManager::BulletWorldManager() {
29  m_name = "Body-Fixed-Coordinate-System";
30  initWorld();
31  }
32 
33 
39  BulletWorldManager::BulletWorldManager(const QString &name) {
40  m_name = name;
41  initWorld();
42  }
43 
44 
48  BulletWorldManager::~BulletWorldManager() { }
49 
50 
56  QString BulletWorldManager::name() const {
57  return ( m_name );
58  }
59 
60 
66  int BulletWorldManager::size() const{
67  return ( m_world->getCollisionObjectArray().size() );
68  }
69 
70 
78  BulletTargetShape *BulletWorldManager::getTarget(const int &index) const {
79  btAssert( index < size() );
80  btAssert( index >= 0 );
81  return ( (BulletTargetShape *) (m_world->getCollisionObjectArray().at(index)->getUserPointer()) );
82  }
83 
84 
92  BulletTargetShape *BulletWorldManager::getTarget(const QString &name) const {
93 
94  QString v_name = name.toLower();
95  const btCollisionObjectArray &btobjects = m_world->getCollisionObjectArray();
96  for ( int i = 0 ; i < btobjects.size() ; i++ ) {
97  BulletTargetShape *target = (BulletTargetShape *) (btobjects[i]->getUserPointer());
98  if ( target->name().toLower() == v_name ) {
99  return (target);
100  }
101  }
102 
103  // Not found...
104  return (0);
105  }
106 
107 
113  void BulletWorldManager::addTarget(BulletTargetShape *target) {
114 
115  // May need to retain the target in a list for world destruction!!??
116  // CollisionBody is expected to contain a UserPointer that links back to
117  // target (BulletTargetShape or some other type).
118  m_world->addCollisionObject( target->body() );
119 
120  }
121 
122 
139  bool BulletWorldManager::raycast(const btVector3 &rayStart, const btVector3 &rayEnd,
140  btCollisionWorld::RayResultCallback &results ) const {
141  m_world->rayTest(rayStart, rayEnd, results);
142  return ( results.hasHit() );
143  }
144 
145 
151  const btCollisionWorld &BulletWorldManager::getWorld() const {
152  return ( *m_world );
153  }
154 
155 
161  void BulletWorldManager::initWorld() {
162  m_collision.reset( new btDefaultCollisionConfiguration() );
163  m_dispatcher.reset(new btCollisionDispatcher(m_collision.data()) );
164  m_broadphase.reset( new btDbvtBroadphase() ); // Could also be an AxisSweep
165  m_world.reset( new btCollisionWorld( m_dispatcher.data(), m_broadphase.data(), m_collision.data() ) );
166 
167  }
168 
169 } // namespace Isis
Isis::BulletTargetShape::name
QString name() const
Return name of the target shape.
Definition: BulletTargetShape.cpp:71
std
Namespace for the standard library.
Isis::BulletTargetShape
Bullet Target Shape for planetary bodies.
Definition: BulletTargetShape.h:33
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::BulletTargetShape::body
btCollisionObject * body() const
Return a pointer to the Bullet target object/shape.
Definition: BulletTargetShape.cpp:150