Panda3D
 All Classes Functions Variables Enumerations
odeGeom.cxx
1 // Filename: odeGeom.cxx
2 // Created by: joswilso (27Dec06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "config_ode.h"
16 #include "odeGeom.h"
17 #include "odeSimpleSpace.h"
18 #include "odeQuadTreeSpace.h"
19 #include "odeHashSpace.h"
20 
21 #include "odeTriMeshGeom.h"
22 #include "odeTriMeshData.h"
23 #include "odeBoxGeom.h"
24 #include "odeCappedCylinderGeom.h"
25 #include "odeCylinderGeom.h"
26 #include "odePlaneGeom.h"
27 #include "odeRayGeom.h"
28 #include "odeSphereGeom.h"
29 
30 //OdeGeom::GeomSurfaceMap OdeGeom::_geom_surface_map;
31 //OdeGeom::GeomCollideIdMap OdeGeom::_geom_collide_id_map;
32 TypeHandle OdeGeom::_type_handle;
33 
34 OdeGeom::
35 OdeGeom(dGeomID id) :
36  _id(id) {
37  odegeom_cat.debug() << get_type() << "(" << _id << ")\n";
38 }
39 
40 OdeGeom::
41 ~OdeGeom() {
42  odegeom_cat.debug() << "~" << get_type() << "(" << _id << ")\n";
43  /*
44  GeomSurfaceMap::iterator iter = _geom_surface_map.find(this->get_id());
45  if (iter != _geom_surface_map.end()) {
46  _geom_surface_map.erase(iter);
47  }
48 
49  GeomCollideIdMap::iterator iter2 = _geom_collide_id_map.find(this->get_id());
50  if (iter2 != _geom_collide_id_map.end()) {
51  _geom_collide_id_map.erase(iter2);
52  }
53  */
54 }
55 
56 /*
57 int OdeGeom::
58 get_surface_type()
59 {
60  return get_space().get_surface_type(this->get_id());
61 }
62 
63 int OdeGeom::
64 get_collide_id()
65 {
66  return get_space().get_collide_id(this->get_id());
67 }
68 
69 void OdeGeom::
70 set_surface_type(int surface_type)
71 {
72  get_space().set_surface_type(surface_type, this->get_id());
73 }
74 
75 int OdeGeom::
76 set_collide_id(int collide_id)
77 {
78  return get_space().set_collide_id(collide_id, this->get_id());
79 }
80 
81 
82 int OdeGeom::
83 test_collide_id(int collide_id)
84 {
85 
86  odegeom_cat.debug() << "test_collide_id start" << "\n";
87  int first = get_space().set_collide_id(collide_id, this->get_id());
88  odegeom_cat.debug() << "returns" << first << "\n";
89  odegeom_cat.debug() << "test_collide_id middle" << "\n";
90  int test = get_space().get_collide_id(this->get_id());
91  odegeom_cat.debug() << "test_collide_id stop" << "\n";
92  return test;
93 }
94 */
95 
96 void OdeGeom::
97 destroy() {
98  if (get_class() == OdeTriMeshGeom::get_geom_class()) {
99  OdeTriMeshData::unlink_data(_id);
100  }
101  dGeomDestroy(_id);
102 }
103 
104 OdeSpace OdeGeom::
105 get_space() const {
106  return OdeSpace(dGeomGetSpace(_id));
107 }
108 
109 
110 void OdeGeom::
111 write(ostream &out, unsigned int indent) const {
112  out.width(indent);
113  out << get_type() << "(id = " << _id << ")";
114 }
115 
116 OdeBoxGeom OdeGeom::
117 convert_to_box() const {
118  nassertr(_id != 0, OdeBoxGeom((dGeomID)0));
119  nassertr(get_class() == GC_box, OdeBoxGeom((dGeomID)0));
120  return OdeBoxGeom(_id);
121 }
122 
123 OdeCappedCylinderGeom OdeGeom::
124 convert_to_capped_cylinder() const {
125  nassertr(_id != 0, OdeCappedCylinderGeom((dGeomID)0));
126  nassertr(get_class() == GC_capped_cylinder, OdeCappedCylinderGeom((dGeomID)0));
127  return OdeCappedCylinderGeom(_id);
128 }
129 
130 /*
131 OdeConvexGeom OdeGeom::
132 convert_to_convex() const {
133  nassertr(_id != 0, OdeConvexGeom((dGeomID)0));
134  nassertr(get_class() == GC_convex, OdeConvexGeom((dGeomID)0));
135  return OdeConvexGeom(_id);
136 }
137 */
138 
139 OdeCylinderGeom OdeGeom::
140 convert_to_cylinder() const {
141  nassertr(_id != 0, OdeCylinderGeom((dGeomID)0));
142  nassertr(get_class() == GC_cylinder, OdeCylinderGeom((dGeomID)0));
143  return OdeCylinderGeom(_id);
144 }
145 
146 /*
147 OdeHeightfieldGeom OdeGeom::
148 convert_to_heightfield() const {
149  nassertr(_id != 0, OdeHeightfieldGeom((dGeomID)0));
150  nassertr(get_class() == GC_heightfield, OdeHeightfieldGeom((dGeomID)0));
151  return OdeHeightfieldGeom(_id);
152 }
153 */
154 
155 OdePlaneGeom OdeGeom::
156 convert_to_plane() const {
157  nassertr(_id != 0, OdePlaneGeom((dGeomID)0));
158  nassertr(get_class() == GC_plane, OdePlaneGeom((dGeomID)0));
159  return OdePlaneGeom(_id);
160 }
161 
162 OdeRayGeom OdeGeom::
163 convert_to_ray() const {
164  nassertr(_id != 0, OdeRayGeom((dGeomID)0));
165  nassertr(get_class() == GC_ray, OdeRayGeom((dGeomID)0));
166  return OdeRayGeom(_id);
167 }
168 
169 OdeSphereGeom OdeGeom::
170 convert_to_sphere() const {
171  nassertr(_id != 0, OdeSphereGeom((dGeomID)0));
172  nassertr(get_class() == GC_sphere, OdeSphereGeom((dGeomID)0));
173  return OdeSphereGeom(_id);
174 }
175 
176 OdeTriMeshGeom OdeGeom::
177 convert_to_tri_mesh() const {
178  nassertr(_id != 0, OdeTriMeshGeom((dGeomID)0));
179  nassertr(get_class() == GC_tri_mesh, OdeTriMeshGeom((dGeomID)0));
180  return OdeTriMeshGeom(_id);
181 }
182 
183 OdeSimpleSpace OdeGeom::
184 convert_to_simple_space() const {
185  nassertr(_id != 0, OdeSimpleSpace((dSpaceID)0));
186  nassertr(get_class() == GC_simple_space, OdeSimpleSpace((dSpaceID)0));
187  return OdeSimpleSpace((dSpaceID)_id);
188 }
189 
190 OdeHashSpace OdeGeom::
191 convert_to_hash_space() const {
192  nassertr(_id != 0, OdeHashSpace((dSpaceID)0));
193  nassertr(get_class() == GC_hash_space, OdeHashSpace((dSpaceID)0));
194  return OdeHashSpace((dSpaceID)_id);
195 }
196 
197 OdeQuadTreeSpace OdeGeom::
198 convert_to_quad_tree_space() const {
199  nassertr(_id != 0, OdeQuadTreeSpace((dSpaceID)0));
200  nassertr(get_class() == GC_quad_tree_space, OdeQuadTreeSpace((dSpaceID)0));
201  return OdeQuadTreeSpace((dSpaceID)_id);
202 }
203 
204 OdeGeom::
205 operator bool () const {
206  return (_id != NULL);
207 }
208 
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85