Project

General

Profile

SO3Engine
SO3BallAndSocketContraint.cpp
Go to the documentation of this file.
1
10
11namespace SO3
12{
13
14SBallAndSocketContraint::SBallAndSocketContraint() : SPhysicContraint(0, 0, 0, SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
15{
16 // Forbiden, private.
17}
18
19SBallAndSocketContraint::SBallAndSocketContraint(SScene* scene, SBody* son, SBody* parent, Ogre::Vector3 position, bool useLimits) : SPhysicContraint(scene, son, parent, SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
20{
21 mPosition = position;
22 mConeAngle = 0.0f;
23 mMinTwist = 0.0f;
24 mMaxTwist = 0.0f;
25 mUseLimits = useLimits;
26 mControlled = false;
27
28 UpdateJoint();
29}
30
32{
33 //mjoint deleted in SPhysicContraint
34}
35
37{
38 mParentBody = body;
39
40 UpdateJoint();
41}
42
44{
45 mSonBody = body;
46
47 UpdateJoint();
48}
49
51{
52 if (mJoint && mControlled)
53 {
55 }
56}
57
59{
60 if (mJoint && mControlled)
61 {
63 }
64 else
65 return 0.0f;
66}
67
69{
70 if (mJoint && mControlled)
71 {
73 }
74}
75
77{
78 if (mJoint && mControlled)
79 {
81 }
82 else
83 return 0.0f;
84}
85
87{
88 if (mJoint && mControlled)
89 {
91 }
92}
93
95{
96 if (mJoint && mControlled)
97 {
99 }
100 else
101 return 0.0f;
102}
103
105{
106 if (mJoint && mControlled)
107 {
109 }
110}
111
113{
114 if (mJoint && mControlled)
115 {
117 }
118 else
119 return 0.0f;
120}
121
122void SBallAndSocketContraint::UpdateJoint()
123{
125 SAFE_DELETE(mJoint);
126
127 if (mSonBody)
128 {
129 OgreNewt::Body* bparent = mParentBody != NULL ? mParentBody->getOgreNewtBodyPointer() : NULL;
130 if (mControlled)
131 {
132 mJoint = static_cast<OgreNewt::Joint*> (new OgreNewt::ControlledBallAndSocket(mSonBody->getOgreNewtBodyPointer(), bparent, mPosition));
133 }
134 else if (mUseLimits)
135 {
136 mJoint = static_cast<OgreNewt::Joint*> (new OgreNewt::BallAndSocketLimits(mSonBody->getOgreNewtBodyPointer(), bparent, mPosition));
137 static_cast<OgreNewt::BallAndSocketLimits*>(mJoint)->setLimits(mConeAngle, mMinTwist, mMaxTwist);
138 }
139 else
140 {
141 mJoint = static_cast<OgreNewt::Joint*> (new OgreNewt::BallAndSocket(mSonBody->getOgreNewtBodyPointer(), bparent, mPosition));
142 }
143 }
144}
145
147{
148 if (state != mUseLimits)
149 {
150 mUseLimits = state;
151 UpdateJoint();
152 }
153}
154
156{
157 if (state != mControlled)
158 {
159 mControlled = state;
160 UpdateJoint();
161 }
162}
163
164void SBallAndSocketContraint::SetLimits(Ogre::Radian maxCone, Ogre::Radian minTwist, Ogre::Radian maxTwist)
165{
166 mConeAngle = maxCone;
167 mMinTwist = minTwist;
168 mMaxTwist = maxTwist;
169
170 if (mJoint != 0 && !mControlled && mUseLimits)
171 static_cast<OgreNewt::BallAndSocketLimits*>(mJoint)->setLimits(mConeAngle, mMinTwist, mMaxTwist);
172}
173
175{
176 if (mJoint == NULL)
177 return Ogre::Vector3::ZERO;
178 else if (mControlled)
179 return static_cast<OgreNewt::ControlledBallAndSocket*>(mJoint)->getJointAngle();
180 else if (mUseLimits)
181 return static_cast<OgreNewt::BallAndSocketLimits*>(mJoint)->getJointAngle();
182 else
183 return static_cast<OgreNewt::BallAndSocket*>(mJoint)->getJointAngle();
184}
185
187{
188 if (mJoint == NULL)
189 return Ogre::Vector3::ZERO;
190 else if (mControlled)
191 return static_cast<OgreNewt::ControlledBallAndSocket*>(mJoint)->getJointOmega();
192 else if (mUseLimits)
193 return static_cast<OgreNewt::BallAndSocketLimits*>(mJoint)->getJointOmega();
194 else
195 return static_cast<OgreNewt::BallAndSocket*>(mJoint)->getJointOmega();
196}
197
199{
200 if (mJoint == NULL)
201 return Ogre::Vector3::ZERO;
202 else if (mControlled)
203 return static_cast<OgreNewt::ControlledBallAndSocket*>(mJoint)->getJointForce();
204 else if (mUseLimits)
205 return static_cast<OgreNewt::BallAndSocketLimits*>(mJoint)->getJointForce();
206 else
207 return static_cast<OgreNewt::BallAndSocket*>(mJoint)->getJointForce();
208}
209
210}
Ball and Socket joint.
main class for all Rigid Bodies in the system.
base class for all joints.
void waitForUpdateToFinish() const
void SetAngularVelocity(Ogre::Real omegaMag)
void SetLimits(Ogre::Radian maxCone, Ogre::Radian minTwist, Ogre::Radian maxTwist)
virtual void SetParentBody(SBody *body)
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
OgreNewt::Joint * mJoint
OgreNewt::World * GetPhysicWorld()
SPhysicWorld * GetPhysicsWorld()
Manage Physics Contraint. .