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