| 1 | #include "OgreOdePrecompiledHeaders.h" |
|---|
| 2 | #include "OgreOdeJoint.h" |
|---|
| 3 | |
|---|
| 4 | #include "OgreOdeWorld.h" |
|---|
| 5 | #include "OgreOdeBody.h" |
|---|
| 6 | #include "OgreOdeGeometry.h" |
|---|
| 7 | |
|---|
| 8 | using namespace OgreOde; |
|---|
| 9 | using namespace Ogre; |
|---|
| 10 | |
|---|
| 11 | //------------------------------------------------------------------------------------------------ |
|---|
| 12 | JointGroup::JointGroup(World *world): |
|---|
| 13 | _world(world) |
|---|
| 14 | { |
|---|
| 15 | _joint_group = dJointGroupCreate(0); |
|---|
| 16 | _world->getJointGroupList().registerItem(this); |
|---|
| 17 | } |
|---|
| 18 | //------------------------------------------------------------------------------------------------ |
|---|
| 19 | dJointGroupID JointGroup::getJointGroupID() const |
|---|
| 20 | { |
|---|
| 21 | return _joint_group; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | size_t JointGroup::getID() |
|---|
| 25 | { |
|---|
| 26 | return (size_t)_joint_group; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | void JointGroup::empty() |
|---|
| 30 | { |
|---|
| 31 | dJointGroupEmpty(_joint_group); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | JointGroup::~JointGroup() |
|---|
| 35 | { |
|---|
| 36 | _world->getJointGroupList().unregisterItem((size_t)_joint_group); |
|---|
| 37 | dJointGroupDestroy(_joint_group); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | Joint::Joint(World *world, const JointGroup* group): |
|---|
| 41 | _world(world) |
|---|
| 42 | { |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | void Joint::registerJoint() |
|---|
| 46 | { |
|---|
| 47 | _world->getJointList().registerItem(this); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | void Joint::setAnchor(const Ogre::Vector3& position) |
|---|
| 51 | { |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void Joint::addTorque(Real torque,Real torque2,Real torque3) |
|---|
| 55 | { |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void Joint::addForce(Real force,Real force2,Real force3) |
|---|
| 59 | { |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | const Ogre::Vector3& Joint::getAnchor() |
|---|
| 63 | { |
|---|
| 64 | return Ogre::Vector3::ZERO; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | const Ogre::Vector3& Joint::getAnchorError() |
|---|
| 68 | { |
|---|
| 69 | return Ogre::Vector3::ZERO; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void Joint::setAxis(const Ogre::Vector3& axis) |
|---|
| 73 | { |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | const Ogre::Vector3& Joint::getAxis() |
|---|
| 77 | { |
|---|
| 78 | return Ogre::Vector3::ZERO; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | void Joint::setAdditionalAxis(const Ogre::Vector3& axis) |
|---|
| 82 | { |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | const Ogre::Vector3& Joint::getAdditionalAxis() |
|---|
| 86 | { |
|---|
| 87 | return Ogre::Vector3::ZERO; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | Real Joint::getAngle() |
|---|
| 91 | { |
|---|
| 92 | return 0.0; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | Real Joint::getAngleRate() |
|---|
| 96 | { |
|---|
| 97 | return 0.0; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | Real Joint::getPosition() |
|---|
| 101 | { |
|---|
| 102 | return 0.0; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | Real Joint::getPositionRate() |
|---|
| 106 | { |
|---|
| 107 | return 0.0; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | size_t Joint::getID() |
|---|
| 111 | { |
|---|
| 112 | return (size_t)_joint; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | Joint::~Joint() |
|---|
| 116 | { |
|---|
| 117 | _world->getJointList().unregisterItem((size_t)_joint); |
|---|
| 118 | dJointDestroy(_joint); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | dWorldID Joint::getWorldID() |
|---|
| 122 | { |
|---|
| 123 | return _world->getWorldID(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | dJointGroupID Joint::getJointGroupID(const JointGroup* group) const |
|---|
| 127 | { |
|---|
| 128 | return ((group)?group->getJointGroupID():0); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | dJointID Joint::getJointID() |
|---|
| 132 | { |
|---|
| 133 | return _joint; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | Joint::Type Joint::getType() |
|---|
| 137 | { |
|---|
| 138 | return (Joint::Type)(dJointGetType(_joint)); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | Body* Joint::getFirstBody() |
|---|
| 142 | { |
|---|
| 143 | dBodyID b = dJointGetBody(_joint, 0); |
|---|
| 144 | return ((Body*)dBodyGetData(b)); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | Body* Joint::getSecondBody() |
|---|
| 148 | { |
|---|
| 149 | dBodyID b = dJointGetBody(_joint,1); |
|---|
| 150 | return b ? ((Body*)dBodyGetData(b)) : 0; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | bool Joint::areConnected(const Body* body_a,const Body* body_b) |
|---|
| 154 | { |
|---|
| 155 | return (dAreConnected(body_a->getBodyID(),body_b->getBodyID()))?true:false; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | bool Joint::areConnectedExcluding(const Body* body_a,const Body* body_b,Joint::Type joint_type) |
|---|
| 159 | { |
|---|
| 160 | return (dAreConnectedExcluding(body_a->getBodyID(),body_b->getBodyID(),(int)joint_type))?true:false; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | void Joint::enableFeedback() |
|---|
| 164 | { |
|---|
| 165 | dJointSetFeedback(_joint,&_feedback); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | void Joint::disableFeedback() |
|---|
| 169 | { |
|---|
| 170 | dJointSetFeedback(_joint,0); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | void Joint::detach() |
|---|
| 174 | { |
|---|
| 175 | dJointAttach(_joint,0,0); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | void Joint::attach(const Body* body) |
|---|
| 179 | { |
|---|
| 180 | dJointAttach(_joint,body->getBodyID(),0); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | void Joint::attach(const Body* body_a,const Body* body_b) |
|---|
| 184 | { |
|---|
| 185 | dJointAttach(_joint,body_a->getBodyID(),body_b->getBodyID()); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | const Ogre::Vector3& Joint::getFirstForce() |
|---|
| 189 | { |
|---|
| 190 | assert(dJointGetFeedback(_joint) == &_feedback); |
|---|
| 191 | |
|---|
| 192 | _first_force.x = _feedback.f1[0]; |
|---|
| 193 | _first_force.y = _feedback.f1[1]; |
|---|
| 194 | _first_force.z = _feedback.f1[2]; |
|---|
| 195 | return _first_force; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | const Ogre::Vector3& Joint::getFirstTorque() |
|---|
| 199 | { |
|---|
| 200 | assert(dJointGetFeedback(_joint) == &_feedback); |
|---|
| 201 | |
|---|
| 202 | _first_torque.x = _feedback.t1[0]; |
|---|
| 203 | _first_torque.y = _feedback.t1[1]; |
|---|
| 204 | _first_torque.z = _feedback.t1[2]; |
|---|
| 205 | return _first_torque; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | const Ogre::Vector3& Joint::getSecondForce() |
|---|
| 209 | { |
|---|
| 210 | assert(dJointGetFeedback(_joint) == &_feedback); |
|---|
| 211 | |
|---|
| 212 | _second_force.x = _feedback.f2[0]; |
|---|
| 213 | _second_force.y = _feedback.f2[1]; |
|---|
| 214 | _second_force.z = _feedback.f2[2]; |
|---|
| 215 | return _second_force; |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | const Ogre::Vector3& Joint::getSecondTorque() |
|---|
| 219 | { |
|---|
| 220 | assert(dJointGetFeedback(_joint) == &_feedback); |
|---|
| 221 | |
|---|
| 222 | _second_torque.x = _feedback.t2[0]; |
|---|
| 223 | _second_torque.y = _feedback.t2[1]; |
|---|
| 224 | _second_torque.z = _feedback.t2[2]; |
|---|
| 225 | return _second_torque; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | void Joint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 229 | { |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | Real Joint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 233 | { |
|---|
| 234 | return 0.0; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | BallJoint::BallJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 238 | { |
|---|
| 239 | _joint = dJointCreateBall(getWorldID(),getJointGroupID(group)); |
|---|
| 240 | registerJoint(); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | void BallJoint::setAnchor(const Ogre::Vector3& position) |
|---|
| 244 | { |
|---|
| 245 | dJointSetBallAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | const Ogre::Vector3& BallJoint::getAnchor() |
|---|
| 249 | { |
|---|
| 250 | dVector3 result; |
|---|
| 251 | dJointGetBallAnchor(_joint,result); |
|---|
| 252 | _anchor.x = (Real)result[0]; |
|---|
| 253 | _anchor.y = (Real)result[1]; |
|---|
| 254 | _anchor.z = (Real)result[2]; |
|---|
| 255 | return _anchor; |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | const Ogre::Vector3& BallJoint::getAnchorError() |
|---|
| 259 | { |
|---|
| 260 | dVector3 result1,result2; |
|---|
| 261 | dJointGetBallAnchor(_joint,result1); |
|---|
| 262 | dJointGetBallAnchor2(_joint,result2); |
|---|
| 263 | _anchor_error.x = (Real)(result1[0] - result2[0]); |
|---|
| 264 | _anchor_error.y = (Real)(result1[1] - result2[1]); |
|---|
| 265 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
|---|
| 266 | return _anchor_error; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | void BallJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 270 | { |
|---|
| 271 | dJointSetBallParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | Real BallJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 275 | { |
|---|
| 276 | return (Real)dJointGetBallParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | BallJoint::~BallJoint() |
|---|
| 281 | { |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | HingeJoint::HingeJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 285 | { |
|---|
| 286 | _joint = dJointCreateHinge(getWorldID(),getJointGroupID(group)); |
|---|
| 287 | registerJoint(); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | void HingeJoint::setAnchor(const Ogre::Vector3& position) |
|---|
| 291 | { |
|---|
| 292 | dJointSetHingeAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | void HingeJoint::addTorque(Real torque,Real torque2,Real torque3) |
|---|
| 296 | { |
|---|
| 297 | dJointAddHingeTorque(_joint,(dReal)torque); |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | const Ogre::Vector3& HingeJoint::getAnchor() |
|---|
| 301 | { |
|---|
| 302 | dVector3 result; |
|---|
| 303 | dJointGetHingeAnchor(_joint,result); |
|---|
| 304 | _anchor.x = (Real)result[0]; |
|---|
| 305 | _anchor.y = (Real)result[1]; |
|---|
| 306 | _anchor.z = (Real)result[2]; |
|---|
| 307 | return _anchor; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | const Ogre::Vector3& HingeJoint::getAnchorError() |
|---|
| 311 | { |
|---|
| 312 | dVector3 result1,result2; |
|---|
| 313 | dJointGetHingeAnchor(_joint,result1); |
|---|
| 314 | dJointGetHingeAnchor2(_joint,result2); |
|---|
| 315 | _anchor_error.x = (Real)(result1[0] - result2[0]); |
|---|
| 316 | _anchor_error.y = (Real)(result1[1] - result2[1]); |
|---|
| 317 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
|---|
| 318 | return _anchor_error; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | void HingeJoint::setAxis(const Ogre::Vector3& axis) |
|---|
| 322 | { |
|---|
| 323 | dJointSetHingeAxis(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | const Ogre::Vector3& HingeJoint::getAxis() |
|---|
| 327 | { |
|---|
| 328 | dVector3 result; |
|---|
| 329 | dJointGetHingeAxis(_joint,result); |
|---|
| 330 | _axis.x = (Real)result[0]; |
|---|
| 331 | _axis.y = (Real)result[1]; |
|---|
| 332 | _axis.z = (Real)result[2]; |
|---|
| 333 | return _axis; |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | Real HingeJoint::getAngle() |
|---|
| 337 | { |
|---|
| 338 | return (Real)dJointGetHingeAngle(_joint); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | Real HingeJoint::getAngleRate() |
|---|
| 342 | { |
|---|
| 343 | return (Real)dJointGetHingeAngleRate(_joint); |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | void HingeJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 347 | { |
|---|
| 348 | dJointSetHingeParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | Real HingeJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 352 | { |
|---|
| 353 | return (Real)dJointGetHingeParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | HingeJoint::~HingeJoint() |
|---|
| 357 | { |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | SliderJoint::SliderJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 361 | { |
|---|
| 362 | _joint = dJointCreateSlider(getWorldID(),getJointGroupID(group)); |
|---|
| 363 | registerJoint(); |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | void SliderJoint::setAxis(const Ogre::Vector3& axis) |
|---|
| 367 | { |
|---|
| 368 | dJointSetSliderAxis(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | const Ogre::Vector3& SliderJoint::getAxis() |
|---|
| 372 | { |
|---|
| 373 | dVector3 result; |
|---|
| 374 | dJointGetSliderAxis(_joint,result); |
|---|
| 375 | _axis.x = (Real)result[0]; |
|---|
| 376 | _axis.y = (Real)result[1]; |
|---|
| 377 | _axis.z = (Real)result[2]; |
|---|
| 378 | return _axis; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | void SliderJoint::addForce(Real force,Real force2,Real force3) |
|---|
| 382 | { |
|---|
| 383 | dJointAddSliderForce(_joint,(dReal)force); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | Real SliderJoint::getPosition() |
|---|
| 387 | { |
|---|
| 388 | return (Real)dJointGetSliderPosition(_joint); |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | Real SliderJoint::getPositionRate() |
|---|
| 392 | { |
|---|
| 393 | return (Real)dJointGetSliderPositionRate(_joint); |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | void SliderJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 397 | { |
|---|
| 398 | dJointSetSliderParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | Real SliderJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 402 | { |
|---|
| 403 | return (Real)dJointGetSliderParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | SliderJoint::~SliderJoint() |
|---|
| 407 | { |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | UniversalJoint::UniversalJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 411 | { |
|---|
| 412 | _joint = dJointCreateUniversal(getWorldID(),getJointGroupID(group)); |
|---|
| 413 | registerJoint(); |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | void UniversalJoint::setAnchor(const Ogre::Vector3& position) |
|---|
| 417 | { |
|---|
| 418 | dJointSetUniversalAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | void UniversalJoint::addTorque(Real torque,Real torque2,Real torque3) |
|---|
| 422 | { |
|---|
| 423 | dJointAddUniversalTorques(_joint,(dReal)torque,(dReal)torque2); |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | const Ogre::Vector3& UniversalJoint::getAnchor() |
|---|
| 427 | { |
|---|
| 428 | dVector3 result; |
|---|
| 429 | dJointGetUniversalAnchor(_joint,result); |
|---|
| 430 | _anchor.x = (Real)result[0]; |
|---|
| 431 | _anchor.y = (Real)result[1]; |
|---|
| 432 | _anchor.z = (Real)result[2]; |
|---|
| 433 | return _anchor; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | const Ogre::Vector3& UniversalJoint::getAnchorError() |
|---|
| 437 | { |
|---|
| 438 | dVector3 result1,result2; |
|---|
| 439 | dJointGetUniversalAnchor(_joint,result1); |
|---|
| 440 | dJointGetUniversalAnchor2(_joint,result2); |
|---|
| 441 | _anchor_error.x = (Real)(result1[0] - result2[0]); |
|---|
| 442 | _anchor_error.y = (Real)(result1[1] - result2[1]); |
|---|
| 443 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
|---|
| 444 | return _anchor_error; |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | void UniversalJoint::setAxis(const Ogre::Vector3& axis) |
|---|
| 448 | { |
|---|
| 449 | dJointSetUniversalAxis1(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | const Ogre::Vector3& UniversalJoint::getAxis() |
|---|
| 453 | { |
|---|
| 454 | dVector3 result; |
|---|
| 455 | dJointGetUniversalAxis1(_joint,result); |
|---|
| 456 | _axis.x = (Real)result[0]; |
|---|
| 457 | _axis.y = (Real)result[1]; |
|---|
| 458 | _axis.z = (Real)result[2]; |
|---|
| 459 | return _axis; |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | void UniversalJoint::setAdditionalAxis(const Ogre::Vector3& axis) |
|---|
| 463 | { |
|---|
| 464 | dJointSetUniversalAxis2(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | const Ogre::Vector3& UniversalJoint::getAdditionalAxis() |
|---|
| 468 | { |
|---|
| 469 | dVector3 result; |
|---|
| 470 | dJointGetUniversalAxis2(_joint,result); |
|---|
| 471 | _additional_axis.x = (Real)result[0]; |
|---|
| 472 | _additional_axis.y = (Real)result[1]; |
|---|
| 473 | _additional_axis.z = (Real)result[2]; |
|---|
| 474 | return _additional_axis; |
|---|
| 475 | } |
|---|
| 476 | |
|---|
| 477 | void UniversalJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 478 | { |
|---|
| 479 | dJointSetUniversalParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | Real UniversalJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 483 | { |
|---|
| 484 | return (Real)dJointGetUniversalParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | UniversalJoint::~UniversalJoint() |
|---|
| 488 | { |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | FixedJoint::FixedJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 492 | { |
|---|
| 493 | _joint = dJointCreateFixed(getWorldID(),getJointGroupID(group)); |
|---|
| 494 | registerJoint(); |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | void FixedJoint::attach(const Body* body) |
|---|
| 498 | { |
|---|
| 499 | Joint::attach(body); |
|---|
| 500 | dJointSetFixed(_joint); |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | void FixedJoint::attach(const Body* body_a,const Body* body_b) |
|---|
| 504 | { |
|---|
| 505 | Joint::attach(body_a,body_b); |
|---|
| 506 | dJointSetFixed(_joint); |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | FixedJoint::~FixedJoint() |
|---|
| 510 | { |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | SuspensionJoint::SuspensionJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 514 | { |
|---|
| 515 | _joint = dJointCreateHinge2(getWorldID(),getJointGroupID(group)); |
|---|
| 516 | registerJoint(); |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | void SuspensionJoint::setAnchor(const Ogre::Vector3& position) |
|---|
| 520 | { |
|---|
| 521 | dJointSetHinge2Anchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | void SuspensionJoint::addTorque(Real torque,Real torque2,Real torque3) |
|---|
| 526 | { |
|---|
| 527 | dJointAddHinge2Torques(_joint,(dReal)torque,(dReal)torque2); |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | const Ogre::Vector3& SuspensionJoint::getAnchor() |
|---|
| 531 | { |
|---|
| 532 | dVector3 result; |
|---|
| 533 | dJointGetHinge2Anchor(_joint,result); |
|---|
| 534 | _anchor.x = (Real)result[0]; |
|---|
| 535 | _anchor.y = (Real)result[1]; |
|---|
| 536 | _anchor.z = (Real)result[2]; |
|---|
| 537 | return _anchor; |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | const Ogre::Vector3& SuspensionJoint::getAdditionalAnchor() |
|---|
| 541 | { |
|---|
| 542 | dVector3 result; |
|---|
| 543 | dJointGetHinge2Anchor2(_joint,result); |
|---|
| 544 | _anchor2.x = (Real)result[0]; |
|---|
| 545 | _anchor2.y = (Real)result[1]; |
|---|
| 546 | _anchor2.z = (Real)result[2]; |
|---|
| 547 | return _anchor2; |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | const Ogre::Vector3& SuspensionJoint::getAnchorError() |
|---|
| 551 | { |
|---|
| 552 | dVector3 result1,result2; |
|---|
| 553 | dJointGetHinge2Anchor(_joint,result1); |
|---|
| 554 | dJointGetHinge2Anchor2(_joint,result2); |
|---|
| 555 | _anchor_error.x = (Real)(result1[0] - result2[0]); |
|---|
| 556 | _anchor_error.y = (Real)(result1[1] - result2[1]); |
|---|
| 557 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
|---|
| 558 | return _anchor_error; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | void SuspensionJoint::setAxis(const Ogre::Vector3& axis) |
|---|
| 562 | { |
|---|
| 563 | dJointSetHinge2Axis1(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | const Ogre::Vector3& SuspensionJoint::getAxis() |
|---|
| 567 | { |
|---|
| 568 | dVector3 result; |
|---|
| 569 | dJointGetHinge2Axis1(_joint,result); |
|---|
| 570 | _axis.x = (Real)result[0]; |
|---|
| 571 | _axis.y = (Real)result[1]; |
|---|
| 572 | _axis.z = (Real)result[2]; |
|---|
| 573 | return _axis; |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | void SuspensionJoint::setAdditionalAxis(const Ogre::Vector3& axis) |
|---|
| 577 | { |
|---|
| 578 | dJointSetHinge2Axis2(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | const Ogre::Vector3& SuspensionJoint::getAdditionalAxis() |
|---|
| 582 | { |
|---|
| 583 | dVector3 result; |
|---|
| 584 | dJointGetHinge2Axis2(_joint,result); |
|---|
| 585 | _additional_axis.x = (Real)result[0]; |
|---|
| 586 | _additional_axis.y = (Real)result[1]; |
|---|
| 587 | _additional_axis.z = (Real)result[2]; |
|---|
| 588 | return _additional_axis; |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | Real SuspensionJoint::getAngle() |
|---|
| 592 | { |
|---|
| 593 | return (Real)dJointGetHinge2Angle1(_joint); |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | Real SuspensionJoint::getAngleRate() |
|---|
| 597 | { |
|---|
| 598 | return (Real)dJointGetHinge2Angle1Rate(_joint); |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | Real SuspensionJoint::getPositionRate() |
|---|
| 602 | { |
|---|
| 603 | return (Real)dJointGetHinge2Angle2Rate(_joint); |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | void SuspensionJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 607 | { |
|---|
| 608 | dJointSetHinge2Param(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | Real SuspensionJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 612 | { |
|---|
| 613 | return (Real)dJointGetHinge2Param(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | SuspensionJoint::~SuspensionJoint() |
|---|
| 617 | { |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | AngularMotorJoint::AngularMotorJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 621 | { |
|---|
| 622 | _joint = dJointCreateAMotor(getWorldID(),getJointGroupID(group)); |
|---|
| 623 | registerJoint(); |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | void AngularMotorJoint::setMode(AngularMotorJoint::Mode mode) |
|---|
| 627 | { |
|---|
| 628 | dJointSetAMotorMode(_joint,(int)mode); |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | AngularMotorJoint::Mode AngularMotorJoint::getMode() |
|---|
| 632 | { |
|---|
| 633 | return (AngularMotorJoint::Mode)dJointGetAMotorMode(_joint); |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | void AngularMotorJoint::addTorque(Real torque,Real torque2,Real torque3) |
|---|
| 637 | { |
|---|
| 638 | dJointAddAMotorTorques(_joint,(dReal)torque,(dReal)torque2,(dReal)torque3); |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | void AngularMotorJoint::setAxisCount(int axes) |
|---|
| 642 | { |
|---|
| 643 | assert((axes >= 0) && (axes <= 3)); |
|---|
| 644 | dJointSetAMotorNumAxes(_joint,axes); |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | int AngularMotorJoint::getAxisCount() |
|---|
| 648 | { |
|---|
| 649 | return dJointGetAMotorNumAxes(_joint); |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | void AngularMotorJoint::setAxis(int axis_number,AngularMotorJoint::RelativeOrientation orientation,const Ogre::Vector3& axis) |
|---|
| 653 | { |
|---|
| 654 | dJointSetAMotorAxis(_joint,axis_number,(int)orientation,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | const Ogre::Vector3& AngularMotorJoint::getAxis(int axis_number) |
|---|
| 658 | { |
|---|
| 659 | dVector3 result; |
|---|
| 660 | dJointGetAMotorAxis(_joint,axis_number,result); |
|---|
| 661 | _axis.x = (Real)result[0]; |
|---|
| 662 | _axis.y = (Real)result[1]; |
|---|
| 663 | _axis.z = (Real)result[2]; |
|---|
| 664 | return _axis; |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | AngularMotorJoint::RelativeOrientation AngularMotorJoint::getAxisRelativeOrientation(int axis_number) |
|---|
| 668 | { |
|---|
| 669 | return (AngularMotorJoint::RelativeOrientation)dJointGetAMotorAxisRel(_joint,axis_number); |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | void AngularMotorJoint::setAngle(int axis,Real angle) |
|---|
| 673 | { |
|---|
| 674 | dJointSetAMotorAngle(_joint,axis,(dReal)angle); |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | Real AngularMotorJoint::getAngle(int axis) |
|---|
| 678 | { |
|---|
| 679 | return (Real)dJointGetAMotorAngle(_joint,axis); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | Real AngularMotorJoint::getAngleRate(int axis) |
|---|
| 683 | { |
|---|
| 684 | return (Real)dJointGetAMotorAngleRate(_joint,axis); |
|---|
| 685 | } |
|---|
| 686 | |
|---|
| 687 | void AngularMotorJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 688 | { |
|---|
| 689 | dJointSetAMotorParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | Real AngularMotorJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 693 | { |
|---|
| 694 | return (Real)dJointGetAMotorParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 695 | } |
|---|
| 696 | |
|---|
| 697 | AngularMotorJoint::~AngularMotorJoint() |
|---|
| 698 | { |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | PlanarJoint::PlanarJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 702 | { |
|---|
| 703 | _joint = dJointCreatePlane2D(getWorldID(),getJointGroupID(group)); |
|---|
| 704 | registerJoint(); |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | void PlanarJoint::setParameterX(Joint::Parameter parameter,Real value,int axis) |
|---|
| 708 | { |
|---|
| 709 | dJointSetPlane2DXParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | void PlanarJoint::setParameterY(Joint::Parameter parameter,Real value,int axis) |
|---|
| 713 | { |
|---|
| 714 | dJointSetPlane2DYParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | void PlanarJoint::setParameterAngle(Joint::Parameter parameter,Real value,int axis) |
|---|
| 718 | { |
|---|
| 719 | dJointSetPlane2DAngleParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | PlanarJoint::~PlanarJoint() |
|---|
| 723 | { |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | SliderHingeJoint::SliderHingeJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 729 | { |
|---|
| 730 | _joint = dJointCreatePR(getWorldID(),getJointGroupID(group)); |
|---|
| 731 | registerJoint(); |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | SliderHingeJoint::~SliderHingeJoint() |
|---|
| 735 | { |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | void SliderHingeJoint::setAnchor(const Ogre::Vector3& position) |
|---|
| 739 | { |
|---|
| 740 | dJointSetPRAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | const Ogre::Vector3& SliderHingeJoint::getAnchor() |
|---|
| 744 | { |
|---|
| 745 | dVector3 result; |
|---|
| 746 | dJointGetPRAnchor(_joint,result); |
|---|
| 747 | _anchor.x = (Real)result[0]; |
|---|
| 748 | _anchor.y = (Real)result[1]; |
|---|
| 749 | _anchor.z = (Real)result[2]; |
|---|
| 750 | return _anchor; |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | Real SliderHingeJoint::getPosition() |
|---|
| 755 | { |
|---|
| 756 | return (Real)dJointGetPRPosition(_joint); |
|---|
| 757 | } |
|---|
| 758 | |
|---|
| 759 | Real SliderHingeJoint::getPositionRate() |
|---|
| 760 | { |
|---|
| 761 | return (Real)dJointGetPRPositionRate(_joint); |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | void SliderHingeJoint::setAxis(const Ogre::Vector3& axis) |
|---|
| 765 | { |
|---|
| 766 | dJointSetPRAxis1(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | const Ogre::Vector3& SliderHingeJoint::getAxis() |
|---|
| 770 | { |
|---|
| 771 | dVector3 result; |
|---|
| 772 | dJointGetPRAxis1(_joint,result); |
|---|
| 773 | _axis.x = (Real)result[0]; |
|---|
| 774 | _axis.y = (Real)result[1]; |
|---|
| 775 | _axis.z = (Real)result[2]; |
|---|
| 776 | return _axis; |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | void SliderHingeJoint::setAdditionalAxis(const Ogre::Vector3& axis) |
|---|
| 780 | { |
|---|
| 781 | dJointSetPRAxis2(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 782 | } |
|---|
| 783 | |
|---|
| 784 | const Ogre::Vector3& SliderHingeJoint::getAdditionalAxis() |
|---|
| 785 | { |
|---|
| 786 | dVector3 result; |
|---|
| 787 | dJointGetPRAxis2(_joint,result); |
|---|
| 788 | _additional_axis.x = (Real)result[0]; |
|---|
| 789 | _additional_axis.y = (Real)result[1]; |
|---|
| 790 | _additional_axis.z = (Real)result[2]; |
|---|
| 791 | return _additional_axis; |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | void SliderHingeJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 795 | { |
|---|
| 796 | dJointSetPRParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | Real SliderHingeJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 800 | { |
|---|
| 801 | return (Real)dJointGetPRParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | void SliderHingeJoint::addTorque(Real torque,Real torque2,Real torque3) |
|---|
| 805 | { |
|---|
| 806 | dJointAddPRTorque(_joint, (dReal)torque); |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | #if ODE_VERSION_MINOR > 9 |
|---|
| 812 | |
|---|
| 813 | PistonJoint::PistonJoint(World *world, const JointGroup* group) : Joint(world, group) |
|---|
| 814 | { |
|---|
| 815 | _joint = dJointCreatePiston(getWorldID(), getJointGroupID(group)); |
|---|
| 816 | registerJoint(); |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | void PistonJoint::setAnchor(const Ogre::Vector3& position) |
|---|
| 820 | { |
|---|
| 821 | dJointSetPistonAnchor(_joint,(dReal)position.x,(dReal)position.y,(dReal)position.z); |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | const Ogre::Vector3& PistonJoint::getAnchor() |
|---|
| 825 | { |
|---|
| 826 | dVector3 result; |
|---|
| 827 | dJointGetPistonAnchor(_joint,result); |
|---|
| 828 | _anchor.x = (Real)result[0]; |
|---|
| 829 | _anchor.y = (Real)result[1]; |
|---|
| 830 | _anchor.z = (Real)result[2]; |
|---|
| 831 | return _anchor; |
|---|
| 832 | } |
|---|
| 833 | |
|---|
| 834 | const Ogre::Vector3& PistonJoint::getAnchorError() |
|---|
| 835 | { |
|---|
| 836 | dVector3 result1,result2; |
|---|
| 837 | dJointGetPistonAnchor(_joint,result1); |
|---|
| 838 | dJointGetPistonAnchor2(_joint,result2); |
|---|
| 839 | _anchor_error.x = (Real)(result1[0] - result2[0]); |
|---|
| 840 | _anchor_error.y = (Real)(result1[1] - result2[1]); |
|---|
| 841 | _anchor_error.z = (Real)(result1[2] - result2[2]); |
|---|
| 842 | return _anchor_error; |
|---|
| 843 | } |
|---|
| 844 | |
|---|
| 845 | void PistonJoint::setAxis(const Ogre::Vector3& axis) |
|---|
| 846 | { |
|---|
| 847 | dJointSetPistonAxis(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | const Ogre::Vector3& PistonJoint::getAxis() |
|---|
| 851 | { |
|---|
| 852 | dVector3 result; |
|---|
| 853 | dJointGetPistonAxis(_joint,result); |
|---|
| 854 | _axis.x = (Real)result[0]; |
|---|
| 855 | _axis.y = (Real)result[1]; |
|---|
| 856 | _axis.z = (Real)result[2]; |
|---|
| 857 | return _axis; |
|---|
| 858 | } |
|---|
| 859 | |
|---|
| 860 | void PistonJoint::setAxisDelta(const Ogre::Vector3& axis, const Ogre::Vector3& initalPosition) |
|---|
| 861 | { |
|---|
| 862 | dJointSetPistonAxisDelta(_joint,(dReal)axis.x,(dReal)axis.y,(dReal)axis.z, |
|---|
| 863 | (dReal)initalPosition.x,(dReal)initalPosition.y,(dReal)initalPosition.z); |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | Real PistonJoint::getPosition() |
|---|
| 867 | { |
|---|
| 868 | return (Real)dJointGetPistonPosition(_joint); |
|---|
| 869 | } |
|---|
| 870 | |
|---|
| 871 | Real PistonJoint::getPositionRate() |
|---|
| 872 | { |
|---|
| 873 | return (Real)dJointGetPistonPositionRate(_joint); |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | Real PistonJoint::getAngle() |
|---|
| 877 | { |
|---|
| 878 | return (Real)dJointGetPistonAngle(_joint); |
|---|
| 879 | } |
|---|
| 880 | |
|---|
| 881 | Real PistonJoint::getAngleRate() |
|---|
| 882 | { |
|---|
| 883 | return (Real)dJointGetPistonAngleRate(_joint); |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | void PistonJoint::addForce(Real force,Real force2,Real force3) |
|---|
| 887 | { |
|---|
| 888 | dJointAddPistonForce(_joint,(dReal)force); |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | void PistonJoint::setParameter(Joint::Parameter parameter,Real value,int axis) |
|---|
| 892 | { |
|---|
| 893 | dJointSetPistonParam(_joint,((int)parameter) + dParamGroup * (axis - 1),(dReal)value); |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | Real PistonJoint::getParameter(Joint::Parameter parameter,int axis) |
|---|
| 897 | { |
|---|
| 898 | return (Real)dJointGetPistonParam(_joint,((int)parameter) + dParamGroup * (axis - 1)); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | #endif /* ODE_VERSION_MINOR > 9 */ |
|---|