| 462 | | void |
| 463 | | PhysicsActor::ApplyForceAndTorqueCallback(const btRigidBody* _body) |
| 464 | | { |
| 465 | | class ApplyForcesEventData |
| 466 | | : public I_ApplyForcesEventData |
| 467 | | { |
| 468 | | /// @name I_ApplyForcesEventData implementation |
| 469 | | /// @{ |
| 470 | | public: |
| 471 | | /// Get the physics shape associated with this event |
| 472 | | virtual I_PhysicsActor& getActor() |
| 473 | | { |
| 474 | | return *m_pShape; |
| 475 | | } |
| 476 | | |
| 477 | | /// Apply a force to this shape |
| 478 | | virtual void applyForce(const Math::Vector3& _force) |
| 479 | | { |
| 480 | | m_pShape->applyForce(_force); |
| 481 | | } |
| 482 | | |
| 483 | | /// Apply torque to this shape |
| 484 | | virtual void applyTorque(const Math::Vector3& _torque) |
| 485 | | { |
| 486 | | m_pShape->applyTorque(_torque); |
| 487 | | } |
| 488 | | |
| 489 | | /// @} |
| 490 | | |
| 491 | | /// @name 'Structors |
| 492 | | /// @{ |
| 493 | | public: |
| 494 | | ApplyForcesEventData(PhysicsActor* _pShape) |
| 495 | | : m_pShape(_pShape) |
| 496 | | { |
| 497 | | } |
| 498 | | |
| 499 | | virtual ~ApplyForcesEventData() |
| 500 | | { |
| 501 | | } |
| 502 | | /// @} |
| 503 | | |
| 504 | | /// @name Member Variables |
| 505 | | /// @{ |
| 506 | | private: |
| 507 | | PhysicsActor* m_pShape; |
| 508 | | /// @} |
| 509 | | |
| 510 | | }; // class ApplyForcesEventData; |
| 511 | | |
| 512 | | void* pBody = btRigidBodyGetUserData(_body); |
| 513 | | if (pBody != NULL) |
| 514 | | { |
| 515 | | PhysicsActor* pPhysicsActor = static_cast<PhysicsActor*>(pBody); |
| 516 | | |
| 517 | | // Only apply forces if the state is active |
| 518 | | if (pPhysicsActor->m_activationState != 0) |
| 519 | | { |
| 520 | | ApplyForcesEventData eventData(pPhysicsActor); |
| 521 | | eventData.getActor().onApplyForcesEvent(eventData); |
| 522 | | } |
| 523 | | } |
| 524 | | } |
| 525 | | |
| 526 | | //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ |
| 527 | | void |
| 528 | | PhysicsActor::ActivationStateCallback(const btRigidBody* _body, unsigned _state) |
| 529 | | { |
| 530 | | void* pBody = btRigidBodyGetUserData(_body); |
| 531 | | if (pBody != NULL) |
| 532 | | { |
| 533 | | static_cast<PhysicsActor*>(pBody)->setActivationState(_state); |
| 534 | | } |
| 535 | | } |
| 536 | | |
| 537 | | //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ |