Project

General

Profile

SO3Engine
OgreNewt_BasicJoints.cpp
Go to the documentation of this file.
5
6#include "CustomHinge.h"
7#include "CustomSlider.h"
8#include "CustomBallAndSocket.h"
9#include "CustomUpVector.h"
10#include "CustomKinematicController.h"
11
12#include <OgreLogManager.h>
13#include <OgreStringConverter.h>
14
15
16
17namespace OgreNewt
18{
19
20
21 BallAndSocketLimits::BallAndSocketLimits(const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos) : Joint()
22 {
23 CustomJoint* suppportJoint;
24
25 // make the joint matrix
26 dMatrix pinsAndPivoFrame(dGetIdentityMatrix());
27 pinsAndPivoFrame.m_posit = dVector(pos.x, pos.y, pos.z);
28
29 // crate a Newton Custom joint and set it at the support joint
30 suppportJoint = new CustomLimitBallAndSocket(pinsAndPivoFrame, child->getNewtonBody(), parent ? parent->getNewtonBody() : NULL);
31 SetSupportJoint(suppportJoint);
32 }
33
35 {
36 // nothing, the ~Joint() function will take care of us.
37 }
38
39 void BallAndSocketLimits::setLimits(Ogre::Radian maxCone, Ogre::Radian minTwist, Ogre::Radian maxTwist)
40 {
41 CustomLimitBallAndSocket* joint = (CustomLimitBallAndSocket*)m_joint;
42 joint->SetConeAngle((float)maxCone.valueRadians());
43 joint->SetTwistAngle((float)minTwist.valueRadians(), (float)maxTwist.valueRadians());
44 }
45
47 {
48 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
49 dVector fvec;
50 NewtonBallGetJointAngle(m_joint->GetJoint(), &fvec.m_x);
51 if (!_isnan(fvec.m_x))
52 ret.x = Ogre::Real(fvec.m_x);
53 if (!_isnan(fvec.m_y))
54 ret.y = Ogre::Real(fvec.m_y);
55 if (!_isnan(fvec.m_z))
56 ret.z = Ogre::Real(fvec.m_z);
57 return ret;
58 }
59
61 {
62 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
63 dVector fvec;
64 NewtonBallGetJointOmega(m_joint->GetJoint(), &fvec.m_x);
65 if (!_isnan(fvec.m_x))
66 ret.x = Ogre::Real(fvec.m_x);
67 if (!_isnan(fvec.m_y))
68 ret.y = Ogre::Real(fvec.m_y);
69 if (!_isnan(fvec.m_z))
70 ret.z = Ogre::Real(fvec.m_z);
71 return ret;
72 }
73
75 {
76 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
77 dVector fvec;
78 NewtonBallGetJointForce(m_joint->GetJoint(), &fvec.m_x);
79 if (!_isnan(fvec.m_x))
80 ret.x = Ogre::Real(fvec.m_x);
81 if (!_isnan(fvec.m_y))
82 ret.y = Ogre::Real(fvec.m_y);
83 if (!_isnan(fvec.m_z))
84 ret.z = Ogre::Real(fvec.m_z);
85 return ret;
86 }
87
88 BallAndSocket::BallAndSocket(const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos) : Joint()
89 {
90 CustomJoint* suppportJoint;
91
92 // make the joint matrix
93 dMatrix pinsAndPivoFrame(dGetIdentityMatrix());
94 pinsAndPivoFrame.m_posit = dVector(pos.x, pos.y, pos.z, 1.0f);
95
96 // crate a Newton Custom joint and set it at the support joint
97 suppportJoint = new CustomBallAndSocket(pinsAndPivoFrame, child->getNewtonBody(), parent ? parent->getNewtonBody() : NULL);
98 SetSupportJoint(suppportJoint);
99 }
100
102 {
103 // nothing, the ~Joint() function will take care of us.
104 }
105
107 {
108 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
109 dVector fvec;
110 NewtonBallGetJointAngle(m_joint->GetJoint(), &fvec.m_x);
111 if (!_isnan(fvec.m_x))
112 ret.x = Ogre::Real(fvec.m_x);
113 if (!_isnan(fvec.m_y))
114 ret.y = Ogre::Real(fvec.m_y);
115 if (!_isnan(fvec.m_z))
116 ret.z = Ogre::Real(fvec.m_z);
117 return ret;
118 }
119
121 {
122 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
123 dVector fvec;
124 NewtonBallGetJointOmega(m_joint->GetJoint(), &fvec.m_x);
125 if (!_isnan(fvec.m_x))
126 ret.x = Ogre::Real(fvec.m_x);
127 if (!_isnan(fvec.m_y))
128 ret.y = Ogre::Real(fvec.m_y);
129 if (!_isnan(fvec.m_z))
130 ret.z = Ogre::Real(fvec.m_z);
131 return ret;
132 }
133
135 {
136 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
137 dVector fvec;
138 NewtonBallGetJointForce(m_joint->GetJoint(), &fvec.m_x);
139 if (!_isnan(fvec.m_x))
140 ret.x = Ogre::Real(fvec.m_x);
141 if (!_isnan(fvec.m_y))
142 ret.y = Ogre::Real(fvec.m_y);
143 if (!_isnan(fvec.m_z))
144 ret.z = Ogre::Real(fvec.m_z);
145 return ret;
146 }
147
148 ControlledBallAndSocket::ControlledBallAndSocket(const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos) : Joint()
149 {
150 CustomJoint* suppportJoint;
151
152 // make the joint matrix
153 dMatrix pinsAndPivoFrame(dGetIdentityMatrix());
154 pinsAndPivoFrame.m_posit = dVector(pos.x, pos.y, pos.z, 1.0f);
155
156 // crate a Newton Custom joint and set it at the support joint
157 suppportJoint = new CustomControlledBallAndSocket(pinsAndPivoFrame, child->getNewtonBody(), parent ? parent->getNewtonBody() : NULL);
158 SetSupportJoint(suppportJoint);
159 }
160
162 {
163 // nothing, the ~Joint() function will take care of us.
164 }
165
167 {
168 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
169 dVector fvec;
170 NewtonBallGetJointAngle(m_joint->GetJoint(), &fvec.m_x);
171 if (!_isnan(fvec.m_x))
172 ret.x = Ogre::Real(fvec.m_x);
173 if (!_isnan(fvec.m_y))
174 ret.y = Ogre::Real(fvec.m_y);
175 if (!_isnan(fvec.m_z))
176 ret.z = Ogre::Real(fvec.m_z);
177 return ret;
178 }
179
181 {
182 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
183 dVector fvec;
184 NewtonBallGetJointOmega(m_joint->GetJoint(), &fvec.m_x);
185 if (!_isnan(fvec.m_x))
186 ret.x = Ogre::Real(fvec.m_x);
187 if (!_isnan(fvec.m_y))
188 ret.y = Ogre::Real(fvec.m_y);
189 if (!_isnan(fvec.m_z))
190 ret.z = Ogre::Real(fvec.m_z);
191 return ret;
192 }
193
195 {
196 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
197 dVector fvec;
198 NewtonBallGetJointForce(m_joint->GetJoint(), &fvec.m_x);
199 if (!_isnan(fvec.m_x))
200 ret.x = Ogre::Real(fvec.m_x);
201 if (!_isnan(fvec.m_y))
202 ret.y = Ogre::Real(fvec.m_y);
203 if (!_isnan(fvec.m_z))
204 ret.z = Ogre::Real(fvec.m_z);
205 return ret;
206 }
207
209 {
210 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
211 joint->SetAngularVelocity(dFloat(omegaMag));
212
213 // hack to wakeup the bodies
214 getBody0()->wakeUp();
215 if (getBody1())
216 getBody1()->wakeUp();
217 }
218
220 {
221 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
222 return Ogre::Real(joint->GetAngularVelocity());
223 }
224
226 {
227 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
228 joint->SetPitchAngle(dFloat(angle));
229
230 // hack to wakeup the bodies
231 getBody0()->wakeUp();
232 if (getBody1())
233 getBody1()->wakeUp();
234 }
235
237 {
238 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
239 return Ogre::Real(joint->SetPitchAngle());
240 }
241
243 {
244 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
245 joint->SetYawAngle(dFloat(angle));
246
247 // hack to wakeup the bodies
248 getBody0()->wakeUp();
249 if (getBody1())
250 getBody1()->wakeUp();
251 }
252
254 {
255 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
256 return Ogre::Real(joint->SetYawAngle());
257 }
258
260 {
261 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
262 joint->SetRollAngle(dFloat(angle));
263
264 // hack to wakeup the bodies
265 getBody0()->wakeUp();
266 if (getBody1())
267 getBody1()->wakeUp();
268 }
269
271 {
272 CustomControlledBallAndSocket* joint = (CustomControlledBallAndSocket*)m_joint;
273 return Ogre::Real(joint->SetRollAngle());
274 }
275
278 Hinge::Hinge(const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos, const Ogre::Vector3& pin) : Joint()
279 {
280 CustomJoint* suppportJoint;
281
282 // make the joint matrix
283 dVector dir(pin.x, pin.y, pin.z, 0.0f);
284 dMatrix pinsAndPivoFrame(dGrammSchmidt(dir));
285 pinsAndPivoFrame.m_posit = dVector(pos.x, pos.y, pos.z, 1.0f);
286
287 // crate a Newton Custom joint and set it at the support joint
288 suppportJoint = new CustomHinge(pinsAndPivoFrame, child->getNewtonBody(), parent ? parent->getNewtonBody() : NULL);
289 SetSupportJoint(suppportJoint);
290
293 m_desiredOmega = 0.0f;
294 m_desiredAngle = 0.0f;
295 m_motorStrength = 0.5f;
296 m_motorTorque = 0.0f;
297 m_motorMinFriction = 0.0f;
298 m_motorMaxFriction = 0.0f;
299 m_brakeMaxForce = 0.0f;
300 m_useLimits = false;
301 m_useMotor = false;
302 m_minAngle = 0.0f;
303 m_maxAngle = 0.0f;
304 }
305
307 {
308 }
309
310
311 void Hinge::enableLimits(bool state)
312 {
313 m_useLimits = state;
314
315 // use our own limits otherwise we cannot add addAngularRow when needed
316 //CustomHinge* joint = (CustomHinge*) GetSupportJoint();
317 //joint->EnableLimits(state);
318 }
319
320 void Hinge::enableMotor(bool state)
321 {
322 m_useMotor = state;
323
324 // hack to wakeup the bodies
325 getBody0()->wakeUp();
326 if (getBody1())
327 getBody1()->wakeUp();
328 }
329
330 void Hinge::setLimits(Ogre::Radian minAngle, Ogre::Radian maxAngle)
331 {
332 m_minAngle = minAngle;
333 m_maxAngle = maxAngle;
334
335 // use our own limits otherwise we cannot add addAngularRow when needed
336 //CustomHinge* joint = (CustomHinge*) GetSupportJoint();
337 //joint->SetLimis(minAngle.valueRadians(), maxAngle.valueRadians());
338
339 // hack to wakeup the bodies
340 getBody0()->wakeUp();
341 if (getBody1())
342 getBody1()->wakeUp();
343 }
344
345 void Hinge::setDesiredOmega(Ogre::Radian omega, Ogre::Real strength)
346 {
347 if (_isnan(omega.valueRadians()) || _isnan(strength))
348 return;
349
350 m_desiredOmega = omega;
351 m_motorStrength = strength;
353 {
356 }
357
358 // hack to wakeup the bodies
359 getBody0()->wakeUp();
360 if (getBody1())
361 getBody1()->wakeUp();
362 }
363
364 void Hinge::setTorque(Ogre::Real torque)
365 {
366 if (_isnan(torque))
367 return;
368
369 m_motorTorque = torque;
370 m_desiredOmega = 0.0f;
371
372 // hack to wakeup the bodies
373 getBody0()->wakeUp();
374 if (getBody1())
375 getBody1()->wakeUp();
376 }
377
378 void Hinge::setDesiredAngle(Ogre::Radian angle, Ogre::Real minFriction, Ogre::Real maxFriction)
379 {
380 if (m_useLimits)
381 if (angle < m_minAngle)
382 angle = m_minAngle;
383 else if (angle > m_maxAngle)
384 angle = m_maxAngle;
385
386 m_desiredAngle = angle;
387 m_motorMinFriction = minFriction;
388 m_motorMaxFriction = maxFriction;
389
391 {
394 }
395
396 // hack to wakeup the bodies
397 getBody0()->wakeUp();
398 if (getBody1())
399 getBody1()->wakeUp();
400 }
401
402 void Hinge::setBrake(Ogre::Real maxForce)
403 {
404 if (_isnan(maxForce))
405 return;
406 m_brakeMaxForce = maxForce;
407
409 {
412 }
413 }
414
415 Ogre::Radian Hinge::getJointAngle() const
416 {
417 CustomHinge* joint = (CustomHinge*)GetSupportJoint();
418 return Ogre::Radian(Ogre::Real(joint->GetJointAngle()));
419 }
420
421 Ogre::Vector3 Hinge::getJointForce()
422 {
423 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
424 dVector fvec;
425 NewtonHingeGetJointForce(m_joint->GetJoint(), &fvec.m_x);
426 if (!_isnan(fvec.m_x))
427 ret.x = Ogre::Real(fvec.m_x);
428 if (!_isnan(fvec.m_y))
429 ret.y = Ogre::Real(fvec.m_y);
430 if (!_isnan(fvec.m_z))
431 ret.z = Ogre::Real(fvec.m_z);
432 return ret;
433 }
434
436 {
437 CustomHinge* joint = (CustomHinge*)GetSupportJoint();
438 if (_isnan(joint->GetJointOmega()))
439 return Ogre::Radian(0.0);
440 return Ogre::Radian(Ogre::Real(joint->GetJointOmega()));
441 }
442
443 Ogre::Vector3 Hinge::getJointPin() const
444 {
445 CustomHinge* joint = (CustomHinge*)GetSupportJoint();
446 dVector pin(joint->GetPinAxis());
447
448 return Ogre::Vector3(Ogre::Real(pin.m_x), Ogre::Real(pin.m_y), Ogre::Real(pin.m_z));
449 }
450
451 void Hinge::submitConstraint(Ogre::Real timestep, int threadindex)
452 {
453 Ogre::Real invTimestep = (timestep > 0.0f) ? 1.0f / timestep : 1.0f;
454 //remove the brake
457
459 {
460 Ogre::Vector3 pin(getJointPin());
461
462 addAngularRow(Ogre::Radian(0), pin);
463 setRowStiffness(1.0f);
464
465 if (m_brakeMaxForce > 0.0f)
466 {
469 }
470 }
472 {
473 Ogre::Radian relativeOmega = (m_desiredOmega - getJointAngularVelocity()) * m_motorStrength;
474 Ogre::Real acceleration = relativeOmega.valueRadians() * invTimestep;
475 Ogre::Vector3 pin(getJointPin());
476 Ogre::Radian nangle = getJointAngle() - relativeOmega;
477
478 if (m_useLimits && ((nangle < m_minAngle) || (nangle > m_maxAngle)))
479 {
481 {
482 Ogre::Radian relAngle = getJointAngle() - m_minAngle;
483 addAngularRow(relAngle, pin);
484
485 // need high stiffness here
486 setRowStiffness(1.0f);
487
488 // allow the joint to move back freely
490 }
491 else if (getJointAngle() > m_maxAngle)
492 {
493 Ogre::Radian relAngle = getJointAngle() - m_maxAngle;
494 addAngularRow(relAngle, pin);
495
496 // need high stiffness here
497 setRowStiffness(1.0f);
498
499 // allow the joint to move back freely
501 }
502 else
503 {
504 addAngularRow(Ogre::Radian(0.0f), pin);
505 setRowAcceleration(acceleration);
506 //set a minimum friction to avoid infinite velocity
507 setRowMinimumFriction(-90000.0f);
508 setRowMaximumFriction(90000.0f);
509 }
510 }
511 else
512 {
513 addAngularRow(Ogre::Radian(0.0f), pin);
514 setRowAcceleration(acceleration);
515 //set a minimum friction to avoid infinite velocity
516 setRowMinimumFriction(-90000.0f);
517 setRowMaximumFriction(90000.0f);
518 }
519 }
521 {
522 Ogre::Radian relativeAngle = getJointAngle() - m_desiredAngle;
523 Ogre::Vector3 pin(getJointPin());
524 if (m_useLimits)
525 {
527 {
528 Ogre::Radian relAngle = getJointAngle() - m_minAngle;
529 addAngularRow(relAngle, pin);
530
531 // need high stiffness here
532 setRowStiffness(1.0f);
533
534 // allow the joint to move back freely
536 }
537 else if (getJointAngle() > m_maxAngle)
538 {
539 Ogre::Radian relAngle = getJointAngle() - m_maxAngle;
540 addAngularRow(relAngle, pin);
541
542 // need high stiffness here
543 setRowStiffness(1.0f);
544
545 // allow the joint to move back freely
547 }
548 else
549 {
550 Ogre::Vector3 pin(getJointPin());
551 addAngularRow(relativeAngle, pin);
552
553 setRowStiffness(1.0f);
554 if (m_motorMinFriction < 0.0f)
556
557 if (m_motorMaxFriction > 0.0f)
559 }
560 }
561 else
562 {
563 Ogre::Vector3 pin(getJointPin());
564 addAngularRow(relativeAngle, pin);
565
566 setRowStiffness(1.0f);
567 if (m_motorMinFriction < 0.0f)
569
570 if (m_motorMaxFriction > 0.0f)
572 }
573 }
574
576 {
578 {
579 Ogre::Radian relAngle = getJointAngle() - m_minAngle;
580 Ogre::Vector3 pin(getJointPin());
581 addAngularRow(relAngle, pin);
582
583 // need high stiffness here
584 setRowStiffness(1.0f);
585
586 // allow the joint to move back freely
588 }
589 else if (getJointAngle() > m_maxAngle)
590 {
591 Ogre::Radian relAngle = getJointAngle() - m_maxAngle;
592
593 Ogre::Vector3 pin(getJointPin());
594 addAngularRow(relAngle, pin);
595
596 // need high stiffness here
597 setRowStiffness(1.0f);
598
599 // allow the joint to move back freely
601 }
602 }
603
605 {
606 if (getBody0() != NULL)
607 {
608 Ogre::Vector3 pin(getJointPin());
609
611
612 if (getBody1() != NULL)
613 {
615 }
616 }
617 }
618 }
619
620
621
624
625
626
627 Slider::Slider(const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos, const Ogre::Vector3& pin) : Joint()
628 {
629 CustomJoint* suppportJoint;
630
631 m_useLimits = false;
632 m_minDist = 0.0f;
633 m_maxDist = 0.0f;
634 m_useSpring = false;
635 m_springStrength = 0.0f;
636 m_springDamping = 0.0f;
637
638 // make the joint matrix
639 dVector dir(pin.x, pin.y, pin.z, 0.0f);
640 dMatrix pinsAndPivoFrame(dGrammSchmidt(dir));
641 pinsAndPivoFrame.m_posit = dVector(pos.x, pos.y, pos.z, 1.0f);
642
643 // create a Newton Custom joint and set it at the support joint
644 suppportJoint = new CustomSlider(pinsAndPivoFrame, child->getNewtonBody(), parent ? parent->getNewtonBody() : NULL);
645 SetSupportJoint(suppportJoint);
646 }
647
649 {
650 }
651
652
653 void Slider::enableLimits(bool state)
654 {
655 m_useLimits = state;
656 CustomSlider* joint = (CustomSlider*)GetSupportJoint();
657 joint->EnableLimits(state);
658
659 // hack to wakeup the bodies
660 getBody0()->wakeUp();
661 if (getBody1())
662 getBody1()->wakeUp();
663 }
664
665
666 void Slider::enableMotor(bool state)
667 {
668 CustomSlider* joint = (CustomSlider*)GetSupportJoint();
669 joint->EnableMotor(state);
670
671 // hack to wakeup the bodies
672 getBody0()->wakeUp();
673 if (getBody1())
674 getBody1()->wakeUp();
675 }
676
677 void Slider::setMotorVelocity(Ogre::Real velocity, Ogre::Real strength)
678 {
679 if (_isnan(velocity) || _isnan(strength))
680 return;
681 CustomSlider* joint = (CustomSlider*)GetSupportJoint();
682 joint->SetMotorVelocity(velocity, strength);
683
684 // hack to wakeup the bodies
685 getBody0()->wakeUp();
686 if (getBody1())
687 getBody1()->wakeUp();
688 }
689
690 void Slider::setLimits(Ogre::Real minStopDist, Ogre::Real maxStopDist)
691 {
692 m_minDist = minStopDist;
693 m_maxDist = maxStopDist;
694
695 CustomSlider* joint = (CustomSlider*)GetSupportJoint();
696 joint->SetLimis(minStopDist, maxStopDist);
697
698 // hack to wakeup the bodies
699 getBody0()->wakeUp();
700 if (getBody1())
701 getBody1()->wakeUp();
702 }
703
704 void Slider::enableSpring(bool state)
705 {
706 m_useSpring = state;
707 }
708
709 void Slider::setSpring(Ogre::Real springStrength, Ogre::Real springDamping)
710 {
711 m_springStrength = springStrength;
712 m_springDamping = springDamping;
713 }
714
715 Ogre::Vector3 Slider::getJointForce()
716 {
717 Ogre::Vector3 ret = Ogre::Vector3::ZERO;
718 dVector fvec;
719 NewtonSliderGetJointForce(m_joint->GetJoint(), &fvec.m_x);
720 if (!_isnan(fvec.m_x))
721 ret.x = Ogre::Real(fvec.m_x);
722 if (!_isnan(fvec.m_y))
723 ret.y = Ogre::Real(fvec.m_y);
724 if (!_isnan(fvec.m_z))
725 ret.z = Ogre::Real(fvec.m_z);
726 return ret;
727 }
728
729 Ogre::Real Slider::getJointVelocity() const
730 {
731 return Ogre::Real(NewtonSliderGetJointVeloc(m_joint->GetJoint()));
732 }
733
734 Ogre::Real Slider::getDistance() const
735 {
736 CustomSlider* joint = (CustomSlider*)GetSupportJoint();
737 return Ogre::Real(joint->GetDistance());
738 }
739
740 void Slider::setFriction(Ogre::Real friction)
741 {
742 CustomSlider* joint = (CustomSlider*)GetSupportJoint();
743 joint->SetFriction(friction);
744 }
745
746 void Slider::submitConstraint(Ogre::Real timestep, int threadindex)
747 {
748 if (m_useSpring)
749 {
750 setRowStiffness(0.8f);
751 setRowSpringDamper(m_springStrength, m_springDamping);
752 };
753 }
754
755
756 UpVector::UpVector(const Body* body, const Ogre::Vector3& pin) : Joint(), m_pin(pin.normalisedCopy())
757 {
758 dVector dPin(m_pin.x, m_pin.y, m_pin.z, 1.0f);
759 CustomUpVector* support_joint = new CustomUpVector(dPin, body->getNewtonBody());
760 SetSupportJoint(support_joint);
761 }
762
764 {
765 }
766
767 void UpVector::setPin(const Ogre::Vector3& pin)
768 {
769 CustomUpVector* up_vector = static_cast<CustomUpVector*>(m_joint);
770 m_pin = pin.normalisedCopy();
771 dVector dPin(m_pin.x, m_pin.y, m_pin.z, 1.0f);
772 up_vector->SetPinDir(dPin);
773 }
774
775 const Ogre::Vector3& UpVector::getPin() const
776 {
777 return m_pin;
778 }
779
780
781 KinematicController::KinematicController(const OgreNewt::Body* child, const Ogre::Vector3& pos)
782 {
783 CustomJoint* suppportJoint;
784
785 // make the joint matrix
786 dVector attachement(pos.x, pos.y, pos.z, 0.0f);
787
788 // crate a Newton Custom joint and set it at the support joint
789 suppportJoint = new CustomKinematicController(child->getNewtonBody(), attachement);
790 SetSupportJoint(suppportJoint);
791 }
792
796
798 {
799 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
800 joint->SetPickMode(mode);
801 }
802
804 {
805 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
806 joint->SetMaxLinearFriction(accel);
807 }
808
810 {
811 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
812 joint->SetMaxAngularFriction(alpha);
813 }
814
815
816 void KinematicController::setTargetPosit(const Ogre::Vector3& position)
817 {
818 dVector posit(position.x, position.y, position.z, 0.0f);
819 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
820 joint->SetTargetPosit(posit);
821 }
822
823 void KinematicController::setTargetRotation(const Ogre::Quaternion& rotation)
824 {
825 dQuaternion rotat(rotation.w, rotation.x, rotation.y, rotation.z);
826
827 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
828 joint->SetTargetRotation(rotat);
829 }
830
831
832 void KinematicController::setTargetMatrix(const Ogre::Vector3& position, const Ogre::Quaternion& rotation)
833 {
834 dMatrix matrix;
835 OgreNewt::Converters::QuatPosToMatrix(rotation, position, &matrix[0][0]);
836
837 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
838 joint->SetTargetMatrix(matrix);
839 }
840
841 void KinematicController::getTargetMatrix(Ogre::Vector3& position, Ogre::Quaternion& rotation) const
842 {
843 CustomKinematicController* joint = (CustomKinematicController*)GetSupportJoint();
844 dMatrix matrix(joint->GetTargetMatrix());
845
846 OgreNewt::Converters::MatrixToQuatPos(&matrix[0][0], rotation, position);
847 }
848
849
850
851#if 0
852 Ogre::Vector3 Slider::getJointForce() const
853 {
854 Ogre::Vector3 ret;
855
856 NewtonSliderGetJointForce(m_joint, &ret.x);
857
858 return ret;
859 }
860
861 unsigned _CDECL Slider::newtonCallback(const NewtonJoint* slider, NewtonHingeSliderUpdateDesc* desc)
862 {
863 Slider* me = (Slider*)NewtonJointGetUserData(slider);
864
865 me->m_desc = desc;
866 me->m_retval = 0;
867
868 if (me->m_callback)
869 (*me->m_callback)(me);
870
871 me->m_desc = NULL;
872
873 return me->m_retval;
874 }
875
876
878 void Slider::setCallbackAccel(Ogre::Real accel)
879 {
880 if (m_desc)
881 {
882 m_retval = 1;
883 m_desc->m_accel = (float)accel;
884 }
885 }
886
887 void Slider::setCallbackFrictionMin(Ogre::Real min)
888 {
889 if (m_desc)
890 {
891 m_retval = 1;
892 m_desc->m_minFriction = (float)min;
893 }
894 }
895
896 void Slider::setCallbackFrictionMax(Ogre::Real max)
897 {
898 if (m_desc)
899 {
900 m_retval = 1;
901 m_desc->m_maxFriction = (float)max;
902 }
903 }
904
905 Ogre::Real Slider::getCallbackTimestep() const
906 {
907 if (m_desc)
908 return (Ogre::Real)m_desc->m_timestep;
909 else
910 return 0.0;
911 }
912
913 Ogre::Real Slider::calculateStopAccel(Ogre::Real dist) const
914 {
915 if (m_desc)
916 return (Ogre::Real)NewtonSliderCalculateStopAccel(m_joint, m_desc, (float)dist);
917 else
918 return 0.0;
919 }
920
921
922
925
926
927
928 Universal::Universal(const World* world, const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos, const Ogre::Vector3& pin0, const Ogre::Vector3& pin1) : Joint()
929 {
930 m_world = world;
931
932 if (parent)
933 {
934 m_joint = NewtonConstraintCreateUniversal(world->getNewtonWorld(), &pos.x, &pin0.x, &pin1.x,
935 child->getNewtonBody(), parent->getNewtonBody());
936 }
937 else
938 {
939 m_joint = NewtonConstraintCreateUniversal(world->getNewtonWorld(), &pos.x, &pin0.x, &pin1.x,
940 child->getNewtonBody(), NULL);
941 }
942
943 NewtonJointSetUserData(m_joint, this);
944 NewtonJointSetDestructor(m_joint, destructor);
945 NewtonUniversalSetUserCallback(m_joint, newtonCallback);
946
947 m_callback = NULL;
948 }
949
953
954 Ogre::Vector3 Universal::getJointForce() const
955 {
956 Ogre::Vector3 ret;
957
958 NewtonUniversalGetJointForce(m_joint, &ret.x);
959
960 return ret;
961 }
962
963 unsigned _CDECL Universal::newtonCallback(const NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc)
964 {
965 Universal* me = (Universal*)NewtonJointGetUserData(universal);
966
967 me->m_desc = desc;
968 me->m_retval = 0;
969
970 if (me->m_callback)
971 (*me->m_callback)(me);
972
973 me->m_desc = NULL;
974
975 return me->m_retval;
976 }
977
978
980 void Universal::setCallbackAccel(Ogre::Real accel, unsigned int axis)
981 {
982 if (axis > 1) { return; }
983
984 if (m_desc)
985 {
986 m_retval |= axis;
987 m_desc[axis].m_accel = (float)accel;
988 }
989 }
990
991 void Universal::setCallbackFrictionMax(Ogre::Real max, unsigned int axis)
992 {
993 if (axis > 1) { return; }
994
995 if (m_desc)
996 {
997 m_retval |= axis;
998 m_desc[axis].m_maxFriction = (float)max;
999 }
1000 }
1001
1002 void Universal::setCallbackFrictionMin(Ogre::Real min, unsigned int axis)
1003 {
1004 if (axis > 1) { return; }
1005
1006 if (m_desc)
1007 {
1008 m_retval |= axis;
1009 m_desc[axis].m_minFriction = (float)min;
1010 }
1011 }
1012
1014 {
1015 if (m_desc)
1016 return (Ogre::Real)m_desc->m_timestep;
1017 else
1018 return 0.0;
1019 }
1020
1021 Ogre::Real Universal::calculateStopAlpha0(Ogre::Real angle) const
1022 {
1023 if (m_desc)
1024 return (Ogre::Real)NewtonUniversalCalculateStopAlpha0(m_joint, m_desc, (float)angle);
1025 else
1026 return 0.0;
1027 }
1028
1029 Ogre::Real Universal::calculateStopAlpha1(Ogre::Real angle) const
1030 {
1031 if (m_desc)
1032 return (Ogre::Real)NewtonUniversalCalculateStopAlpha1(m_joint, m_desc, (float)angle);
1033 else
1034 return 0.0;
1035 }
1036
1037
1040
1041
1042
1043 UpVector::UpVector(const World* world, const Body* body, const Ogre::Vector3& pin)
1044 {
1045 m_world = world;
1046
1047 m_joint = NewtonConstraintCreateUpVector(world->getNewtonWorld(), &pin.x, body->getNewtonBody());
1048
1049 NewtonJointSetUserData(m_joint, this);
1050 NewtonJointSetDestructor(m_joint, destructor);
1051
1052 }
1053
1055 {
1056 }
1057
1058 Ogre::Vector3 UpVector::getPin() const
1059 {
1060 Ogre::Vector3 ret;
1061
1062 NewtonUpVectorGetPin(m_joint, &ret.x);
1063
1064 return ret;
1065 }
1066
1067
1068#endif
1069
1070
1071
1072
1073
1074
1075
1076#if 0
1077
1080
1081
1082
1085
1086
1087 namespace PrebuiltCustomJoints
1088 {
1089
1090 Custom2DJoint::Custom2DJoint(const OgreNewt::Body* body, const Ogre::Vector3& pin) : CustomJoint(4, body, NULL)
1091 {
1092 mPin = pin;
1093 Ogre::Quaternion bodyorient;
1094 Ogre::Vector3 bodypos;
1095
1096 body->getPositionOrientation(bodypos, bodyorient);
1097
1098 pinAndDirToLocal(bodypos, pin, mLocalOrient0, mLocalPos0, mLocalOrient1, mLocalPos1);
1099
1100 // initialize variables
1101 mMin = mMax = Ogre::Degree(0);
1102 mLimitsOn = false;
1103 mAccel = 0.0f;
1104
1105 }
1106
1107
1108 void Custom2DJoint::submitConstraint(Ogre::Real timeStep, int threadIndex)
1109 {
1110 // get the global orientations.
1111 Ogre::Quaternion globalOrient0, globalOrient1;
1112 Ogre::Vector3 globalPos0, globalPos1;
1113
1114 localToGlobal(mLocalOrient0, mLocalPos0, globalOrient0, globalPos0, 0);
1115 localToGlobal(mLocalOrient1, mLocalPos1, globalOrient1, globalPos1, 1);
1116
1117 // calculate all main 6 vectors.
1118 Ogre::Vector3 bod0X = globalOrient0 * Ogre::Vector3(Ogre::Vector3::UNIT_X);
1119 Ogre::Vector3 bod0Y = globalOrient0 * Ogre::Vector3(Ogre::Vector3::UNIT_Y);
1120 Ogre::Vector3 bod0Z = globalOrient0 * Ogre::Vector3(Ogre::Vector3::UNIT_Z);
1121
1122 Ogre::Vector3 bod1X = globalOrient1 * Ogre::Vector3(Ogre::Vector3::UNIT_X);
1123 Ogre::Vector3 bod1Y = globalOrient1 * Ogre::Vector3(Ogre::Vector3::UNIT_Y);
1124 Ogre::Vector3 bod1Z = globalOrient1 * Ogre::Vector3(Ogre::Vector3::UNIT_Z);
1125
1126#ifdef _DEBUG
1127 Ogre::LogManager::getSingletonPtr()->logMessage(" Submit Constraint bod0X:" + Ogre::StringConverter::toString(bod0X) +
1128 " bod1X:" + Ogre::StringConverter::toString(bod1X));
1129#endif
1130
1131 // ---------------------------------------------------------------
1132 // first add a linear row to keep the body on the plane.
1133 addLinearRow(globalPos0, globalPos1, bod0X);
1134
1135 // have we strayed from the plane along the normal?
1136 Ogre::Plane thePlane(bod0X, globalPos0);
1137 Ogre::Real stray = thePlane.getDistance(globalPos1);
1138 if (stray > 0.0001f)
1139 {
1140 // we have strayed, apply acceleration to move back to 0 in one timestep.
1141 Ogre::Real accel = (stray / timeStep);
1142 if (thePlane.getSide(globalPos1) == Ogre::Plane::NEGATIVE_SIDE) { accel = -accel; }
1143
1144 setRowAcceleration(accel);
1145 }
1146
1147 // see if the main axis (pin) has wandered off.
1148 Ogre::Vector3 latDir = bod0X.crossProduct(bod1X);
1149 Ogre::Real latMag = latDir.squaredLength();
1150
1151 if (latMag > 1.0e-6f)
1152 {
1153 // has wandered a bit, we need to correct. first find the angle off.
1154 latMag = Ogre::Math::Sqrt(latMag);
1155 latDir.normalise();
1156 Ogre::Radian angle = Ogre::Math::ASin(latMag);
1157
1158 // ---------------------------------------------------------------
1159 addAngularRow(angle, latDir);
1160
1161 // ---------------------------------------------------------------
1162 // secondary correction for stability.
1163 Ogre::Vector3 latDir2 = latDir.crossProduct(bod1X);
1164 addAngularRow(Ogre::Radian(0.0f), latDir2);
1165 }
1166 else
1167 {
1168 // ---------------------------------------------------------------
1169 // no major change, just add 2 simple constraints.
1170 addAngularRow(Ogre::Radian(0.0f), bod1Y);
1171 addAngularRow(Ogre::Radian(0.0f), bod1Z);
1172 }
1173
1174 // calculate the current angle.
1175 Ogre::Real cos = bod0Y.dotProduct(bod1Y);
1176 Ogre::Real sin = (bod0Y.crossProduct(bod1Y)).dotProduct(bod0X);
1177
1178 mAngle = Ogre::Math::ATan2(sin, cos);
1179
1180 if (mLimitsOn)
1181 {
1182 if (mAngle > mMax)
1183 {
1184 Ogre::Radian diff = mAngle - mMax;
1185
1186 addAngularRow(diff, bod0X);
1187 setRowStiffness(1.0f);
1188 }
1189 else if (mAngle < mMin)
1190 {
1191 Ogre::Radian diff = mAngle - mMin;
1192
1193 addAngularRow(diff, bod0X);
1194 setRowStiffness(1.0f);
1195 }
1196 }
1197 else
1198 {
1199 if (mAccel != 0.0f)
1200 {
1201 addAngularRow(Ogre::Radian(0.0f), bod0X);
1202 setRowAcceleration(mAccel);
1203
1204 mAccel = 0.0f;
1205 }
1206 }
1207
1208 }
1209
1210
1211 CustomRigidJoint::CustomRigidJoint(OgreNewt::Body *child, OgreNewt::Body *parent, Ogre::Vector3 dir, Ogre::Vector3 pos) : OgreNewt::OgCustomJoint(6, child, parent)
1212 {
1213 // calculate local offsets.
1214 pinAndDirToLocal(pos, dir, mLocalOrient0, mLocalPos0, mLocalOrient1, mLocalPos1);
1215 }
1216
1220
1221 void CustomRigidJoint::submitConstraint(Ogre::Real timeStep, int threadIndex)
1222 {
1223 // get globals.
1224 Ogre::Vector3 globalPos0, globalPos1;
1225 Ogre::Quaternion globalOrient0, globalOrient1;
1226
1227 localToGlobal(mLocalOrient0, mLocalPos0, globalOrient0, globalPos0, 0);
1228 localToGlobal(mLocalOrient1, mLocalPos1, globalOrient1, globalPos1, 1);
1229
1230 // apply the constraints!
1231 addLinearRow(globalPos0, globalPos1, globalOrient0 * Ogre::Vector3::UNIT_X);
1232 addLinearRow(globalPos0, globalPos1, globalOrient0 * Ogre::Vector3::UNIT_Y);
1233 addLinearRow(globalPos0, globalPos1, globalOrient0 * Ogre::Vector3::UNIT_Z);
1234
1235 // now find a point off 10 units away.
1236 globalPos0 = globalPos0 + (globalOrient0 * (Ogre::Vector3::UNIT_X * 10.0f));
1237 globalPos1 = globalPos1 + (globalOrient1 * (Ogre::Vector3::UNIT_X * 10.0f));
1238
1239 // apply the constraints!
1240 addLinearRow(globalPos0, globalPos1, globalOrient0 * Ogre::Vector3::UNIT_Y);
1241 addLinearRow(globalPos0, globalPos1, globalOrient0 * Ogre::Vector3::UNIT_Z);
1242
1243 Ogre::Vector3 xdir0 = globalOrient0 * Ogre::Vector3::UNIT_X;
1244 Ogre::Vector3 xdir1 = globalOrient1 * Ogre::Vector3::UNIT_X;
1245
1246 Ogre::Radian angle = Ogre::Math::ACos(xdir0.dotProduct(xdir1));
1247 addAngularRow(angle, globalOrient0 * Ogre::Vector3::UNIT_X);
1248 }
1249
1250 /*
1251 CustomDryRollingFriction::CustomDryRollingFriction( OgreNewt::Body* child, Ogre::Real radius, Ogre::Real rollingFrictionCoefficient ) :
1252 OgreNewt::OgCustomJoint(1, child, NULL),
1253 mChild(child)
1254 {
1255 Ogre::Real mass;
1256 Ogre::Vector3 inertia;
1257
1258 child->getMassMatrix( mass, inertia );
1259
1260 mFrictionCoefficient = rollingFrictionCoefficient;
1261 mFrictionTorque = inertia.x * radius;
1262 }
1263
1264 CustomDryRollingFriction::~CustomDryRollingFriction()
1265 {
1266 }
1267
1268
1269 // copied from CustomDryRollingFriction joint in newton
1270 void CustomDryRollingFriction::submitConstraint( Ogre::Real timestep, int threadIndex )
1271 {
1272 Ogre::Vector3 omega;
1273 Ogre::Real omegaMag;
1274 Ogre::Real torqueFriction;
1275
1276
1277 omega = mChild->getOmega();
1278 omegaMag = omega.length();
1279
1280 if( omegaMag > 0.1f )
1281 {
1282 addAngularRow(Ogre::Radian(0), omega.normalisedCopy());
1283 setRowAcceleration( -omegaMag/timestep );
1284 torqueFriction = mFrictionTorque*mFrictionCoefficient;
1285 setRowMinimumFriction(-torqueFriction);
1286 setRowMaximumFriction(torqueFriction);
1287 }
1288 else
1289 {
1290 mChild->setOmega(omega*0.2f);
1291 }
1292
1293 }
1294 */
1295
1296
1297 } // end NAMESPACE PrebuiltCustomJoints
1298
1299
1300#endif
1301
1302
1303} // end NAMESPACE OgreNewt
1304
Ogre::Vector3 getJointAngle()
retrieve the current joint angle
Ogre::Vector3 getJointForce()
retrieve the current joint force.
Ogre::Vector3 getJointOmega()
retrieve the current joint omega
BallAndSocket(const OgreNewt::Body *child, const OgreNewt::Body *parent, const Ogre::Vector3 &pos)
constructor
Ogre::Vector3 getJointForce()
retrieve the current joint force.
void setLimits(Ogre::Radian maxCone, Ogre::Radian minTwist, Ogre::Radian maxTwist)
set limits for the joints rotation
Ogre::Vector3 getJointAngle()
retrieve the current joint angle
BallAndSocketLimits(const OgreNewt::Body *child, const OgreNewt::Body *parent, const Ogre::Vector3 &pos)
constructor
Ogre::Vector3 getJointOmega()
retrieve the current joint omega
main class for all Rigid Bodies in the system.
void addTorque(const Ogre::Vector3 &torque)
add torque to the body.
NewtonBody * getNewtonBody() const
get a pointer to the NewtonBody object
void getPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient) const
get position and orientation in form of an Ogre::Vector(position) and Ogre::Quaternion(orientation)
Ogre::Vector3 getJointOmega()
retrieve the current joint omega
void SetAngularVelocity(Ogre::Real omegaMag)
ControlledBallAndSocket(const OgreNewt::Body *child, const OgreNewt::Body *parent, const Ogre::Vector3 &pos)
constructor
Ogre::Vector3 getJointAngle()
retrieve the current joint angle
Ogre::Vector3 getJointForce()
retrieve the current joint force.
Ogre::Radian getJointAngularVelocity() const
get the relative joint angle around the hinge pin.
void setLimits(Ogre::Radian minAngle, Ogre::Radian maxAngle)
set minimum and maximum hinge limits.
Ogre::Radian m_desiredAngle
ConstraintType m_constraintType
void setDesiredOmega(Ogre::Radian omega, Ogre::Real strength=0.5f)
sets desired rotational velocity of the joint
void setTorque(Ogre::Real torque)
sets hinge torque
void setDesiredAngle(Ogre::Radian angle, Ogre::Real minFriction=0, Ogre::Real maxFriction=0)
set desired angle and optionally minimum and maximum friction
Hinge(const OgreNewt::Body *child, const OgreNewt::Body *parent, const Ogre::Vector3 &pos, const Ogre::Vector3 &pin)
constructor
Ogre::Radian m_desiredOmega
void setBrake(Ogre::Real maxForce=0)
apply hinge brake for one frame.
Ogre::Vector3 getJointPin() const
get the joint pin in global space
void enableLimits(bool state)
enable hinge limits.
virtual void submitConstraint(Ogre::Real timestep, int threadindex)
must be define for a functioning joint.
Ogre::Vector3 getJointForce()
retrieve the current joint force.
ConstraintType m_lastConstraintType
void enableMotor(bool state)
Ogre::Radian getJointAngle() const
get the relative joint angle around the hinge pin.
base class for all joints.
void setRowMaximumFriction(Ogre::Real friction) const
Body * getBody0() const
get the pointer to the first rigid body
void setRowAcceleration(Ogre::Real accel) const
CustomJoint * GetSupportJoint() const
GetSupportJoint.
void setRowMinimumFriction(Ogre::Real friction) const
void setRowStiffness(Ogre::Real stiffness) const
CustomJoint * m_joint
void addAngularRow(Ogre::Radian relativeAngleError, const Ogre::Vector3 &dir) const
void setRowSpringDamper(Ogre::Real springK, Ogre::Real springD) const
void addLinearRow(const Ogre::Vector3 &pt0, const Ogre::Vector3 &pt1, const Ogre::Vector3 &dir) const
void SetSupportJoint(CustomJoint *supportJoint)
SetSupportJoint.
Body * getBody1() const
get the pointer to the first rigid body
void setTargetPosit(const Ogre::Vector3 &position)
set the position part of the attachment matrix
void getTargetMatrix(Ogre::Vector3 &position, Ogre::Quaternion &rotation) const
set the position and orientation part of the attachment matrix
void setTargetMatrix(const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
set the position and orientation part of the attachment matrix
void setMaxLinearFriction(Ogre::Real accel)
set the linear acceleration the joint can take before the joint is violated .
void setMaxAngularFriction(Ogre::Real alpha)
set the angular acceleration the joint can take before the joint is violated .
void setTargetRotation(const Ogre::Quaternion &rotation)
set the orientation part of the attachment matrix
void setPickingMode(int mode)
enable limits.
KinematicController(const OgreNewt::Body *child, const Ogre::Vector3 &pos)
constructor
void pinAndDirToLocal(const Ogre::Vector3 &pinpt, const Ogre::Vector3 &pindir, Ogre::Quaternion &localOrient0, Ogre::Vector3 &localPos0, Ogre::Quaternion &localOrient1, Ogre::Vector3 &localPos1) const
void localToGlobal(const Ogre::Quaternion &localOrient, const Ogre::Vector3 &localPos, Ogre::Quaternion &globalOrient, Ogre::Vector3 &globalPos, int bodyIndex) const
virtual void submitConstraint(Ogre::Real timeStep, int threadIndex)
overloaded function that applies the actual constraint.
Custom2DJoint(const OgreNewt::Body *body, const Ogre::Vector3 &pin)
constructor
CustomRigidJoint(OgreNewt::Body *child, OgreNewt::Body *parent, Ogre::Vector3 dir, Ogre::Vector3 pos)
virtual void submitConstraint(Ogre::Real timeStep, int threadIndex)
must be define for a functioning joint.
Ogre::Real getDistance() const
void enableMotor(bool state)
enable motor.
void setMotorVelocity(Ogre::Real velocity, Ogre::Real strength)
void setSpring(Ogre::Real springStrength, Ogre::Real springDamping)
set spring strenght and damping
Slider(const OgreNewt::Body *child, const OgreNewt::Body *parent, const Ogre::Vector3 &pos, const Ogre::Vector3 &pin)
constructor
virtual void submitConstraint(Ogre::Real timestep, int threadindex)
must be define for a functioning joint.
Ogre::Vector3 getJointForce()
retrieve the current joint force.
void setLimits(Ogre::Real minStopDist, Ogre::Real maxStopDist)
set minimum and maximum stops limits.
void enableSpring(bool state)
enable spring.
void setFriction(Ogre::Real friction)
Ogre::Real getJointVelocity() const
get the relative joint angle around the hinge pin.
void enableLimits(bool state)
enable limits.
this class represents a Universal joint.
Ogre::Real calculateStopAlpha0(Ogre::Real angle) const
calculate the acceleration neccesary to stop the joint at the specified angle on pin 0.
static unsigned _CDECL newtonCallback(const NewtonJoint *universal, NewtonHingeSliderUpdateDesc *desc)
newton callback. used internally.
Universal(const World *world, const OgreNewt::Body *child, const OgreNewt::Body *parent, const Ogre::Vector3 &pos, const Ogre::Vector3 &pin0, const Ogre::Vector3 &pin1)
constructor
void setCallbackAccel(Ogre::Real accel, unsigned axis)
set the acceleration around a particular pin.
void setCallbackFrictionMax(Ogre::Real max, unsigned axis)
set the maximum friction around a particular pin.
Ogre::Vector3 getJointForce() const
get the force on the joint.
NewtonHingeSliderUpdateDesc * m_desc
Ogre::Real calculateStopAlpha1(Ogre::Real angle) const
calculate the acceleration neccesary to stop the joint at the specified angle on pin 1.
void setCallbackFrictionMin(Ogre::Real min, unsigned axis)
set the minimum friction around a particular pin
UniversalCallback m_callback
Ogre::Real getCallbackTimestep() const
get the current phsics timestep.
const Ogre::Vector3 & getPin() const
get the current pin direction.
UpVector(const Body *body, const Ogre::Vector3 &pin)
constructor
void setPin(const Ogre::Vector3 &pin)
set the pin direction.
represents a physics world.
NewtonWorld * getNewtonWorld() const
retrieves a pointer to the NewtonWorld
_OgreNewtExport void MatrixToQuatPos(const dFloat *matrix, Ogre::Quaternion &quat, Ogre::Vector3 &pos)
Take a Newton matrix and create a Quaternion + Position_vector.
_OgreNewtExport void QuatPosToMatrix(const Ogre::Quaternion &quat, const Ogre::Vector3 &pos, dFloat *matrix)
Take a Quaternion and Position Matrix and create a Newton-happy float matrix!