Project

General

Profile

SO3Engine
SO3HingeContraint.cpp
Go to the documentation of this file.
1
10
11namespace SO3
12{
13
14 SHingeContraint::SHingeContraint() : SPhysicContraint(0, 0, 0, SPhysicContraint::SO3_HINGE_CONTRAINT)
15{
16 // Forbiden, private.
17}
18
19SHingeContraint::SHingeContraint(SScene* scene, SBody* son, SBody* parent, Ogre::Vector3 position, Ogre::Vector3 pin, bool useLimits) : SPhysicContraint(scene, son, parent, SPhysicContraint::SO3_HINGE_CONTRAINT)
20{
21 mPosition = position;
22 mPin = pin;
23 mUseLimits = useLimits;
24 mUseMotor = false;
25
26 UpdateJoint();
27}
28
30{
31 //mjoint deleted in SPhysicContraint
32}
33
35{
36 mParentBody = body;
37
38 UpdateJoint();
39}
40
42{
43 mSonBody = body;
44
45 UpdateJoint();
46}
47
48void SHingeContraint::UpdateJoint()
49{
51 SAFE_DELETE(mJoint);
52
53 if (mSonBody)
54 {
55 OgreNewt::Body* bparent = mParentBody != NULL ? mParentBody->getOgreNewtBodyPointer() : NULL;
56 mJoint = static_cast<OgreNewt::Joint*> (new OgreNewt::Hinge(mSonBody->getOgreNewtBodyPointer(), bparent, mPosition, mPin));
57 static_cast<OgreNewt::Hinge*>(mJoint)->enableLimits(mUseLimits);
58 static_cast<OgreNewt::Hinge*>(mJoint)->enableMotor(mUseMotor);
59 }
60}
61
63{
64 mUseLimits = state;
65 if (mJoint != NULL)
66 static_cast<OgreNewt::Hinge*>(mJoint)->enableLimits(mUseLimits);
67}
68
69void SHingeContraint::SetLimits(Ogre::Radian minAngle, Ogre::Radian maxAngle)
70{
71 if (minAngle > maxAngle)
72 minAngle = maxAngle;
73
74 if (mJoint != NULL)
75 static_cast<OgreNewt::Hinge*>(mJoint)->setLimits(minAngle, maxAngle);
76}
77
79{
80 if (mJoint == NULL)
81 return Ogre::Radian(0.0f);
82 else
83 return static_cast<OgreNewt::Hinge*>(mJoint)->getJointAngle();
84}
85
87{
88 if (mJoint == NULL)
89 return Ogre::Radian(0.0f);
90 else
91 return static_cast<OgreNewt::Hinge*>(mJoint)->getJointAngularVelocity();
92}
93
95{
96 if (mJoint == NULL)
97 return Ogre::Vector3::ZERO;
98 else
99 return static_cast<OgreNewt::Hinge*>(mJoint)->getJointForce();
100}
101
103{
104 if (mJoint == NULL)
105 return Ogre::Vector3::ZERO;
106 else
107 return static_cast<OgreNewt::Hinge*>(mJoint)->getJointPin();
108}
109
110void SHingeContraint::SetMotorOmega(Ogre::Radian omega, Ogre::Real strength)
111{
112 if (mJoint != NULL)
113 static_cast<OgreNewt::Hinge*>(mJoint)->setDesiredOmega(omega, strength);
114}
115
116void SHingeContraint::SetMotorAngle(Ogre::Radian angle, Ogre::Real minFriction, Ogre::Real maxFriction)
117{
118 if (mJoint != NULL)
119 static_cast<OgreNewt::Hinge*>(mJoint)->setDesiredAngle(angle, minFriction, maxFriction);
120}
121
122void SHingeContraint::SetTorque(Ogre::Real torque)
123{
124 if (mJoint != NULL)
125 static_cast<OgreNewt::Hinge*>(mJoint)->setTorque(torque);
126}
127
128void SHingeContraint::SetBrake(Ogre::Real maxForce)
129{
130 if (mJoint != NULL)
131 static_cast<OgreNewt::Hinge*>(mJoint)->setBrake(maxForce);
132}
133
135{
136 mUseMotor = state;
137 if (mJoint != NULL)
138 static_cast<OgreNewt::Hinge*>(mJoint)->enableMotor(mUseMotor);
139}
140
141}
main class for all Rigid Bodies in the system.
base class for all joints.
void waitForUpdateToFinish() const
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
void SetMotorOmega(Ogre::Radian omega, Ogre::Real strength=0.5f)
void SetMotorAngle(Ogre::Radian angle, Ogre::Real minFriction=0, Ogre::Real maxFriction=0)
virtual void SetParentBody(SBody *body)
void SetTorque(Ogre::Real torque)
Ogre::Radian GetAngularVelocity()
void UseLimits(bool state)
void SetBrake(Ogre::Real maxForce=0)
void SetLimits(Ogre::Radian maxAngle, Ogre::Radian minAngle)
virtual void SetSonBody(SBody *body)
OgreNewt::Joint * mJoint
OgreNewt::World * GetPhysicWorld()
SPhysicWorld * GetPhysicsWorld()
Manage Physics Contraint. .