1 | #ifndef _OGREODEJOINT_H_ |
---|
2 | #define _OGREODEJOINT_H_ |
---|
3 | |
---|
4 | #include "OgreOdePreReqs.h" |
---|
5 | #include "OgreOdeMaintainedList.h" |
---|
6 | |
---|
7 | namespace OgreOde |
---|
8 | { |
---|
9 | class _OgreOdeExport JointGroup |
---|
10 | { |
---|
11 | friend class World; |
---|
12 | friend class Joint; |
---|
13 | |
---|
14 | public: |
---|
15 | JointGroup(World *world); |
---|
16 | virtual ~JointGroup(); |
---|
17 | |
---|
18 | void empty(); |
---|
19 | |
---|
20 | virtual size_t getID(); |
---|
21 | |
---|
22 | protected: |
---|
23 | dJointGroupID getJointGroupID() const; |
---|
24 | |
---|
25 | protected: |
---|
26 | dJointGroupID _joint_group; |
---|
27 | World *_world; |
---|
28 | }; |
---|
29 | |
---|
30 | class _OgreOdeExport Joint |
---|
31 | { |
---|
32 | friend class World; |
---|
33 | |
---|
34 | public: |
---|
35 | enum Type |
---|
36 | { |
---|
37 | Type_BallJoint = dJointTypeBall, |
---|
38 | Type_HingeJoint = dJointTypeHinge, |
---|
39 | Type_SliderJoint = dJointTypeSlider, |
---|
40 | Type_UniversalJoint = dJointTypeUniversal, |
---|
41 | Type_Suspension_Joint = dJointTypeHinge2, |
---|
42 | Type_FixedJoint = dJointTypeFixed, |
---|
43 | Type_AngularMotorJoint = dJointTypeAMotor, |
---|
44 | Type_PlanarJoint = dJointTypePlane2D, |
---|
45 | #if ODE_VERSION_MINOR > 9 |
---|
46 | Type_SliderHingeJoint = dJointTypePR, |
---|
47 | Type_SliderUniversalJoint = dJointTypePU, |
---|
48 | Type_PistonJoint = dJointTypePiston |
---|
49 | #else |
---|
50 | Type_SliderHingeJoint = dJointTypePR |
---|
51 | #endif |
---|
52 | }; |
---|
53 | |
---|
54 | enum Parameter |
---|
55 | { |
---|
56 | Parameter_LowStop = dParamLoStop, |
---|
57 | Parameter_HighStop = dParamHiStop, |
---|
58 | Parameter_MotorVelocity = dParamVel, |
---|
59 | Parameter_MaximumForce = dParamFMax, |
---|
60 | Parameter_FudgeFactor = dParamFudgeFactor, |
---|
61 | Parameter_Bounceyness = dParamBounce, |
---|
62 | Parameter_CFM = dParamCFM, |
---|
63 | Parameter_ERP = dParamERP, |
---|
64 | Parameter_StopERP = dParamStopERP, |
---|
65 | Parameter_StopCFM = dParamStopCFM, |
---|
66 | Parameter_SuspensionERP = dParamSuspensionERP, // SuspensionJoint |
---|
67 | Parameter_SuspensionCFM = dParamSuspensionCFM // SuspensionJoint |
---|
68 | }; |
---|
69 | |
---|
70 | public: |
---|
71 | Joint(World *world, const JointGroup* group = 0); |
---|
72 | virtual ~Joint(); |
---|
73 | |
---|
74 | Joint::Type getType(); |
---|
75 | |
---|
76 | void registerJoint(); |
---|
77 | |
---|
78 | void detach(); |
---|
79 | virtual void attach(const Body* body); |
---|
80 | virtual void attach(const Body* body_a,const Body* body_b); |
---|
81 | |
---|
82 | Body* getFirstBody(); |
---|
83 | Body* getSecondBody(); |
---|
84 | |
---|
85 | static bool areConnected(const Body* body_a,const Body* body_b); |
---|
86 | static bool areConnectedExcluding(const Body* body_a,const Body* body_b,Joint::Type joint_type); |
---|
87 | |
---|
88 | void enableFeedback(); |
---|
89 | void disableFeedback(); |
---|
90 | const Ogre::Vector3& getFirstForce(); |
---|
91 | const Ogre::Vector3& getFirstTorque(); |
---|
92 | const Ogre::Vector3& getSecondForce(); |
---|
93 | const Ogre::Vector3& getSecondTorque(); |
---|
94 | |
---|
95 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
96 | virtual const Ogre::Vector3& getAnchor(); |
---|
97 | virtual const Ogre::Vector3& getAnchorError(); |
---|
98 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
99 | virtual const Ogre::Vector3& getAxis(); |
---|
100 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
101 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
102 | virtual Ogre::Real getAngle(); |
---|
103 | virtual Ogre::Real getAngleRate(); |
---|
104 | virtual Ogre::Real getPosition(); |
---|
105 | virtual Ogre::Real getPositionRate(); |
---|
106 | |
---|
107 | virtual void setParameter(Joint::Parameter parameter,Ogre::Real value,int axis = 1); |
---|
108 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
109 | |
---|
110 | virtual size_t getID(); |
---|
111 | |
---|
112 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
113 | virtual void addForce(Ogre::Real force, Ogre::Real force2 = 0.0, Ogre::Real force3 = 0.0); |
---|
114 | |
---|
115 | protected: |
---|
116 | dJointID getJointID(); |
---|
117 | |
---|
118 | dWorldID getWorldID(); |
---|
119 | dJointGroupID getJointGroupID(const JointGroup* group) const; |
---|
120 | |
---|
121 | protected: |
---|
122 | dJointID _joint; |
---|
123 | dJointFeedback _feedback; |
---|
124 | Ogre::Vector3 _axis,_anchor,_anchor_error,_additional_axis; |
---|
125 | Ogre::Vector3 _first_force,_first_torque,_second_force,_second_torque; |
---|
126 | World *_world; |
---|
127 | }; |
---|
128 | |
---|
129 | class _OgreOdeExport BallJoint:public Joint |
---|
130 | { |
---|
131 | public: |
---|
132 | BallJoint(World *world, const JointGroup* group = 0); |
---|
133 | ~BallJoint(); |
---|
134 | |
---|
135 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
136 | virtual const Ogre::Vector3& getAnchor(); |
---|
137 | virtual const Ogre::Vector3& getAnchorError(); |
---|
138 | |
---|
139 | // as of ode-0.9 can set Parameter_CFM and Parameter_ERP to make the joint springy, an axis value isn't needed |
---|
140 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
141 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
142 | }; |
---|
143 | |
---|
144 | class _OgreOdeExport HingeJoint:public Joint |
---|
145 | { |
---|
146 | public: |
---|
147 | HingeJoint(World *world, const JointGroup* group = 0); |
---|
148 | ~HingeJoint(); |
---|
149 | |
---|
150 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
151 | virtual const Ogre::Vector3& getAnchor(); |
---|
152 | virtual const Ogre::Vector3& getAnchorError(); |
---|
153 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
154 | virtual const Ogre::Vector3& getAxis(); |
---|
155 | virtual Ogre::Real getAngle(); |
---|
156 | virtual Ogre::Real getAngleRate(); |
---|
157 | |
---|
158 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
159 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
160 | |
---|
161 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
162 | }; |
---|
163 | |
---|
164 | class _OgreOdeExport SliderJoint:public Joint |
---|
165 | { |
---|
166 | public: |
---|
167 | SliderJoint(World *world, const JointGroup* group = 0); |
---|
168 | ~SliderJoint(); |
---|
169 | |
---|
170 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
171 | virtual const Ogre::Vector3& getAxis(); |
---|
172 | virtual Ogre::Real getPosition(); |
---|
173 | virtual Ogre::Real getPositionRate(); |
---|
174 | |
---|
175 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
176 | virtual Ogre::Real getParameter(Joint::Parameter parameter, int axis = 1); |
---|
177 | |
---|
178 | virtual void addForce(Ogre::Real force, Ogre::Real force2 = 0.0, Ogre::Real force3 = 0.0); |
---|
179 | }; |
---|
180 | |
---|
181 | class _OgreOdeExport UniversalJoint:public Joint |
---|
182 | { |
---|
183 | public: |
---|
184 | UniversalJoint(World *world, const JointGroup* group = 0); |
---|
185 | ~UniversalJoint(); |
---|
186 | |
---|
187 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
188 | virtual const Ogre::Vector3& getAnchor(); |
---|
189 | virtual const Ogre::Vector3& getAnchorError(); |
---|
190 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
191 | virtual const Ogre::Vector3& getAxis(); |
---|
192 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
193 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
194 | |
---|
195 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value, int axis = 1); |
---|
196 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
197 | |
---|
198 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
199 | }; |
---|
200 | |
---|
201 | class _OgreOdeExport FixedJoint:public Joint |
---|
202 | { |
---|
203 | public: |
---|
204 | FixedJoint(World *world, const JointGroup* group = 0); |
---|
205 | ~FixedJoint(); |
---|
206 | |
---|
207 | virtual void attach(const Body* body); |
---|
208 | virtual void attach(const Body* body_a,const Body* body_b); |
---|
209 | }; |
---|
210 | |
---|
211 | class _OgreOdeExport SuspensionJoint:public Joint |
---|
212 | { |
---|
213 | public: |
---|
214 | SuspensionJoint(World *world, const JointGroup* group = 0); |
---|
215 | ~SuspensionJoint(); |
---|
216 | |
---|
217 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
218 | virtual const Ogre::Vector3& getAnchor(); |
---|
219 | virtual const Ogre::Vector3& getAdditionalAnchor(); |
---|
220 | virtual const Ogre::Vector3& getAnchorError(); |
---|
221 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
222 | virtual const Ogre::Vector3& getAxis(); |
---|
223 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
224 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
225 | virtual Ogre::Real getAngle(); |
---|
226 | virtual Ogre::Real getAngleRate(); |
---|
227 | virtual Ogre::Real getPositionRate(); |
---|
228 | |
---|
229 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
230 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
231 | |
---|
232 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
233 | |
---|
234 | protected: |
---|
235 | Ogre::Vector3 _anchor2; |
---|
236 | }; |
---|
237 | |
---|
238 | class _OgreOdeExport AngularMotorJoint:public Joint |
---|
239 | { |
---|
240 | public: |
---|
241 | enum Mode |
---|
242 | { |
---|
243 | Mode_UserAngularMotor = dAMotorUser, |
---|
244 | Mode_EulerAngularMotor = dAMotorEuler |
---|
245 | }; |
---|
246 | |
---|
247 | enum RelativeOrientation |
---|
248 | { |
---|
249 | RelativeOrientation_GlobalFrame = 0, |
---|
250 | RelativeOrientation_FirstBody = 1, |
---|
251 | RelativeOrientation_SecondBody = 2 |
---|
252 | }; |
---|
253 | |
---|
254 | public: |
---|
255 | AngularMotorJoint(World *world, const JointGroup* group = 0); |
---|
256 | ~AngularMotorJoint(); |
---|
257 | |
---|
258 | void setMode(AngularMotorJoint::Mode mode); |
---|
259 | AngularMotorJoint::Mode getMode(); |
---|
260 | |
---|
261 | void setAxisCount(int axes); |
---|
262 | int getAxisCount(); |
---|
263 | |
---|
264 | void setAxis(int axis_number,AngularMotorJoint::RelativeOrientation orientation,const Ogre::Vector3& axis); |
---|
265 | const Ogre::Vector3& getAxis(int axis_number); |
---|
266 | AngularMotorJoint::RelativeOrientation getAxisRelativeOrientation(int axis_number); |
---|
267 | |
---|
268 | void setAngle(int axis, Ogre::Real angle); |
---|
269 | Ogre::Real getAngle(int axis); |
---|
270 | Ogre::Real getAngleRate(int axis); |
---|
271 | |
---|
272 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
273 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
274 | |
---|
275 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
276 | }; |
---|
277 | |
---|
278 | /** Planar joints are for 2D physics in the x, y plane wth z=0 |
---|
279 | */ |
---|
280 | class _OgreOdeExport PlanarJoint:public Joint |
---|
281 | { |
---|
282 | public: |
---|
283 | PlanarJoint(World *world, const JointGroup* group = 0); |
---|
284 | ~PlanarJoint(); |
---|
285 | |
---|
286 | virtual void setParameterX(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
287 | virtual void setParameterY(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
288 | virtual void setParameterAngle(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
289 | }; |
---|
290 | |
---|
291 | |
---|
292 | /** A prismatic and rotoide joint (ODE_API JointPR) combines a Slider (prismatic) and a Hinge (rotoide). |
---|
293 | It can be used to decrease the number of bodies in a simulation. |
---|
294 | Usually you cannot attach 2 ODE joints together they need a body in between. |
---|
295 | An example of use of this type of joint can be in the creation of a hydraulic piston. |
---|
296 | |
---|
297 | The 2 axies must not be parallel. Since this is a new joint only when the 2 joint are at |
---|
298 | 90deg of each other was fully tested. |
---|
299 | */ |
---|
300 | class _OgreOdeExport SliderHingeJoint:public Joint |
---|
301 | { |
---|
302 | public: |
---|
303 | SliderHingeJoint(World *world, const JointGroup* group = 0); |
---|
304 | ~SliderHingeJoint(); |
---|
305 | |
---|
306 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
307 | virtual const Ogre::Vector3& getAnchor(); |
---|
308 | |
---|
309 | // Equivalent to getting the Slider's extension |
---|
310 | virtual Ogre::Real getPosition(); |
---|
311 | virtual Ogre::Real getPositionRate(); |
---|
312 | |
---|
313 | // Set the axis for the Slider articulation |
---|
314 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
315 | // Get the axis for the Slider articulation |
---|
316 | virtual const Ogre::Vector3& getAxis(); |
---|
317 | // Set the axis for the Hinge articulation. |
---|
318 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
319 | // Get the axis for the Hinge articulation |
---|
320 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
321 | |
---|
322 | // Set joint parameter axis = 3 for Hinge |
---|
323 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
324 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
325 | |
---|
326 | // Applies the torque about the Hinge axis of the joint |
---|
327 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
328 | }; |
---|
329 | |
---|
330 | |
---|
331 | #if ODE_VERSION_MINOR > 9 |
---|
332 | |
---|
333 | /** "A piston joint is similar to a Slider joint except that rotation around the translation axis is possible." |
---|
334 | */ |
---|
335 | class _OgreOdeExport PistonJoint : public Joint |
---|
336 | { |
---|
337 | public: |
---|
338 | PistonJoint(World *world, const JointGroup* group = 0); |
---|
339 | |
---|
340 | // "The joint will try to keep the distance of this point fixed with respect to body2. |
---|
341 | // The input is specified in world coordinates. |
---|
342 | // If there is no body attached to the joint this function has not effect." |
---|
343 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
344 | virtual const Ogre::Vector3& getAnchor(); |
---|
345 | virtual const Ogre::Vector3& getAnchorError(); |
---|
346 | |
---|
347 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
348 | virtual const Ogre::Vector3& getAxis(); |
---|
349 | // "This function set prismatic axis of the joint and also set the position of the joint." |
---|
350 | virtual void setAxisDelta(const Ogre::Vector3& axis, const Ogre::Vector3& initalPosition); |
---|
351 | |
---|
352 | // "Get the piston linear position. |
---|
353 | // When the anchor is set, the current position of body1 and the anchor is examined and that |
---|
354 | // position will be the zero position" |
---|
355 | virtual Ogre::Real getPosition(); |
---|
356 | virtual Ogre::Real getPositionRate(); |
---|
357 | |
---|
358 | // "Get the angle and the time derivative of this value. |
---|
359 | // The angle is measured between the two bodies, or between the body and the static environment. |
---|
360 | // The angle will be between -pi..pi. |
---|
361 | // The only possible axis of rotation is the one defined by the dJointSetPistonAxis. |
---|
362 | // When the piston anchor or axis is set, the current position of the attached bodies is examined |
---|
363 | // and that position will be the zero angle." |
---|
364 | virtual Ogre::Real getAngle(); |
---|
365 | virtual Ogre::Real getAngleRate(); |
---|
366 | |
---|
367 | // "This function create a force inside the piston and this force will be applied on the 2 bodies. |
---|
368 | // Then force is apply to the center of mass of each body and the orientation of the force vector is |
---|
369 | // along the axis of the piston" |
---|
370 | // One axis so only the first force is used |
---|
371 | virtual void addForce(Ogre::Real force, Ogre::Real force2 = 0.0, Ogre::Real force3 = 0.0); |
---|
372 | |
---|
373 | // Set joint parameter |
---|
374 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
375 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
376 | }; |
---|
377 | |
---|
378 | #endif /* ODE_VERSION_MINOR > 9 */ |
---|
379 | |
---|
380 | } |
---|
381 | |
---|
382 | #endif |
---|