Panda3D
odeGeom.I
1 // Filename: odeGeom.I
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 ////////////////////////////////////////////////////////////////////
16 // Function: OdeGeom::is_empty
17 // Access: Published
18 // Description: Returns true if the ID is 0, meaning the OdeGeom
19 // does not point to a valid geom. It is an error to
20 // call a method on an empty geom.
21 // Note that an empty OdeGeom also evaluates to False.
22 ////////////////////////////////////////////////////////////////////
23 INLINE bool OdeGeom::
24 is_empty() const {
25  return (_id == 0);
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: OdeGeom::get_id
30 // Access: Published
31 // Description: Returns the underlying dGeomID.
32 ////////////////////////////////////////////////////////////////////
33 INLINE dGeomID OdeGeom::
34 get_id() const {
35  return _id;
36 }
37 
38 INLINE bool OdeGeom::
39 has_body() const {
40  return (dGeomGetBody(_id) != NULL);
41 }
42 
43 INLINE OdeBody OdeGeom::
44 get_body() const {
45  return OdeBody(dGeomGetBody(_id));
46 }
47 
48 INLINE void OdeGeom::
49 set_body(OdeBody &body) {
50  dGeomSetBody(_id, body.get_id());
51 }
52 
53 /*
54 INLINE void OdeGeom::
55 set_data(void* data) {
56  dGeomSetData(_id, data);
57 }
58 */
59 
60 INLINE void OdeGeom::
61 set_position(dReal x, dReal y, dReal z) {
62  dGeomSetPosition(_id, x, y, z);
63 }
64 
65 INLINE void OdeGeom::
66 set_position(const LVecBase3f &pos) {
67  set_position(pos[0], pos[1], pos[2]);
68 }
69 
70 INLINE void OdeGeom::
71 set_rotation(const LMatrix3f &r) {
72  dMatrix3 rot = { r(0, 0), r(0, 1), r(0, 2), 0,
73  r(1, 0), r(1, 1), r(1, 2), 0,
74  r(2, 0), r(2, 1), r(2, 2), 0 };
75  dGeomSetRotation(_id, rot);
76 }
77 
78 INLINE void OdeGeom::
79 set_quaternion(const LQuaternionf &q) {
80  dQuaternion quat = { q[0], q[1], q[2], q[3] };
81  dGeomSetQuaternion(_id, quat);
82 }
83 
84 INLINE LPoint3f OdeGeom::
85 get_position() const {
86  const dReal *pos = dGeomGetPosition(_id);
87  return LPoint3f(pos[0], pos[1], pos[2]);
88 }
89 
90 INLINE LMatrix3f OdeGeom::
91 get_rotation() const {
92  const dReal *rot = dGeomGetRotation(_id);
93  return LMatrix3f(rot[0], rot[1], rot[2],
94  rot[4], rot[5], rot[6],
95  rot[8], rot[9], rot[10]);
96 }
97 
98 INLINE LQuaternionf OdeGeom::
99 get_quaternion() const {
100  dQuaternion res;
101  dGeomGetQuaternion(_id, res);
102  return LQuaternionf(res[0], res[1], res[2], res[3]);
103 }
104 
105 INLINE void OdeGeom::
106 get_AABB(LVecBase3f &min, LVecBase3f &max) const {
107  dReal result[6];
108  dGeomGetAABB(_id, result);
109  min.set(result[0], result[2], result[4]);
110  max.set(result[1], result[3], result[5]);
111 }
112 
113 INLINE int OdeGeom::
114 is_space() {
115  return dGeomIsSpace(_id);
116 }
117 
118 INLINE int OdeGeom::
119 get_class() const {
120  return dGeomGetClass(_id);
121 }
122 
123 INLINE void OdeGeom::
124 set_category_bits(const BitMask32 &bits) {
125  dGeomSetCategoryBits(_id, bits.get_word());
126 }
127 
128 INLINE void OdeGeom::
129 set_collide_bits(const BitMask32 &bits) {
130  dGeomSetCollideBits(_id, bits.get_word());
131 }
132 
133 INLINE BitMask32 OdeGeom::
134 get_category_bits() {
135  return BitMask32(dGeomGetCategoryBits(_id));
136 }
137 
138 INLINE BitMask32 OdeGeom::
139 get_collide_bits() {
140  return BitMask32(dGeomGetCollideBits(_id));
141 }
142 
143 INLINE void OdeGeom::
144 enable() {
145  dGeomEnable(_id);
146 }
147 
148 INLINE void OdeGeom::
149 disable() {
150  dGeomDisable(_id);
151 }
152 
153 INLINE int OdeGeom::
154 is_enabled() {
155  return dGeomIsEnabled(_id);
156 }
157 
158 INLINE void OdeGeom::
159 set_offset_position(dReal x, dReal y, dReal z) {
160  dGeomSetOffsetPosition(_id, x, y, z);
161 }
162 
163 INLINE void OdeGeom::
164 set_offset_position(const LVecBase3f &pos) {
165  set_offset_position(pos[0], pos[1], pos[2]);
166 }
167 
168 INLINE void OdeGeom::
169 set_offset_rotation(const LMatrix3f &r) {
170  dMatrix3 rot = { r(0, 0), r(0, 1), r(0, 2), 0,
171  r(1, 0), r(1, 1), r(1, 2), 0,
172  r(2, 0), r(2, 1), r(2, 2), 0 };
173  dGeomSetOffsetRotation(_id, rot);
174 }
175 
176 INLINE void OdeGeom::
177 set_offset_quaternion(const LQuaternionf &q) {
178  dQuaternion quat = { q[0], q[1], q[2], q[3] };
179  dGeomSetOffsetQuaternion(_id, quat);
180 }
181 
182 INLINE void OdeGeom::
183 set_offset_world_position(dReal x, dReal y, dReal z) {
184  dGeomSetOffsetWorldPosition(_id, x, y, z);
185 }
186 
187 INLINE void OdeGeom::
188 set_offset_world_position(const LVecBase3f &pos) {
189  set_offset_world_position(pos[0], pos[1], pos[2]);
190 }
191 
192 INLINE void OdeGeom::
193 set_offset_world_rotation(const LMatrix3f &r) {
194  dMatrix3 rot = { r(0, 0), r(0, 1), r(0, 2), 0,
195  r(1, 0), r(1, 1), r(1, 2), 0,
196  r(2, 0), r(2, 1), r(2, 2), 0 };
197  dGeomSetOffsetWorldRotation(_id, rot);
198 }
199 
200 INLINE void OdeGeom::
201 set_offset_world_quaternion(const LQuaternionf &q) {
202  dQuaternion quat = { q[0], q[1], q[2], q[3] };
203  dGeomSetOffsetWorldQuaternion(_id, quat);
204 }
205 
206 INLINE void OdeGeom::
207 clear_offset() {
208  dGeomClearOffset(_id);
209 }
210 
211 INLINE int OdeGeom::
212 is_offset() {
213  return dGeomIsOffset(_id);
214 }
215 
216 INLINE LPoint3f OdeGeom::
217 get_offset_position() const {
218  const dReal *pos = dGeomGetOffsetPosition(_id);
219  return LPoint3f(pos[0], pos[1], pos[2]);
220 }
221 
222 INLINE LMatrix3f OdeGeom::
223 get_offset_rotation() const {
224  const dReal *rot = dGeomGetOffsetRotation(_id);
225  return LMatrix3f(rot[0], rot[1], rot[2],
226  rot[4], rot[5], rot[6],
227  rot[8], rot[9], rot[10]);
228 }
229 
230 INLINE LQuaternionf OdeGeom::
231 get_offset_quaternion() const {
232  dQuaternion res;
233  dGeomGetOffsetQuaternion(_id, res);
234  return LQuaternionf(res[0], res[1], res[2], res[3]);
235 }
236 
237 INLINE int OdeGeom::
238 compare_to(const OdeGeom &other) const {
239  if (_id != other._id) {
240  return _id < other._id ? -1 : 1;
241  }
242  return 0;
243 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
bool is_empty() const
Returns true if the ID is 0, meaning the OdeGeom does not point to a valid geom.
Definition: odeGeom.I:24
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
dGeomID get_id() const
Returns the underlying dGeomID.
Definition: odeGeom.I:34
WordType get_word() const
Returns the entire BitMask as a single word.
Definition: bitMask.I:383
dBodyID get_id() const
Returns the underlying dBodyID.
Definition: odeBody.I:34
This is the base quaternion class.
Definition: lquaternion.h:96
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110