Panda3D
|
00001 // Filename: odeGeom.I 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 //////////////////////////////////////////////////////////////////// 00016 // Function: OdeGeom::is_empty 00017 // Access: Published 00018 // Description: Returns true if the ID is 0, meaning the OdeGeom 00019 // does not point to a valid geom. It is an error to 00020 // call a method on an empty geom. 00021 // Note that an empty OdeGeom also evaluates to False. 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE bool OdeGeom:: 00024 is_empty() const { 00025 return (_id == 0); 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: OdeGeom::get_id 00030 // Access: Published 00031 // Description: Returns the underlying dGeomID. 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE dGeomID OdeGeom:: 00034 get_id() const { 00035 return _id; 00036 } 00037 00038 INLINE bool OdeGeom:: 00039 has_body() const { 00040 return (dGeomGetBody(_id) != NULL); 00041 } 00042 00043 INLINE OdeBody OdeGeom:: 00044 get_body() const { 00045 return OdeBody(dGeomGetBody(_id)); 00046 } 00047 00048 INLINE void OdeGeom:: 00049 set_body(OdeBody &body) { 00050 dGeomSetBody(_id, body.get_id()); 00051 } 00052 00053 /* 00054 INLINE void OdeGeom:: 00055 set_data(void* data) { 00056 dGeomSetData(_id, data); 00057 } 00058 */ 00059 00060 INLINE void OdeGeom:: 00061 set_position(dReal x, dReal y, dReal z) { 00062 dGeomSetPosition(_id, x, y, z); 00063 } 00064 00065 INLINE void OdeGeom:: 00066 set_position(const LVecBase3f &pos) { 00067 set_position(pos[0], pos[1], pos[2]); 00068 } 00069 00070 INLINE void OdeGeom:: 00071 set_rotation(const LMatrix3f &r) { 00072 dMatrix3 rot = { r(0, 0), r(0, 1), r(0, 2), 0, 00073 r(1, 0), r(1, 1), r(1, 2), 0, 00074 r(2, 0), r(2, 1), r(2, 2), 0 }; 00075 dGeomSetRotation(_id, rot); 00076 } 00077 00078 INLINE void OdeGeom:: 00079 set_quaternion(const LQuaternionf &q) { 00080 dQuaternion quat = { q[0], q[1], q[2], q[3] }; 00081 dGeomSetQuaternion(_id, quat); 00082 } 00083 00084 INLINE LPoint3f OdeGeom:: 00085 get_position() const { 00086 const dReal *pos = dGeomGetPosition(_id); 00087 return LPoint3f(pos[0], pos[1], pos[2]); 00088 } 00089 00090 INLINE LMatrix3f OdeGeom:: 00091 get_rotation() const { 00092 const dReal *rot = dGeomGetRotation(_id); 00093 return LMatrix3f(rot[0], rot[1], rot[2], 00094 rot[4], rot[5], rot[6], 00095 rot[8], rot[9], rot[10]); 00096 } 00097 00098 INLINE LQuaternionf OdeGeom:: 00099 get_quaternion() const { 00100 dQuaternion res; 00101 dGeomGetQuaternion(_id, res); 00102 return LQuaternionf(res[0], res[1], res[2], res[3]); 00103 } 00104 00105 INLINE void OdeGeom:: 00106 get_AABB(LVecBase3f &min, LVecBase3f &max) const { 00107 dReal result[6]; 00108 dGeomGetAABB(_id, result); 00109 min.set(result[0], result[2], result[4]); 00110 max.set(result[1], result[3], result[5]); 00111 } 00112 00113 INLINE int OdeGeom:: 00114 is_space() { 00115 return dGeomIsSpace(_id); 00116 } 00117 00118 INLINE int OdeGeom:: 00119 get_class() const { 00120 return dGeomGetClass(_id); 00121 } 00122 00123 INLINE void OdeGeom:: 00124 set_category_bits(const BitMask32 &bits) { 00125 dGeomSetCategoryBits(_id, bits.get_word()); 00126 } 00127 00128 INLINE void OdeGeom:: 00129 set_collide_bits(const BitMask32 &bits) { 00130 dGeomSetCollideBits(_id, bits.get_word()); 00131 } 00132 00133 INLINE BitMask32 OdeGeom:: 00134 get_category_bits() { 00135 return BitMask32(dGeomGetCategoryBits(_id)); 00136 } 00137 00138 INLINE BitMask32 OdeGeom:: 00139 get_collide_bits() { 00140 return BitMask32(dGeomGetCollideBits(_id)); 00141 } 00142 00143 INLINE void OdeGeom:: 00144 enable() { 00145 dGeomEnable(_id); 00146 } 00147 00148 INLINE void OdeGeom:: 00149 disable() { 00150 dGeomDisable(_id); 00151 } 00152 00153 INLINE int OdeGeom:: 00154 is_enabled() { 00155 return dGeomIsEnabled(_id); 00156 } 00157 00158 INLINE void OdeGeom:: 00159 set_offset_position(dReal x, dReal y, dReal z) { 00160 dGeomSetOffsetPosition(_id, x, y, z); 00161 } 00162 00163 INLINE void OdeGeom:: 00164 set_offset_position(const LVecBase3f &pos) { 00165 set_offset_position(pos[0], pos[1], pos[2]); 00166 } 00167 00168 INLINE void OdeGeom:: 00169 set_offset_rotation(const LMatrix3f &r) { 00170 dMatrix3 rot = { r(0, 0), r(0, 1), r(0, 2), 0, 00171 r(1, 0), r(1, 1), r(1, 2), 0, 00172 r(2, 0), r(2, 1), r(2, 2), 0 }; 00173 dGeomSetOffsetRotation(_id, rot); 00174 } 00175 00176 INLINE void OdeGeom:: 00177 set_offset_quaternion(const LQuaternionf &q) { 00178 dQuaternion quat = { q[0], q[1], q[2], q[3] }; 00179 dGeomSetOffsetQuaternion(_id, quat); 00180 } 00181 00182 INLINE void OdeGeom:: 00183 set_offset_world_position(dReal x, dReal y, dReal z) { 00184 dGeomSetOffsetWorldPosition(_id, x, y, z); 00185 } 00186 00187 INLINE void OdeGeom:: 00188 set_offset_world_position(const LVecBase3f &pos) { 00189 set_offset_world_position(pos[0], pos[1], pos[2]); 00190 } 00191 00192 INLINE void OdeGeom:: 00193 set_offset_world_rotation(const LMatrix3f &r) { 00194 dMatrix3 rot = { r(0, 0), r(0, 1), r(0, 2), 0, 00195 r(1, 0), r(1, 1), r(1, 2), 0, 00196 r(2, 0), r(2, 1), r(2, 2), 0 }; 00197 dGeomSetOffsetWorldRotation(_id, rot); 00198 } 00199 00200 INLINE void OdeGeom:: 00201 set_offset_world_quaternion(const LQuaternionf &q) { 00202 dQuaternion quat = { q[0], q[1], q[2], q[3] }; 00203 dGeomSetOffsetWorldQuaternion(_id, quat); 00204 } 00205 00206 INLINE void OdeGeom:: 00207 clear_offset() { 00208 dGeomClearOffset(_id); 00209 } 00210 00211 INLINE int OdeGeom:: 00212 is_offset() { 00213 return dGeomIsOffset(_id); 00214 } 00215 00216 INLINE LPoint3f OdeGeom:: 00217 get_offset_position() const { 00218 const dReal *pos = dGeomGetOffsetPosition(_id); 00219 return LPoint3f(pos[0], pos[1], pos[2]); 00220 } 00221 00222 INLINE LMatrix3f OdeGeom:: 00223 get_offset_rotation() const { 00224 const dReal *rot = dGeomGetOffsetRotation(_id); 00225 return LMatrix3f(rot[0], rot[1], rot[2], 00226 rot[4], rot[5], rot[6], 00227 rot[8], rot[9], rot[10]); 00228 } 00229 00230 INLINE LQuaternionf OdeGeom:: 00231 get_offset_quaternion() const { 00232 dQuaternion res; 00233 dGeomGetOffsetQuaternion(_id, res); 00234 return LQuaternionf(res[0], res[1], res[2], res[3]); 00235 } 00236 00237 INLINE int OdeGeom:: 00238 compare_to(const OdeGeom &other) const { 00239 if (_id != other._id) { 00240 return _id < other._id ? -1 : 1; 00241 } 00242 return 0; 00243 }