ARGoS 3
A parallel, multi-engine simulator for swarm robotics
dynamics3d_shape_manager.cpp
Go to the documentation of this file.
1
9#include <argos3/core/utility/configuration/argos_exception.h>
10
11namespace argos {
12
13 /****************************************/
14 /****************************************/
15
16 std::vector<CDynamics3DShapeManager::SBoxResource>
17 CDynamics3DShapeManager::m_vecBoxResources;
18
19 /****************************************/
20 /****************************************/
21
22 std::shared_ptr<btCollisionShape> CDynamics3DShapeManager::RequestBox(const btVector3& c_half_extents) {
23 std::vector<SBoxResource>::iterator itBoxResource;
24 for(itBoxResource = std::begin(m_vecBoxResources);
25 itBoxResource != std::end(m_vecBoxResources);
26 ++itBoxResource) {
27 if(itBoxResource->HalfExtents == c_half_extents) break;
28 }
29 /* If the resource doesn't exist, create a new one */
30 if(itBoxResource == std::end(m_vecBoxResources)) {
31 itBoxResource =
32 m_vecBoxResources.emplace(itBoxResource, c_half_extents);
33 }
34 return std::static_pointer_cast<btCollisionShape>(itBoxResource->Shape);
35 }
36
37 /****************************************/
38 /****************************************/
39
40 CDynamics3DShapeManager::SBoxResource::SBoxResource(const btVector3& c_half_extents) :
41 HalfExtents(c_half_extents),
42 Shape(new btBoxShape(c_half_extents)) {}
43
44 /****************************************/
45 /****************************************/
46
47 std::vector<CDynamics3DShapeManager::SCylinderResource>
48 CDynamics3DShapeManager::m_vecCylinderResources;
49
50 /****************************************/
51 /****************************************/
52
53 std::shared_ptr<btCollisionShape> CDynamics3DShapeManager::RequestCylinder(const btVector3& c_half_extents) {
54 std::vector<SCylinderResource>::iterator itCylinderResource;
55 for(itCylinderResource = std::begin(m_vecCylinderResources);
56 itCylinderResource != std::end(m_vecCylinderResources);
57 ++itCylinderResource) {
58 if(itCylinderResource->HalfExtents == c_half_extents) break;
59 }
60 /* If the resource doesn't exist, create a new one */
61 if(itCylinderResource == std::end(m_vecCylinderResources)) {
62 itCylinderResource =
63 m_vecCylinderResources.emplace(itCylinderResource, c_half_extents);
64 }
65 return std::static_pointer_cast<btCollisionShape>(itCylinderResource->Shape);
66 }
67
68 /****************************************/
69 /****************************************/
70
71 CDynamics3DShapeManager::SCylinderResource::SCylinderResource(const btVector3& c_half_extents) :
72 HalfExtents(c_half_extents),
73 Shape(new btCylinderShape(c_half_extents)) {}
74
75 /****************************************/
76 /****************************************/
77
78 std::vector<CDynamics3DShapeManager::SSphereResource>
79 CDynamics3DShapeManager::m_vecSphereResources;
80
81 /****************************************/
82 /****************************************/
83
84 std::shared_ptr<btCollisionShape> CDynamics3DShapeManager::RequestSphere(btScalar f_radius) {
85 std::vector<SSphereResource>::iterator itSphereResource;
86 for(itSphereResource = std::begin(m_vecSphereResources);
87 itSphereResource != std::end(m_vecSphereResources);
88 ++itSphereResource) {
89 if(itSphereResource->Radius == f_radius) break;
90 }
91 /* If the resource doesn't exist, create a new one */
92 if(itSphereResource == std::end(m_vecSphereResources)) {
93 itSphereResource =
94 m_vecSphereResources.emplace(itSphereResource, f_radius);
95 }
96 return std::static_pointer_cast<btCollisionShape>(itSphereResource->Shape);
97 }
98
99 /****************************************/
100 /****************************************/
101
102 CDynamics3DShapeManager::SSphereResource::SSphereResource(btScalar f_radius) :
103 Radius(f_radius),
104 Shape(new btSphereShape(f_radius)) {}
105
106 /****************************************/
107 /****************************************/
108
109 std::vector<CDynamics3DShapeManager::SConvexHullResource>
110 CDynamics3DShapeManager::m_vecConvexHullResources;
111
112 /****************************************/
113 /****************************************/
114
115 std::shared_ptr<btCollisionShape> CDynamics3DShapeManager::RequestConvexHull(const std::vector<btVector3>& vec_points) {
116 std::vector<SConvexHullResource>::iterator itConvexHullResource;
117 for(itConvexHullResource = std::begin(m_vecConvexHullResources);
118 itConvexHullResource != std::end(m_vecConvexHullResources);
119 ++itConvexHullResource) {
120 if(itConvexHullResource->Points == vec_points) break;
121 }
122 /* If the resource doesn't exist, create a new one */
123 if(itConvexHullResource == std::end(m_vecConvexHullResources)) {
124 itConvexHullResource =
125 m_vecConvexHullResources.emplace(itConvexHullResource, vec_points);
126 }
127 return std::static_pointer_cast<btCollisionShape>(itConvexHullResource->Shape);
128 }
129
130 /****************************************/
131 /****************************************/
132
133 CDynamics3DShapeManager::SConvexHullResource::SConvexHullResource(const std::vector<btVector3>& vec_points) :
134 Points(vec_points),
135 Shape(new btConvexHullShape) {
136 Shape->setMargin(0);
137 for(const btVector3& c_point : vec_points) {
138 Shape->addPoint(c_point);
139 }
140 }
141
142 /****************************************/
143 /****************************************/
144}
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
static std::shared_ptr< btCollisionShape > RequestBox(const btVector3 &c_half_extents)
static std::shared_ptr< btCollisionShape > RequestSphere(btScalar f_radius)
static std::shared_ptr< btCollisionShape > RequestConvexHull(const std::vector< btVector3 > &vec_points)
static std::shared_ptr< btCollisionShape > RequestCylinder(const btVector3 &c_half_extents)