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 unsigned long 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 | Type_SliderHingeJoint = dJointTypePR |
---|
46 | }; |
---|
47 | |
---|
48 | enum Parameter |
---|
49 | { |
---|
50 | Parameter_LowStop = dParamLoStop, |
---|
51 | Parameter_HighStop = dParamHiStop, |
---|
52 | Parameter_LowStop2 = dParamLoStop2, // SliderHingeJoint |
---|
53 | Parameter_HighStop2 = dParamHiStop2, // SliderHingeJoint |
---|
54 | Parameter_MotorVelocity = dParamVel, |
---|
55 | Parameter_MaximumForce = dParamFMax, |
---|
56 | Parameter_FudgeFactor = dParamFudgeFactor, |
---|
57 | Parameter_Bounceyness = dParamBounce, |
---|
58 | Parameter_CFM = dParamCFM, |
---|
59 | Parameter_ERP = dParamERP, |
---|
60 | Parameter_StopERP = dParamStopERP, |
---|
61 | Parameter_StopCFM = dParamStopCFM, |
---|
62 | Parameter_SuspensionERP = dParamSuspensionERP, // SuspensionJoint |
---|
63 | Parameter_SuspensionCFM = dParamSuspensionCFM // SuspensionJoint |
---|
64 | }; |
---|
65 | |
---|
66 | public: |
---|
67 | Joint(World *world, const JointGroup* group = 0); |
---|
68 | virtual ~Joint(); |
---|
69 | |
---|
70 | Joint::Type getType(); |
---|
71 | |
---|
72 | void registerJoint(); |
---|
73 | |
---|
74 | void detach(); |
---|
75 | virtual void attach(const Body* body); |
---|
76 | virtual void attach(const Body* body_a,const Body* body_b); |
---|
77 | |
---|
78 | Body* getFirstBody(); |
---|
79 | Body* getSecondBody(); |
---|
80 | |
---|
81 | static bool areConnected(const Body* body_a,const Body* body_b); |
---|
82 | static bool areConnectedExcluding(const Body* body_a,const Body* body_b,Joint::Type joint_type); |
---|
83 | |
---|
84 | void enableFeedback(); |
---|
85 | void disableFeedback(); |
---|
86 | const Ogre::Vector3& getFirstForce(); |
---|
87 | const Ogre::Vector3& getFirstTorque(); |
---|
88 | const Ogre::Vector3& getSecondForce(); |
---|
89 | const Ogre::Vector3& getSecondTorque(); |
---|
90 | |
---|
91 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
92 | virtual const Ogre::Vector3& getAnchor(); |
---|
93 | virtual const Ogre::Vector3& getAnchorError(); |
---|
94 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
95 | virtual const Ogre::Vector3& getAxis(); |
---|
96 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
97 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
98 | virtual Ogre::Real getAngle(); |
---|
99 | virtual Ogre::Real getAngleRate(); |
---|
100 | virtual Ogre::Real getPosition(); |
---|
101 | virtual Ogre::Real getPositionRate(); |
---|
102 | |
---|
103 | virtual void setParameter(Joint::Parameter parameter,Ogre::Real value,int axis = 1); |
---|
104 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
105 | |
---|
106 | virtual unsigned long getID(); |
---|
107 | |
---|
108 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
109 | virtual void addForce(Ogre::Real force, Ogre::Real force2 = 0.0, Ogre::Real force3 = 0.0); |
---|
110 | |
---|
111 | protected: |
---|
112 | dJointID getJointID(); |
---|
113 | |
---|
114 | dWorldID getWorldID(); |
---|
115 | dJointGroupID getJointGroupID(const JointGroup* group) const; |
---|
116 | |
---|
117 | protected: |
---|
118 | dJointID _joint; |
---|
119 | dJointFeedback _feedback; |
---|
120 | Ogre::Vector3 _axis,_anchor,_anchor_error,_additional_axis; |
---|
121 | Ogre::Vector3 _first_force,_first_torque,_second_force,_second_torque; |
---|
122 | World *_world; |
---|
123 | }; |
---|
124 | |
---|
125 | class _OgreOdeExport BallJoint:public Joint |
---|
126 | { |
---|
127 | public: |
---|
128 | BallJoint(World *world, const JointGroup* group = 0); |
---|
129 | ~BallJoint(); |
---|
130 | |
---|
131 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
132 | virtual const Ogre::Vector3& getAnchor(); |
---|
133 | virtual const Ogre::Vector3& getAnchorError(); |
---|
134 | |
---|
135 | // as of ode-0.9 can set Parameter_CFM and Parameter_ERP to make the joint springy, an axis value isn't needed |
---|
136 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
137 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
138 | }; |
---|
139 | |
---|
140 | class _OgreOdeExport HingeJoint:public Joint |
---|
141 | { |
---|
142 | public: |
---|
143 | HingeJoint(World *world, const JointGroup* group = 0); |
---|
144 | ~HingeJoint(); |
---|
145 | |
---|
146 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
147 | virtual const Ogre::Vector3& getAnchor(); |
---|
148 | virtual const Ogre::Vector3& getAnchorError(); |
---|
149 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
150 | virtual const Ogre::Vector3& getAxis(); |
---|
151 | virtual Ogre::Real getAngle(); |
---|
152 | virtual Ogre::Real getAngleRate(); |
---|
153 | |
---|
154 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
155 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
156 | |
---|
157 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
158 | }; |
---|
159 | |
---|
160 | class _OgreOdeExport SliderJoint:public Joint |
---|
161 | { |
---|
162 | public: |
---|
163 | SliderJoint(World *world, const JointGroup* group = 0); |
---|
164 | ~SliderJoint(); |
---|
165 | |
---|
166 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
167 | virtual const Ogre::Vector3& getAxis(); |
---|
168 | virtual Ogre::Real getPosition(); |
---|
169 | virtual Ogre::Real getPositionRate(); |
---|
170 | |
---|
171 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
172 | virtual Ogre::Real getParameter(Joint::Parameter parameter, int axis = 1); |
---|
173 | |
---|
174 | virtual void addForce(Ogre::Real force, Ogre::Real force2 = 0.0, Ogre::Real force3 = 0.0); |
---|
175 | }; |
---|
176 | |
---|
177 | class _OgreOdeExport UniversalJoint:public Joint |
---|
178 | { |
---|
179 | public: |
---|
180 | UniversalJoint(World *world, const JointGroup* group = 0); |
---|
181 | ~UniversalJoint(); |
---|
182 | |
---|
183 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
184 | virtual const Ogre::Vector3& getAnchor(); |
---|
185 | virtual const Ogre::Vector3& getAnchorError(); |
---|
186 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
187 | virtual const Ogre::Vector3& getAxis(); |
---|
188 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
189 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
190 | |
---|
191 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value, int axis = 1); |
---|
192 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
193 | |
---|
194 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
195 | }; |
---|
196 | |
---|
197 | class _OgreOdeExport FixedJoint:public Joint |
---|
198 | { |
---|
199 | public: |
---|
200 | FixedJoint(World *world, const JointGroup* group = 0); |
---|
201 | ~FixedJoint(); |
---|
202 | |
---|
203 | virtual void attach(const Body* body); |
---|
204 | virtual void attach(const Body* body_a,const Body* body_b); |
---|
205 | }; |
---|
206 | |
---|
207 | class _OgreOdeExport SuspensionJoint:public Joint |
---|
208 | { |
---|
209 | public: |
---|
210 | SuspensionJoint(World *world, const JointGroup* group = 0); |
---|
211 | ~SuspensionJoint(); |
---|
212 | |
---|
213 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
214 | virtual const Ogre::Vector3& getAnchor(); |
---|
215 | virtual const Ogre::Vector3& getAdditionalAnchor(); |
---|
216 | virtual const Ogre::Vector3& getAnchorError(); |
---|
217 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
218 | virtual const Ogre::Vector3& getAxis(); |
---|
219 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
220 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
221 | virtual Ogre::Real getAngle(); |
---|
222 | virtual Ogre::Real getAngleRate(); |
---|
223 | virtual Ogre::Real getPositionRate(); |
---|
224 | |
---|
225 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
226 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
227 | |
---|
228 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
229 | |
---|
230 | protected: |
---|
231 | Ogre::Vector3 _anchor2; |
---|
232 | }; |
---|
233 | |
---|
234 | class _OgreOdeExport AngularMotorJoint:public Joint |
---|
235 | { |
---|
236 | public: |
---|
237 | enum Mode |
---|
238 | { |
---|
239 | Mode_UserAngularMotor = dAMotorUser, |
---|
240 | Mode_EulerAngularMotor = dAMotorEuler |
---|
241 | }; |
---|
242 | |
---|
243 | enum RelativeOrientation |
---|
244 | { |
---|
245 | RelativeOrientation_GlobalFrame = 0, |
---|
246 | RelativeOrientation_FirstBody = 1, |
---|
247 | RelativeOrientation_SecondBody = 2 |
---|
248 | }; |
---|
249 | |
---|
250 | public: |
---|
251 | AngularMotorJoint(World *world, const JointGroup* group = 0); |
---|
252 | ~AngularMotorJoint(); |
---|
253 | |
---|
254 | void setMode(AngularMotorJoint::Mode mode); |
---|
255 | AngularMotorJoint::Mode getMode(); |
---|
256 | |
---|
257 | void setAxisCount(int axes); |
---|
258 | int getAxisCount(); |
---|
259 | |
---|
260 | void setAxis(int axis_number,AngularMotorJoint::RelativeOrientation orientation,const Ogre::Vector3& axis); |
---|
261 | const Ogre::Vector3& getAxis(int axis_number); |
---|
262 | AngularMotorJoint::RelativeOrientation getAxisRelativeOrientation(int axis_number); |
---|
263 | |
---|
264 | void setAngle(int axis, Ogre::Real angle); |
---|
265 | Ogre::Real getAngle(int axis); |
---|
266 | Ogre::Real getAngleRate(int axis); |
---|
267 | |
---|
268 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
269 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
270 | |
---|
271 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
272 | }; |
---|
273 | |
---|
274 | class _OgreOdeExport PlanarJoint:public Joint |
---|
275 | { |
---|
276 | public: |
---|
277 | PlanarJoint(World *world, const JointGroup* group = 0); |
---|
278 | ~PlanarJoint(); |
---|
279 | |
---|
280 | virtual void setParameterX(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
281 | virtual void setParameterY(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
282 | virtual void setParameterAngle(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
283 | }; |
---|
284 | |
---|
285 | |
---|
286 | /** A prismatic and rotoide joint (ODE_API JointPR) combines a Slider (prismatic) and a Hinge (rotoide). |
---|
287 | It can be used to decrease the number of bodies in a simulation. |
---|
288 | Usually you cannot attach 2 ODE joints together they need a body in between. |
---|
289 | An example of use of this type of joint can be in the creation of a hydraulic piston. |
---|
290 | |
---|
291 | The 2 axies must not be parallel. Since this is a new joint only when the 2 joint are at |
---|
292 | 90deg of each other was fully tested. |
---|
293 | */ |
---|
294 | class _OgreOdeExport SliderHingeJoint:public Joint |
---|
295 | { |
---|
296 | public: |
---|
297 | SliderHingeJoint(World *world, const JointGroup* group = 0); |
---|
298 | ~SliderHingeJoint(); |
---|
299 | |
---|
300 | virtual void setAnchor(const Ogre::Vector3& position); |
---|
301 | virtual const Ogre::Vector3& getAnchor(); |
---|
302 | |
---|
303 | // Equivalent to getting the Slider's extension |
---|
304 | virtual Ogre::Real getPosition(); |
---|
305 | virtual Ogre::Real getPositionRate(); |
---|
306 | |
---|
307 | // Set the axis for the Slider articulation |
---|
308 | virtual void setAxis(const Ogre::Vector3& axis); |
---|
309 | // Get the axis for the Slider articulation |
---|
310 | virtual const Ogre::Vector3& getAxis(); |
---|
311 | // Set the axis for the Hinge articulation. |
---|
312 | virtual void setAdditionalAxis(const Ogre::Vector3& axis); |
---|
313 | // Get the axis for the Hinge articulation |
---|
314 | virtual const Ogre::Vector3& getAdditionalAxis(); |
---|
315 | |
---|
316 | // Set joint parameter axis = 3 for Hinge |
---|
317 | virtual void setParameter(Joint::Parameter parameter, Ogre::Real value,int axis = 1); |
---|
318 | virtual Ogre::Real getParameter(Joint::Parameter parameter,int axis = 1); |
---|
319 | |
---|
320 | // Applies the torque about the Hinge axis of the joint |
---|
321 | virtual void addTorque(Ogre::Real torque, Ogre::Real torque2 = 0.0, Ogre::Real torque3 = 0.0); |
---|
322 | }; |
---|
323 | |
---|
324 | |
---|
325 | } |
---|
326 | |
---|
327 | #endif |
---|