Panda3D
|
00001 // Filename: odeGeom.cxx 00002 // Created by: joswilso (27Dec06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "config_ode.h" 00016 #include "odeGeom.h" 00017 00018 //OdeGeom::GeomSurfaceMap OdeGeom::_geom_surface_map; 00019 //OdeGeom::GeomCollideIdMap OdeGeom::_geom_collide_id_map; 00020 TypeHandle OdeGeom::_type_handle; 00021 00022 OdeGeom:: 00023 OdeGeom(dGeomID id) : 00024 _id(id) { 00025 odegeom_cat.debug() << get_type() << "(" << _id << ")\n"; 00026 } 00027 00028 OdeGeom:: 00029 ~OdeGeom() { 00030 odegeom_cat.debug() << "~" << get_type() << "(" << _id << ")\n"; 00031 /* 00032 GeomSurfaceMap::iterator iter = _geom_surface_map.find(this->get_id()); 00033 if (iter != _geom_surface_map.end()) { 00034 _geom_surface_map.erase(iter); 00035 } 00036 00037 GeomCollideIdMap::iterator iter2 = _geom_collide_id_map.find(this->get_id()); 00038 if (iter2 != _geom_collide_id_map.end()) { 00039 _geom_collide_id_map.erase(iter2); 00040 } 00041 */ 00042 } 00043 00044 /* 00045 int OdeGeom:: 00046 get_surface_type() 00047 { 00048 return get_space().get_surface_type(this->get_id()); 00049 } 00050 00051 int OdeGeom:: 00052 get_collide_id() 00053 { 00054 return get_space().get_collide_id(this->get_id()); 00055 } 00056 00057 void OdeGeom:: 00058 set_surface_type(int surface_type) 00059 { 00060 get_space().set_surface_type(surface_type, this->get_id()); 00061 } 00062 00063 int OdeGeom:: 00064 set_collide_id(int collide_id) 00065 { 00066 return get_space().set_collide_id(collide_id, this->get_id()); 00067 } 00068 00069 00070 int OdeGeom:: 00071 test_collide_id(int collide_id) 00072 { 00073 00074 odegeom_cat.debug() << "test_collide_id start" << "\n"; 00075 int first = get_space().set_collide_id(collide_id, this->get_id()); 00076 odegeom_cat.debug() << "returns" << first << "\n"; 00077 odegeom_cat.debug() << "test_collide_id middle" << "\n"; 00078 int test = get_space().get_collide_id(this->get_id()); 00079 odegeom_cat.debug() << "test_collide_id stop" << "\n"; 00080 return test; 00081 } 00082 */ 00083 00084 void OdeGeom:: 00085 destroy() { 00086 if (get_class() == OdeTriMeshGeom::get_geom_class()) { 00087 OdeTriMeshData::unlink_data(_id); 00088 } 00089 dGeomDestroy(_id); 00090 } 00091 00092 OdeSpace OdeGeom:: 00093 get_space() const { 00094 return OdeSpace(dGeomGetSpace(_id)); 00095 } 00096 00097 00098 void OdeGeom:: 00099 write(ostream &out, unsigned int indent) const { 00100 out.width(indent); 00101 out << get_type() << "(id = " << _id << ")"; 00102 } 00103 00104 OdeBoxGeom OdeGeom:: 00105 convert_to_box() const { 00106 nassertr(_id != 0, OdeBoxGeom((dGeomID)0)); 00107 nassertr(get_class() == GC_box, OdeBoxGeom((dGeomID)0)); 00108 return OdeBoxGeom(_id); 00109 } 00110 00111 OdeCappedCylinderGeom OdeGeom:: 00112 convert_to_capped_cylinder() const { 00113 nassertr(_id != 0, OdeCappedCylinderGeom((dGeomID)0)); 00114 nassertr(get_class() == GC_capped_cylinder, OdeCappedCylinderGeom((dGeomID)0)); 00115 return OdeCappedCylinderGeom(_id); 00116 } 00117 00118 /* 00119 OdeConvexGeom OdeGeom:: 00120 convert_to_convex() const { 00121 nassertr(_id != 0, OdeConvexGeom((dGeomID)0)); 00122 nassertr(get_class() == GC_convex, OdeConvexGeom((dGeomID)0)); 00123 return OdeConvexGeom(_id); 00124 } 00125 */ 00126 00127 OdeCylinderGeom OdeGeom:: 00128 convert_to_cylinder() const { 00129 nassertr(_id != 0, OdeCylinderGeom((dGeomID)0)); 00130 nassertr(get_class() == GC_cylinder, OdeCylinderGeom((dGeomID)0)); 00131 return OdeCylinderGeom(_id); 00132 } 00133 00134 /* 00135 OdeHeightfieldGeom OdeGeom:: 00136 convert_to_heightfield() const { 00137 nassertr(_id != 0, OdeHeightfieldGeom((dGeomID)0)); 00138 nassertr(get_class() == GC_heightfield, OdeHeightfieldGeom((dGeomID)0)); 00139 return OdeHeightfieldGeom(_id); 00140 } 00141 */ 00142 00143 OdePlaneGeom OdeGeom:: 00144 convert_to_plane() const { 00145 nassertr(_id != 0, OdePlaneGeom((dGeomID)0)); 00146 nassertr(get_class() == GC_plane, OdePlaneGeom((dGeomID)0)); 00147 return OdePlaneGeom(_id); 00148 } 00149 00150 OdeRayGeom OdeGeom:: 00151 convert_to_ray() const { 00152 nassertr(_id != 0, OdeRayGeom((dGeomID)0)); 00153 nassertr(get_class() == GC_ray, OdeRayGeom((dGeomID)0)); 00154 return OdeRayGeom(_id); 00155 } 00156 00157 OdeSphereGeom OdeGeom:: 00158 convert_to_sphere() const { 00159 nassertr(_id != 0, OdeSphereGeom((dGeomID)0)); 00160 nassertr(get_class() == GC_sphere, OdeSphereGeom((dGeomID)0)); 00161 return OdeSphereGeom(_id); 00162 } 00163 00164 OdeTriMeshGeom OdeGeom:: 00165 convert_to_tri_mesh() const { 00166 nassertr(_id != 0, OdeTriMeshGeom((dGeomID)0)); 00167 nassertr(get_class() == GC_tri_mesh, OdeTriMeshGeom((dGeomID)0)); 00168 return OdeTriMeshGeom(_id); 00169 } 00170 00171 OdeSimpleSpace OdeGeom:: 00172 convert_to_simple_space() const { 00173 nassertr(_id != 0, OdeSimpleSpace((dSpaceID)0)); 00174 nassertr(get_class() == GC_simple_space, OdeSimpleSpace((dSpaceID)0)); 00175 return OdeSimpleSpace((dSpaceID)_id); 00176 } 00177 00178 OdeHashSpace OdeGeom:: 00179 convert_to_hash_space() const { 00180 nassertr(_id != 0, OdeHashSpace((dSpaceID)0)); 00181 nassertr(get_class() == GC_hash_space, OdeHashSpace((dSpaceID)0)); 00182 return OdeHashSpace((dSpaceID)_id); 00183 } 00184 00185 OdeQuadTreeSpace OdeGeom:: 00186 convert_to_quad_tree_space() const { 00187 nassertr(_id != 0, OdeQuadTreeSpace((dSpaceID)0)); 00188 nassertr(get_class() == GC_quad_tree_space, OdeQuadTreeSpace((dSpaceID)0)); 00189 return OdeQuadTreeSpace((dSpaceID)_id); 00190 } 00191 00192 OdeGeom:: 00193 operator bool () const { 00194 return (_id != NULL); 00195 } 00196