1 | |
---|
2 | #include "OgreOdePrecompiledHeaders.h" |
---|
3 | |
---|
4 | #include "OgreOdeGeometry.h" |
---|
5 | #include "OgreOdeWorld.h" |
---|
6 | #include "OgreOdeBody.h" |
---|
7 | #include "OgreOdeGeometry.h" |
---|
8 | #include "OgreOdeJoint.h" |
---|
9 | |
---|
10 | using namespace OgreOde; |
---|
11 | using namespace Ogre; |
---|
12 | |
---|
13 | //------------------------------------------------------------------------------------------------ |
---|
14 | JointGroup::JointGroup(World *world): |
---|
15 | _world(world) |
---|
16 | { |
---|
17 | _joint_group = dJointGroupCreate(0); |
---|
18 | _world->getJointGroupList().registerItem(this); |
---|
19 | } |
---|
20 | //------------------------------------------------------------------------------------------------ |
---|
21 | dJointGroupID JointGroup::getJointGroupID() const |
---|
22 | { |
---|
23 | return _joint_group; |
---|
24 | } |
---|
25 | |
---|
26 | unsigned long JointGroup::getID() |
---|
27 | { |
---|
28 | return (long unsigned long)_joint_group; |
---|
29 | } |
---|
30 | |
---|
31 | void JointGroup::empty() |
---|
32 | { |
---|
33 | dJointGroupEmpty(_joint_group); |
---|
34 | } |
---|
35 | |
---|
36 | JointGroup::~JointGroup() |
---|
37 | { |
---|
38 | _world->getJointGroupList().unregisterItem((long unsigned int)_joint_group); |
---|
39 | dJointGroupDestroy(_joint_group); |
---|
40 | } |
---|
41 | |
---|
42 | Joint::Joint(World *world, const JointGroup* group): |
---|
43 | _world(world) |
---|
44 | { |
---|
45 | } |
---|
46 | |
---|
47 | void Joint::registerJoint() |
---|
48 | { |
---|
49 | _world->getJointList().registerItem(this); |
---|
50 | } |
---|
51 | |
---|
52 | void Joint::setAnchor(const Ogre::Vector3& position) |
---|
53 | { |
---|
54 | } |
---|
55 | |
---|
56 | void Joint::addTorque(Real torque,Real torque2,Real torque3) |
---|
57 | { |
---|
58 | } |
---|
59 | |
---|
60 | void Joint::addForce(Real force,Real force2,Real force3) |
---|
61 | { |
---|
62 | } |
---|
63 | |
---|
64 | const Ogre::Vector3& Joint::getAnchor() |
---|
65 | { |
---|
66 | return Ogre::Vector3::ZERO; |
---|
67 | } |
---|
68 | |
---|
69 | const Ogre::Vector3& Joint::getAnchorError() |
---|
70 | { |
---|
71 | return Ogre::Vector3::ZERO; |
---|
72 | } |
---|
73 | |
---|
74 | void Joint::setAxis(const Ogre::Vector3& axis) |
---|
75 | { |
---|
76 | } |
---|
77 | |
---|
78 | const Ogre::Vector3& Joint::getAxis() |
---|
79 | { |
---|
80 | return Ogre::Vector3::ZERO; |
---|
81 | } |
---|
82 | |
---|
83 | void Joint::setAdditionalAxis(const Ogre::Vector3& axis) |
---|
84 | { |
---|
85 | } |
---|
86 | |
---|
87 | const Ogre::Vector3& Joint::getAdditionalAxis() |
---|
88 | { |
---|
89 | return Ogre::Vector3::ZERO; |
---|
90 | } |
---|
91 | |
---|
92 | Real Joint::getAngle() |
---|
93 | { |
---|
94 | return 0.0; |
---|
95 | } |
---|
96 | |
---|
97 | Real Joint::getAngleRate() |
---|
98 | { |
---|
99 | return 0.0; |
---|
100 | } |
---|
101 | |
---|
102 | Real Joint::getPosition() |
---|
103 | { |
---|
104 | return 0.0; |
---|
105 | } |
---|
106 | |
---|
107 | Real Joint::getPositionRate() |
---|
108 | { |
---|
109 | return 0.0; |
---|
110 | } |
---|
111 | |
---|
112 | unsigned long Joint::getID() |
---|
113 | { |
---|
114 | return (unsigned long)_joint; |
---|
115 | } |
---|
116 | |
---|
117 | Joint::~Joint() |
---|
118 | { |
---|
119 | _world->getJointList().unregisterItem((unsigned long)_joint); |
---|
120 | dJointDestroy(_joint); |
---|
121 | } |
---|
122 | |
---|
123 | dWorldID Joint::getWorldID() |
---|
124 | { |
---|
125 | return _world->getWorldID(); |
---|
126 | } |
---|
127 | |
---|
128 | dJointGroupID Joint::getJointGroupID(const JointGroup* group) const |
---|
129 | { |
---|
130 | return ((group)?group->getJointGroupID():0); |
---|
131 | } |
---|
132 | |
---|
133 | dJointID Joint::getJointID() |
---|
134 | { |
---|
135 | return _joint; |
---|
136 | } |
---|
137 | |
---|
138 | Joint::Type Joint::getType() |
---|
139 | { |
---|
140 | return (Joint::Type)(dJointGetType(_joint)); |
---|
141 | } |
---|
142 | |
---|
143 | Body* Joint::getFirstBody() |
---|
144 | { |
---|
145 | dBodyID b = dJointGetBody(_joint, 0); |
---|
146 | return ((Body*)dBodyGetData(b)); |
---|
147 | } |
---|
148 | |
---|
149 | Body* Joint::getSecondBody() |
---|
150 | { |
---|
151 | dBodyID b = dJointGetBody(_joint,1); |
---|
152 | return b ? ((Body*)dBodyGetData(b)) : 0; |
---|
153 | } |
---|
154 | |
---|
155 | bool Joint::areConnected(const Body* body_a,const Body* body_b) |
---|
156 | { |
---|
157 | return (dAreConnected(body_a->getBodyID(),body_b->getBodyID()))?true:false; |
---|
158 | } |
---|
159 | |
---|
160 | bool Joint::areConnectedExcluding(const Body* body_a,const Body* body_b,Joint::Type joint_type) |
---|
161 | { |
---|
162 | return (dAreConnectedExcluding(body_a->getBodyID(),body_b->getBodyID(),(int)joint_type))?true:false; |
---|
163 | } |
---|
164 | |
---|
165 | void Joint::enableFeedback() |
---|
166 | { |
---|
167 | dJointSetFeedback(_joint,&_feedback); |
---|
168 | } |
---|
169 | |
---|
170 | void Joint::disableFeedback() |
---|
171 | { |
---|
172 | dJointSetFeedback(_joint,0); |
---|
173 | } |
---|
174 | |
---|
175 | void Joint::detach() |
---|
176 | { |
---|
177 | dJointAttach(_joint,0,0); |
---|
178 | } |
---|
179 | |
---|
180 | void Joint::attach(const Body* body) |
---|
181 | { |
---|
182 | dJointAttach(_joint,body->getBodyID(),0); |
---|
183 | } |
---|
184 | |
---|
185 | void Joint::attach(const Body* body_a,const Body* body_b) |
---|
186 | { |
---|
187 | dJointAttach(_joint,body_a->getBodyID(),body_b->getBodyID()); |
---|
188 | } |
---|
189 | |
---|
190 | const Ogre::Vector3& Joint::getFirstForce() |
---|
191 | { |
---|
192 | assert(dJointGetFeedback(_joint) == &_feedback); |
---|
193 | |
---|
194 | _first_force.x = _feedback.f1[0]; |
---|
195 | _first_force.y = _feedback.f1[1]; |
---|
196 | _first_force.z = _feedback.f1[2]; |
---|
197 | return _first_force; |
---|
198 | } |
---|
199 | |
---|
200 | const Ogre::Vector3& Joint::getFirstTorque() |
---|
201 | { |
---|
202 | assert(dJointGetFeedback(_joint) == &_feedback); |
---|
203 | |
---|
204 | _first_torque.x = _feedback.t1[0]; |
---|
205 | _first_torque.y = _feedback.t1[1]; |
---|
206 | _first_torque.z = _feedback.t1[2]; |
---|
207 | return _first_torque; |
---|
208 | } |
---|
209 | |
---|
210 | const Ogre::Vector3& Joint::getSecondForce() |
---|
211 | { |
---|
212 | assert(dJointGetFeedback(_joint) == &_feedback); |
---|
213 | |
---|
214 | _second_force.x = _feedback.f2[0]; |
---|
215 | _second_force.y = _feedback.f2[1]; |
---|
216 | _second_force.z = _feedback.f2[2]; |
---|
217 | return _second_force; |
---|
218 | } |
---|
219 | |
---|
220 | const Ogre::Vector3& Joint::getSecondTorque() |
---|
221 | { |
---|
222 | assert(dJointGetFeedback(_joint) == &_feedback); |
---|
223 | |
---|
224 | _second_torque.x = _feedback.t2[0]; |
---|
225 | _second_torque.y = _feedback.t2[1]; |
---|
226 | _second_torque.z = _feedback.t2[2]; |
---|
227 | return _second_torque; |
---|
228 | } |
---|
229 | |
---|
230 | void Joint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
231 | { |
---|
232 | } |
---|
233 | |
---|
234 | Real Joint::getParameter(Joint::Parameter parameter,int axis) |
---|
235 | { |
---|
236 | return 0.0; |
---|
237 | } |
---|
238 | |
---|
239 | BallJoint::BallJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
240 | { |
---|
241 | _joint = dJointCreateBall(getWorldID(),getJointGroupID(group)); |
---|
242 | registerJoint(); |
---|
243 | } |
---|
244 | |
---|
245 | void BallJoint::setAnchor(const Ogre::Vector3& position) |
---|
246 | { |
---|
247 | dJointSetBallAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
---|
248 | } |
---|
249 | |
---|
250 | const Ogre::Vector3& BallJoint::getAnchor() |
---|
251 | { |
---|
252 | dVector3 result; |
---|
253 | dJointGetBallAnchor(_joint,result); |
---|
254 | _anchor.x = (Real)result[0]; |
---|
255 | _anchor.y = (Real)result[1]; |
---|
256 | _anchor.z = (Real)result[2]; |
---|
257 | return _anchor; |
---|
258 | } |
---|
259 | |
---|
260 | const Ogre::Vector3& BallJoint::getAnchorError() |
---|
261 | { |
---|
262 | dVector3 result1,result2; |
---|
263 | dJointGetBallAnchor(_joint,result1); |
---|
264 | dJointGetBallAnchor2(_joint,result2); |
---|
265 | _anchor_error.x = (Real)(result1[0] - result2[2]); |
---|
266 | _anchor_error.y = (Real)(result1[1] - result2[2]); |
---|
267 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
---|
268 | return _anchor_error; |
---|
269 | } |
---|
270 | |
---|
271 | void BallJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
272 | { |
---|
273 | dJointSetBallParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
274 | } |
---|
275 | |
---|
276 | Real BallJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
277 | { |
---|
278 | return (Real)dJointGetBallParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
279 | } |
---|
280 | |
---|
281 | |
---|
282 | BallJoint::~BallJoint() |
---|
283 | { |
---|
284 | } |
---|
285 | |
---|
286 | HingeJoint::HingeJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
287 | { |
---|
288 | _joint = dJointCreateHinge(getWorldID(),getJointGroupID(group)); |
---|
289 | registerJoint(); |
---|
290 | } |
---|
291 | |
---|
292 | void HingeJoint::setAnchor(const Ogre::Vector3& position) |
---|
293 | { |
---|
294 | dJointSetHingeAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
---|
295 | } |
---|
296 | |
---|
297 | void HingeJoint::addTorque(Real torque,Real torque2,Real torque3) |
---|
298 | { |
---|
299 | dJointAddHingeTorque(_joint,(dReal)torque); |
---|
300 | } |
---|
301 | |
---|
302 | const Ogre::Vector3& HingeJoint::getAnchor() |
---|
303 | { |
---|
304 | dVector3 result; |
---|
305 | dJointGetHingeAnchor(_joint,result); |
---|
306 | _anchor.x = (Real)result[0]; |
---|
307 | _anchor.y = (Real)result[1]; |
---|
308 | _anchor.z = (Real)result[2]; |
---|
309 | return _anchor; |
---|
310 | } |
---|
311 | |
---|
312 | const Ogre::Vector3& HingeJoint::getAnchorError() |
---|
313 | { |
---|
314 | dVector3 result1,result2; |
---|
315 | dJointGetHingeAnchor(_joint,result1); |
---|
316 | dJointGetHingeAnchor2(_joint,result2); |
---|
317 | _anchor_error.x = (Real)(result1[0] - result2[2]); |
---|
318 | _anchor_error.y = (Real)(result1[1] - result2[2]); |
---|
319 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
---|
320 | return _anchor_error; |
---|
321 | } |
---|
322 | |
---|
323 | void HingeJoint::setAxis(const Ogre::Vector3& axis) |
---|
324 | { |
---|
325 | dJointSetHingeAxis(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
326 | } |
---|
327 | |
---|
328 | const Ogre::Vector3& HingeJoint::getAxis() |
---|
329 | { |
---|
330 | dVector3 result; |
---|
331 | dJointGetHingeAxis(_joint,result); |
---|
332 | _axis.x = (Real)result[0]; |
---|
333 | _axis.y = (Real)result[1]; |
---|
334 | _axis.z = (Real)result[2]; |
---|
335 | return _axis; |
---|
336 | } |
---|
337 | |
---|
338 | Real HingeJoint::getAngle() |
---|
339 | { |
---|
340 | return (Real)dJointGetHingeAngle(_joint); |
---|
341 | } |
---|
342 | |
---|
343 | Real HingeJoint::getAngleRate() |
---|
344 | { |
---|
345 | return (Real)dJointGetHingeAngleRate(_joint); |
---|
346 | } |
---|
347 | |
---|
348 | void HingeJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
349 | { |
---|
350 | dJointSetHingeParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
351 | } |
---|
352 | |
---|
353 | Real HingeJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
354 | { |
---|
355 | return (Real)dJointGetHingeParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
356 | } |
---|
357 | |
---|
358 | HingeJoint::~HingeJoint() |
---|
359 | { |
---|
360 | } |
---|
361 | |
---|
362 | SliderJoint::SliderJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
363 | { |
---|
364 | _joint = dJointCreateSlider(getWorldID(),getJointGroupID(group)); |
---|
365 | registerJoint(); |
---|
366 | } |
---|
367 | |
---|
368 | void SliderJoint::setAxis(const Ogre::Vector3& axis) |
---|
369 | { |
---|
370 | dJointSetSliderAxis(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
371 | } |
---|
372 | |
---|
373 | const Ogre::Vector3& SliderJoint::getAxis() |
---|
374 | { |
---|
375 | dVector3 result; |
---|
376 | dJointGetSliderAxis(_joint,result); |
---|
377 | _axis.x = (Real)result[0]; |
---|
378 | _axis.y = (Real)result[1]; |
---|
379 | _axis.z = (Real)result[2]; |
---|
380 | return _axis; |
---|
381 | } |
---|
382 | |
---|
383 | void SliderJoint::addForce(Real force,Real force2,Real force3) |
---|
384 | { |
---|
385 | dJointAddSliderForce(_joint,(dReal)force); |
---|
386 | } |
---|
387 | |
---|
388 | Real SliderJoint::getPosition() |
---|
389 | { |
---|
390 | return (Real)dJointGetSliderPosition(_joint); |
---|
391 | } |
---|
392 | |
---|
393 | Real SliderJoint::getPositionRate() |
---|
394 | { |
---|
395 | return (Real)dJointGetSliderPositionRate(_joint); |
---|
396 | } |
---|
397 | |
---|
398 | void SliderJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
399 | { |
---|
400 | dJointSetSliderParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
401 | } |
---|
402 | |
---|
403 | Real SliderJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
404 | { |
---|
405 | return (Real)dJointGetSliderParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
406 | } |
---|
407 | |
---|
408 | SliderJoint::~SliderJoint() |
---|
409 | { |
---|
410 | } |
---|
411 | |
---|
412 | UniversalJoint::UniversalJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
413 | { |
---|
414 | _joint = dJointCreateUniversal(getWorldID(),getJointGroupID(group)); |
---|
415 | registerJoint(); |
---|
416 | } |
---|
417 | |
---|
418 | void UniversalJoint::setAnchor(const Ogre::Vector3& position) |
---|
419 | { |
---|
420 | dJointSetUniversalAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
---|
421 | } |
---|
422 | |
---|
423 | void UniversalJoint::addTorque(Real torque,Real torque2,Real torque3) |
---|
424 | { |
---|
425 | dJointAddUniversalTorques(_joint,(dReal)torque,(dReal)torque2); |
---|
426 | } |
---|
427 | |
---|
428 | const Ogre::Vector3& UniversalJoint::getAnchor() |
---|
429 | { |
---|
430 | dVector3 result; |
---|
431 | dJointGetUniversalAnchor(_joint,result); |
---|
432 | _anchor.x = (Real)result[0]; |
---|
433 | _anchor.y = (Real)result[1]; |
---|
434 | _anchor.z = (Real)result[2]; |
---|
435 | return _anchor; |
---|
436 | } |
---|
437 | |
---|
438 | const Ogre::Vector3& UniversalJoint::getAnchorError() |
---|
439 | { |
---|
440 | dVector3 result1,result2; |
---|
441 | dJointGetUniversalAnchor(_joint,result1); |
---|
442 | dJointGetUniversalAnchor2(_joint,result2); |
---|
443 | _anchor_error.x = (Real)(result1[0] - result2[2]); |
---|
444 | _anchor_error.y = (Real)(result1[1] - result2[2]); |
---|
445 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
---|
446 | return _anchor_error; |
---|
447 | } |
---|
448 | |
---|
449 | void UniversalJoint::setAxis(const Ogre::Vector3& axis) |
---|
450 | { |
---|
451 | dJointSetUniversalAxis1(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
452 | } |
---|
453 | |
---|
454 | const Ogre::Vector3& UniversalJoint::getAxis() |
---|
455 | { |
---|
456 | dVector3 result; |
---|
457 | dJointGetUniversalAxis1(_joint,result); |
---|
458 | _axis.x = (Real)result[0]; |
---|
459 | _axis.y = (Real)result[1]; |
---|
460 | _axis.z = (Real)result[2]; |
---|
461 | return _axis; |
---|
462 | } |
---|
463 | |
---|
464 | void UniversalJoint::setAdditionalAxis(const Ogre::Vector3& axis) |
---|
465 | { |
---|
466 | dJointSetUniversalAxis2(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
467 | } |
---|
468 | |
---|
469 | const Ogre::Vector3& UniversalJoint::getAdditionalAxis() |
---|
470 | { |
---|
471 | dVector3 result; |
---|
472 | dJointGetUniversalAxis2(_joint,result); |
---|
473 | _additional_axis.x = (Real)result[0]; |
---|
474 | _additional_axis.y = (Real)result[1]; |
---|
475 | _additional_axis.z = (Real)result[2]; |
---|
476 | return _additional_axis; |
---|
477 | } |
---|
478 | |
---|
479 | void UniversalJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
480 | { |
---|
481 | dJointSetUniversalParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
482 | } |
---|
483 | |
---|
484 | Real UniversalJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
485 | { |
---|
486 | return (Real)dJointGetUniversalParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
487 | } |
---|
488 | |
---|
489 | UniversalJoint::~UniversalJoint() |
---|
490 | { |
---|
491 | } |
---|
492 | |
---|
493 | FixedJoint::FixedJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
494 | { |
---|
495 | _joint = dJointCreateFixed(getWorldID(),getJointGroupID(group)); |
---|
496 | registerJoint(); |
---|
497 | } |
---|
498 | |
---|
499 | void FixedJoint::attach(const Body* body) |
---|
500 | { |
---|
501 | Joint::attach(body); |
---|
502 | dJointSetFixed(_joint); |
---|
503 | } |
---|
504 | |
---|
505 | void FixedJoint::attach(const Body* body_a,const Body* body_b) |
---|
506 | { |
---|
507 | Joint::attach(body_a,body_b); |
---|
508 | dJointSetFixed(_joint); |
---|
509 | } |
---|
510 | |
---|
511 | FixedJoint::~FixedJoint() |
---|
512 | { |
---|
513 | } |
---|
514 | |
---|
515 | SuspensionJoint::SuspensionJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
516 | { |
---|
517 | _joint = dJointCreateHinge2(getWorldID(),getJointGroupID(group)); |
---|
518 | registerJoint(); |
---|
519 | } |
---|
520 | |
---|
521 | void SuspensionJoint::setAnchor(const Ogre::Vector3& position) |
---|
522 | { |
---|
523 | dJointSetHinge2Anchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
---|
524 | } |
---|
525 | |
---|
526 | |
---|
527 | void SuspensionJoint::addTorque(Real torque,Real torque2,Real torque3) |
---|
528 | { |
---|
529 | dJointAddHinge2Torques(_joint,(dReal)torque,(dReal)torque2); |
---|
530 | } |
---|
531 | |
---|
532 | const Ogre::Vector3& SuspensionJoint::getAnchor() |
---|
533 | { |
---|
534 | dVector3 result; |
---|
535 | dJointGetHinge2Anchor(_joint,result); |
---|
536 | _anchor.x = (Real)result[0]; |
---|
537 | _anchor.y = (Real)result[1]; |
---|
538 | _anchor.z = (Real)result[2]; |
---|
539 | return _anchor; |
---|
540 | } |
---|
541 | |
---|
542 | const Ogre::Vector3& SuspensionJoint::getAdditionalAnchor() |
---|
543 | { |
---|
544 | dVector3 result; |
---|
545 | dJointGetHinge2Anchor2(_joint,result); |
---|
546 | _anchor2.x = (Real)result[0]; |
---|
547 | _anchor2.y = (Real)result[1]; |
---|
548 | _anchor2.z = (Real)result[2]; |
---|
549 | return _anchor2; |
---|
550 | } |
---|
551 | |
---|
552 | const Ogre::Vector3& SuspensionJoint::getAnchorError() |
---|
553 | { |
---|
554 | dVector3 result1,result2; |
---|
555 | dJointGetHinge2Anchor(_joint,result1); |
---|
556 | dJointGetHinge2Anchor2(_joint,result2); |
---|
557 | _anchor_error.x = (Real)(result1[0] - result2[2]); |
---|
558 | _anchor_error.y = (Real)(result1[1] - result2[2]); |
---|
559 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
---|
560 | return _anchor_error; |
---|
561 | } |
---|
562 | |
---|
563 | void SuspensionJoint::setAxis(const Ogre::Vector3& axis) |
---|
564 | { |
---|
565 | dJointSetHinge2Axis1(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
566 | } |
---|
567 | |
---|
568 | const Ogre::Vector3& SuspensionJoint::getAxis() |
---|
569 | { |
---|
570 | dVector3 result; |
---|
571 | dJointGetHinge2Axis1(_joint,result); |
---|
572 | _axis.x = (Real)result[0]; |
---|
573 | _axis.y = (Real)result[1]; |
---|
574 | _axis.z = (Real)result[2]; |
---|
575 | return _axis; |
---|
576 | } |
---|
577 | |
---|
578 | void SuspensionJoint::setAdditionalAxis(const Ogre::Vector3& axis) |
---|
579 | { |
---|
580 | dJointSetHinge2Axis2(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
581 | } |
---|
582 | |
---|
583 | const Ogre::Vector3& SuspensionJoint::getAdditionalAxis() |
---|
584 | { |
---|
585 | dVector3 result; |
---|
586 | dJointGetHinge2Axis2(_joint,result); |
---|
587 | _additional_axis.x = (Real)result[0]; |
---|
588 | _additional_axis.y = (Real)result[1]; |
---|
589 | _additional_axis.z = (Real)result[2]; |
---|
590 | return _additional_axis; |
---|
591 | } |
---|
592 | |
---|
593 | Real SuspensionJoint::getAngle() |
---|
594 | { |
---|
595 | return (Real)dJointGetHinge2Angle1(_joint); |
---|
596 | } |
---|
597 | |
---|
598 | Real SuspensionJoint::getAngleRate() |
---|
599 | { |
---|
600 | return (Real)dJointGetHinge2Angle1Rate(_joint); |
---|
601 | } |
---|
602 | |
---|
603 | Real SuspensionJoint::getPositionRate() |
---|
604 | { |
---|
605 | return (Real)dJointGetHinge2Angle2Rate(_joint); |
---|
606 | } |
---|
607 | |
---|
608 | void SuspensionJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
609 | { |
---|
610 | dJointSetHinge2Param(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
611 | } |
---|
612 | |
---|
613 | Real SuspensionJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
614 | { |
---|
615 | return (Real)dJointGetHinge2Param(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
616 | } |
---|
617 | |
---|
618 | SuspensionJoint::~SuspensionJoint() |
---|
619 | { |
---|
620 | } |
---|
621 | |
---|
622 | AngularMotorJoint::AngularMotorJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
623 | { |
---|
624 | _joint = dJointCreateAMotor(getWorldID(),getJointGroupID(group)); |
---|
625 | registerJoint(); |
---|
626 | } |
---|
627 | |
---|
628 | void AngularMotorJoint::setMode(AngularMotorJoint::Mode mode) |
---|
629 | { |
---|
630 | dJointSetAMotorMode(_joint,(int)mode); |
---|
631 | } |
---|
632 | |
---|
633 | AngularMotorJoint::Mode AngularMotorJoint::getMode() |
---|
634 | { |
---|
635 | return (AngularMotorJoint::Mode)dJointGetAMotorMode(_joint); |
---|
636 | } |
---|
637 | |
---|
638 | void AngularMotorJoint::addTorque(Real torque,Real torque2,Real torque3) |
---|
639 | { |
---|
640 | dJointAddAMotorTorques(_joint,(dReal)torque,(dReal)torque2,(dReal)torque3); |
---|
641 | } |
---|
642 | |
---|
643 | void AngularMotorJoint::setAxisCount(int axes) |
---|
644 | { |
---|
645 | assert((axes >= 0) && (axes <= 3)); |
---|
646 | dJointSetAMotorNumAxes(_joint,axes); |
---|
647 | } |
---|
648 | |
---|
649 | int AngularMotorJoint::getAxisCount() |
---|
650 | { |
---|
651 | return dJointGetAMotorNumAxes(_joint); |
---|
652 | } |
---|
653 | |
---|
654 | void AngularMotorJoint::setAxis(int axis_number,AngularMotorJoint::RelativeOrientation orientation,const Ogre::Vector3& axis) |
---|
655 | { |
---|
656 | dJointSetAMotorAxis(_joint,axis_number,(int)orientation,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
657 | } |
---|
658 | |
---|
659 | const Ogre::Vector3& AngularMotorJoint::getAxis(int axis_number) |
---|
660 | { |
---|
661 | dVector3 result; |
---|
662 | dJointGetAMotorAxis(_joint,axis_number,result); |
---|
663 | _axis.x = (Real)result[0]; |
---|
664 | _axis.y = (Real)result[1]; |
---|
665 | _axis.z = (Real)result[2]; |
---|
666 | return _axis; |
---|
667 | } |
---|
668 | |
---|
669 | AngularMotorJoint::RelativeOrientation AngularMotorJoint::getAxisRelativeOrientation(int axis_number) |
---|
670 | { |
---|
671 | return (AngularMotorJoint::RelativeOrientation)dJointGetAMotorAxisRel(_joint,axis_number); |
---|
672 | } |
---|
673 | |
---|
674 | void AngularMotorJoint::setAngle(int axis,Real angle) |
---|
675 | { |
---|
676 | dJointSetAMotorAngle(_joint,axis,(dReal)angle); |
---|
677 | } |
---|
678 | |
---|
679 | Real AngularMotorJoint::getAngle(int axis) |
---|
680 | { |
---|
681 | return (Real)dJointGetAMotorAngle(_joint,axis); |
---|
682 | } |
---|
683 | |
---|
684 | Real AngularMotorJoint::getAngleRate(int axis) |
---|
685 | { |
---|
686 | return (Real)dJointGetAMotorAngleRate(_joint,axis); |
---|
687 | } |
---|
688 | |
---|
689 | void AngularMotorJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
690 | { |
---|
691 | dJointSetAMotorParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
692 | } |
---|
693 | |
---|
694 | Real AngularMotorJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
695 | { |
---|
696 | return (Real)dJointGetAMotorParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
697 | } |
---|
698 | |
---|
699 | AngularMotorJoint::~AngularMotorJoint() |
---|
700 | { |
---|
701 | } |
---|
702 | |
---|
703 | PlanarJoint::PlanarJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
704 | { |
---|
705 | _joint = dJointCreatePlane2D(getWorldID(),getJointGroupID(group)); |
---|
706 | registerJoint(); |
---|
707 | } |
---|
708 | |
---|
709 | void PlanarJoint::setParameterX(Joint::Parameter parameter,Real value,int axis) |
---|
710 | { |
---|
711 | dJointSetPlane2DXParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
712 | } |
---|
713 | |
---|
714 | void PlanarJoint::setParameterY(Joint::Parameter parameter,Real value,int axis) |
---|
715 | { |
---|
716 | dJointSetPlane2DYParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
717 | } |
---|
718 | |
---|
719 | void PlanarJoint::setParameterAngle(Joint::Parameter parameter,Real value,int axis) |
---|
720 | { |
---|
721 | dJointSetPlane2DAngleParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
722 | } |
---|
723 | |
---|
724 | PlanarJoint::~PlanarJoint() |
---|
725 | { |
---|
726 | } |
---|
727 | |
---|
728 | |
---|
729 | |
---|
730 | SliderHingeJoint::SliderHingeJoint(World *world, const JointGroup* group) : Joint(world, group) |
---|
731 | { |
---|
732 | _joint = dJointCreatePR(getWorldID(),getJointGroupID(group)); |
---|
733 | registerJoint(); |
---|
734 | } |
---|
735 | |
---|
736 | SliderHingeJoint::~SliderHingeJoint() |
---|
737 | { |
---|
738 | } |
---|
739 | |
---|
740 | void SliderHingeJoint::setAnchor(const Ogre::Vector3& position) |
---|
741 | { |
---|
742 | dJointSetPRAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
---|
743 | } |
---|
744 | |
---|
745 | const Ogre::Vector3& SliderHingeJoint::getAnchor() |
---|
746 | { |
---|
747 | dVector3 result; |
---|
748 | dJointGetPRAnchor(_joint,result); |
---|
749 | _anchor.x = (Real)result[0]; |
---|
750 | _anchor.y = (Real)result[1]; |
---|
751 | _anchor.z = (Real)result[2]; |
---|
752 | return _anchor; |
---|
753 | } |
---|
754 | |
---|
755 | |
---|
756 | Real SliderHingeJoint::getPosition() |
---|
757 | { |
---|
758 | return (Real)dJointGetPRPosition(_joint); |
---|
759 | } |
---|
760 | |
---|
761 | Real SliderHingeJoint::getPositionRate() |
---|
762 | { |
---|
763 | return (Real)dJointGetPRPositionRate(_joint); |
---|
764 | } |
---|
765 | |
---|
766 | void SliderHingeJoint::setAxis(const Ogre::Vector3& axis) |
---|
767 | { |
---|
768 | dJointSetPRAxis1(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
769 | } |
---|
770 | |
---|
771 | const Ogre::Vector3& SliderHingeJoint::getAxis() |
---|
772 | { |
---|
773 | dVector3 result; |
---|
774 | dJointGetPRAxis1(_joint,result); |
---|
775 | _axis.x = (Real)result[0]; |
---|
776 | _axis.y = (Real)result[1]; |
---|
777 | _axis.z = (Real)result[2]; |
---|
778 | return _axis; |
---|
779 | } |
---|
780 | |
---|
781 | void SliderHingeJoint::setAdditionalAxis(const Ogre::Vector3& axis) |
---|
782 | { |
---|
783 | dJointSetPRAxis2(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
---|
784 | } |
---|
785 | |
---|
786 | const Ogre::Vector3& SliderHingeJoint::getAdditionalAxis() |
---|
787 | { |
---|
788 | dVector3 result; |
---|
789 | dJointGetPRAxis2(_joint,result); |
---|
790 | _additional_axis.x = (Real)result[0]; |
---|
791 | _additional_axis.y = (Real)result[1]; |
---|
792 | _additional_axis.z = (Real)result[2]; |
---|
793 | return _additional_axis; |
---|
794 | } |
---|
795 | |
---|
796 | void SliderHingeJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
---|
797 | { |
---|
798 | dJointSetPRParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
---|
799 | } |
---|
800 | |
---|
801 | Real SliderHingeJoint::getParameter(Joint::Parameter parameter,int axis) |
---|
802 | { |
---|
803 | return (Real)dJointGetPRParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
---|
804 | } |
---|
805 | |
---|
806 | |
---|
807 | void SliderHingeJoint::addTorque(Real torque,Real torque2,Real torque3) |
---|
808 | { |
---|
809 | dJointAddPRTorque(_joint, (dReal)torque); |
---|
810 | } |
---|