Project

General

Profile

SO3Engine
OgreNewt_BasicJoints.h
Go to the documentation of this file.
1/*
2 OgreNewt Library
3
4 Ogre implementation of Newton Game Dynamics SDK
5
6 OgreNewt basically has no license, you may use any or all of the library however you desire... I hope it can help you in any way.
7
8 by Walaber
9 some changes by melven
10
11*/
12#ifndef _INCLUDE_OGRENEWT_BASICJOINTS
13#define _INCLUDE_OGRENEWT_BASICJOINTS
14
16#include "OgreNewt_Joint.h"
17
18
19// OgreNewt namespace. all functions and classes use this namespace.
20namespace OgreNewt
21{
22
24
27 class _OgreNewtExport BallAndSocketLimits : public Joint
28 {
29 private:
30 public:
32
37 BallAndSocketLimits( const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos );
38
41
43 Ogre::Vector3 getJointAngle();
44
46 Ogre::Vector3 getJointOmega();
47
49
52 Ogre::Vector3 getJointForce();
53
55
60 void setLimits(Ogre::Radian maxCone, Ogre::Radian minTwist, Ogre::Radian maxTwist);
61 };
62
63
65
68 class _OgreNewtExport BallAndSocket : public Joint
69 {
70 private:
71 public:
73
78 BallAndSocket( const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos );
79
82
84 Ogre::Vector3 getJointAngle();
85
87 Ogre::Vector3 getJointOmega();
88
90
93 Ogre::Vector3 getJointForce();
94 };
95
97
100 class _OgreNewtExport ControlledBallAndSocket : public Joint
101 {
102 private:
103 public:
105
110 ControlledBallAndSocket( const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos );
111
114
116 Ogre::Vector3 getJointAngle();
117
119 Ogre::Vector3 getJointOmega();
120
122
125 Ogre::Vector3 getJointForce();
126
127 void SetAngularVelocity(Ogre::Real omegaMag);
128 Ogre::Real GetAngularVelocity() const;
129
130 void SetPitchAngle(Ogre::Real angle);
131 Ogre::Real GetPitchAngle() const;
132
133 void SetYawAngle(Ogre::Real angle);
134 Ogre::Real GetYawAngle() const;
135
136 void SetRollAngle(Ogre::Real angle);
137 Ogre::Real GetRollAngle() const;
138 };
139
141
144 class _OgreNewtExport Hinge : public Joint
145 {
146
147 public:
148
150
155 Hinge (const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos, const Ogre::Vector3& pin );
156
158 ~Hinge();
159
161 void enableLimits(bool state);
162
163 void enableMotor(bool state);
164
166 void setLimits(Ogre::Radian minAngle, Ogre::Radian maxAngle);
167
169 Ogre::Radian getJointAngle () const;
170
172
175 Ogre::Vector3 getJointForce();
176
178 Ogre::Radian getJointAngularVelocity () const;
179
181 Ogre::Vector3 getJointPin () const;
182
184 void setDesiredOmega(Ogre::Radian omega, Ogre::Real strength = 0.5f);
185
187 void setDesiredAngle(Ogre::Radian angle, Ogre::Real minFriction = 0, Ogre::Real maxFriction = 0);
188
190
194 void setTorque(Ogre::Real torque);
195
197 // 0: brake with infinite force
198 // > 0: brake with limited force
199 void setBrake(Ogre::Real maxForce = 0);
200
202 void clearConstraints() {m_constraintType = CONSTRAINT_NONE;}
203
204 virtual void submitConstraint(Ogre::Real timestep, int threadindex);
205
206 protected:
207 enum ConstraintType { CONSTRAINT_NONE, CONSTRAINT_OMEGA, CONSTRAINT_ANGLE, CONSTRAINT_BRAKE };
208
211
212 Ogre::Radian m_desiredOmega;
213 Ogre::Radian m_desiredAngle;
214
217 Ogre::Radian m_minAngle;
218 Ogre::Radian m_maxAngle;
219
220 Ogre::Real m_motorStrength;
221 Ogre::Real m_motorTorque;
224 Ogre::Real m_brakeMaxForce;
225
227 };
228
229
231
234 class _OgreNewtExport Slider : public Joint
235 {
236
237 public:
238
240
245 Slider(const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos, const Ogre::Vector3& pin );
246
248 ~Slider();
249
251 void enableLimits(bool state);
252
253 void setFriction(Ogre::Real friction);
254
256 void enableMotor(bool state);
257
258 void setMotorVelocity(Ogre::Real velocity, Ogre::Real strength);
259
261 void setLimits(Ogre::Real minStopDist, Ogre::Real maxStopDist);
262
264 void enableSpring(bool state);
265
267 void setSpring(Ogre::Real springStrength, Ogre::Real springDamping);
268
270
273 Ogre::Vector3 getJointForce();
274
276 Ogre::Real getJointVelocity() const;
277
278 Ogre::Real getDistance() const;
279
280 virtual void submitConstraint(Ogre::Real timestep, int threadindex);
281
282
283 private:
284 bool m_useLimits;
285 Ogre::Real m_minDist;
286 Ogre::Real m_maxDist;
287 bool m_useSpring;
288 Ogre::Real m_springStrength;
289 Ogre::Real m_springDamping;
290 };
291
292
294
297 class _OgreNewtExport UpVector : public Joint
298 {
299 public:
301 /*
302 \param world pointer to the OgreNewt::World.
303 \param body pointer to the body to apply the upvector to.
304 \param pin direction of the upvector in global space.
305 */
306 UpVector( const Body* body, const Ogre::Vector3& pin );
307
309 ~UpVector();
310
312 /*
313 by calling this function in realtime, you can effectively "animate" the pin.
314 */
315 void setPin( const Ogre::Vector3& pin );
316
318 const Ogre::Vector3& getPin() const;
319
320 private:
321 Ogre::Vector3 m_pin;
322 };
323
324#if 0
326
329 class _OgreNewtExport Universal : public Joint
330 {
331
332 public:
333
335
338 typedef void(*UniversalCallback)( Universal* me );
339
341
349 Universal( const World* world, const OgreNewt::Body* child, const OgreNewt::Body* parent, const Ogre::Vector3& pos, const Ogre::Vector3& pin0, const Ogre::Vector3& pin1 );
350
352 ~Universal();
353
355 Ogre::Radian getJointAngle0() const { return Ogre::Radian(NewtonUniversalGetJointAngle0( m_joint )); }
356
358 Ogre::Radian getJointAngle1() const { return Ogre::Radian(NewtonUniversalGetJointAngle1( m_joint )); }
359
361 Ogre::Real getJointOmega0() const { return (Ogre::Real)NewtonUniversalGetJointOmega0( m_joint ); }
362
364 Ogre::Real getJointOmega1() const { return (Ogre::Real)NewtonUniversalGetJointOmega1( m_joint ); }
365
367 Ogre::Vector3 getJointForce() const;
368
370
375 void setCallback( UniversalCallback callback ) { m_callback = callback; }
376
378 // the following commands are only valid from inside a hinge callback function
379
381 /*
382 this function can only be called from within a custom callback.
383 \param accel desired acceleration
384 \param axis which pin to use (0 or 1)
385 */
386 void setCallbackAccel( Ogre::Real accel, unsigned axis );
387
389 /*
390 this function can only be called from within a custom callback.
391 \param min minimum friction
392 \param axis which pin to use (0 or 1)
393 */
394 void setCallbackFrictionMin( Ogre::Real min, unsigned axis );
395
397 /*
398 this function can only be called from within a custom callback.
399 \param max maximum friction
400 \param axis which pin to use (0 or 1)
401 */
402 void setCallbackFrictionMax( Ogre::Real max, unsigned axis );
403
405 /*
406 this function can only be called from within a custom callback.
407 */
408 Ogre::Real getCallbackTimestep() const;
409
411
415 Ogre::Real calculateStopAlpha0( Ogre::Real angle ) const;
416
418
422 Ogre::Real calculateStopAlpha1( Ogre::Real angle ) const;
423
424 protected:
425
427 static unsigned _CDECL newtonCallback( const NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc );
428
429 UniversalCallback m_callback;
430 NewtonHingeSliderUpdateDesc* m_desc;
431
432 unsigned m_retval;
433 };
434
435
436
438
441 class _OgreNewtExport UpVector : public Joint
442 {
443
444 public:
446 /*
447 \param world pointer to the OgreNewt::World.
448 \param body pointer to the body to apply the upvector to.
449 \param pin direction of the upvector in global space.
450 */
451 UpVector( const World* world, const Body* body, const Ogre::Vector3& pin );
452
455
457 /*
458 by calling this function in realtime, you can effectively "animate" the pin.
459 */
460 void setPin( const Ogre::Vector3& pin ) const { NewtonUpVectorSetPin( m_joint, &pin.x ); }
461
463 Ogre::Vector3 getPin() const;
464 };
465
466
467
469 namespace PrebuiltCustomJoints
470 {
471
473
478 class _OgreNewtExport Custom2DJoint : public OgreNewt::OgCustomJoint
479 {
480 public:
482 Custom2DJoint( const OgreNewt::Body* body, const Ogre::Vector3& pin );
483
486
488 virtual void submitConstraint( Ogre::Real timeStep, int threadIndex );
489
491 Ogre::Radian getAngle() const { return mAngle; }
492
494 void setLimits( Ogre::Degree min, Ogre::Degree max ) { mMin = min, mMax = max; }
495
497 void setLimitsOn( bool onoff ) { mLimitsOn = onoff; }
498
500 bool getLimitsOn() const { return mLimitsOn; }
501
503 void addAccel( Ogre::Real accel ) { mAccel = accel; }
504
507 void resetAngle() { mAngle = Ogre::Radian(0.0f); }
508
510 Ogre::Vector3 getPin() { return mPin; }
511
512 private:
513 Ogre::Vector3 mPin;
514 Ogre::Quaternion mLocalOrient0, mLocalOrient1;
515 Ogre::Vector3 mLocalPos0, mLocalPos1;
516
517 Ogre::Radian mAngle;
518
519 Ogre::Radian mMin;
520 Ogre::Radian mMax;
521
522 bool mLimitsOn;
523
524 Ogre::Real mAccel;
525 };
526
528
532 class _OgreNewtExport CustomRigidJoint : public OgreNewt::OgCustomJoint
533 {
534 public:
535 CustomRigidJoint( OgreNewt::Body* child, OgreNewt::Body* parent, Ogre::Vector3 dir, Ogre::Vector3 pos);
537
538 virtual void submitConstraint( Ogre::Real timeStep, int threadIndex );
539
540 private:
541 Ogre::Vector3 mLocalPos0;
542 Ogre::Vector3 mLocalPos1;
543
544 Ogre::Quaternion mLocalOrient0;
545 Ogre::Quaternion mLocalOrient1;
546 };
547
549
554 /* // not tested yet
555 class _OgreNewtExport CustomDryRollingFriction : public OgreNewt::OgCustomJoint
556 {
557 public:
558 CustomDryRollingFriction( OgreNewt::Body* child, Ogre::Real radius, Ogre::Real rollingFrictionCoefficient );
559 ~CustomDryRollingFriction();
560
561 virtual void submitConstraint( Ogre::Real timestep, int threadIndex );
562
563 private:
564 Ogre::Real mFrictionCoefficient;
565 Ogre::Real mFrictionTorque;
566 OgreNewt::Body* mChild;
567 };
568 */
569
570 } // end NAMESPACE PrebuiltCustomJoints
571
572#endif
573
574
576
579 class _OgreNewtExport KinematicController : public Joint
580 {
581
582 public:
583
585
589 KinematicController(const OgreNewt::Body* child, const Ogre::Vector3& pos);
590
593
595
598 void setPickingMode (int mode);
599
601
604 void setMaxLinearFriction(Ogre::Real accel);
605
607
610 void setMaxAngularFriction(Ogre::Real alpha);
611
613
616 void setTargetPosit (const Ogre::Vector3& position);
617
619
622 void setTargetRotation (const Ogre::Quaternion& rotation);
623
625
629 void setTargetMatrix (const Ogre::Vector3& position, const Ogre::Quaternion& rotation);
630
632
636 void getTargetMatrix (Ogre::Vector3& position, Ogre::Quaternion& rotation) const;
637
638 };
639
640} // end NAMESPACE OgreNewt
641
642#endif
643// _INCLUDE_OGRENEWT_BASICJOINTS
644
Ball and Socket joint.
main class for all Rigid Bodies in the system.
Ogre::Radian m_desiredAngle
ConstraintType m_constraintType
Ogre::Radian m_desiredOmega
void clearConstraints()
clears the motor constraints
ConstraintType m_lastConstraintType
base class for all joints.
Kinematic controller joint.
void setLimits(Ogre::Degree min, Ogre::Degree max)
set rotational limits for the joint.
bool getLimitsOn() const
returns whether limits are turned on or off for the joint.
Ogre::Radian getAngle() const
get the current angle of the joint.
void addAccel(Ogre::Real accel)
adds rotational acceleration to the joint (like a motor)
void setLimitsOn(bool onoff)
sets whether to enable limits or not for the joint.
this class represents a Universal joint.
void setCallback(UniversalCallback callback)
set a custom callback for controlling this joint.
NewtonHingeSliderUpdateDesc * m_desc
Ogre::Radian getJointAngle0() const
get the angle around pin0.
Ogre::Real getJointOmega0() const
get the rotational velocity around pin0.
UniversalCallback m_callback
Ogre::Real getJointOmega1() const
get the rotational velocity around pin1.
Ogre::Radian getJointAngle1() const
get the angle around pin1.
Ogre::Vector3 getPin() const
get the current pin direction.
~UpVector()
destructor
void setPin(const Ogre::Vector3 &pin) const
set the pin direction.
represents a physics world.