-------------------------- RigidBodySystem::Process Synchronize physics transforms - if the rigid body was externally transformed, it moves the rigid body, otherwise the rigid body moves the transform
| 75 | // - if the rigid body was externally transformed, it moves the rigid body, otherwise the rigid body moves the transform |
| 76 | // |
| 77 | void RigidBodySystem::Process(ComponentRange<RigidBodySystemView>& range) |
| 78 | { |
| 79 | for (RigidBodySystemView& view : range) |
| 80 | { |
| 81 | // #todo: split non dynamic rigid bodies into a new component type, e.g ColliderComponent |
| 82 | if (!(view.rigidBody->m_IsDynamic)) |
| 83 | { |
| 84 | continue; |
| 85 | } |
| 86 | |
| 87 | // extract bullet transform |
| 88 | //-------------------------- |
| 89 | ET_ASSERT(view.rigidBody->m_Body != nullptr); |
| 90 | |
| 91 | btMotionState* const motionState = view.rigidBody->m_Body->getMotionState(); |
| 92 | ET_ASSERT(motionState != nullptr); |
| 93 | |
| 94 | btTransform rbTransform; |
| 95 | motionState->getWorldTransform(rbTransform); |
| 96 | |
| 97 | bool modified = false; |
| 98 | |
| 99 | // #todo: deal with transform hierachy |
| 100 | |
| 101 | // deal with translations |
| 102 | //-------------------------- |
| 103 | if (view.transf->HasTranslationChanged()) |
| 104 | { |
| 105 | rbTransform.setOrigin(ToBtVec3(view.transf->GetPosition())); |
| 106 | modified = true; |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | view.transf->SetPosition(ToEtmVec3(rbTransform.getOrigin())); // will make flags dirty |
| 111 | } |
| 112 | |
| 113 | // deal with rotations |
| 114 | //-------------------------- |
| 115 | if (view.transf->HasRotationChanged()) |
| 116 | { |
| 117 | rbTransform.setRotation(ToBtQuat(view.transf->GetRotation())); |
| 118 | modified = true; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | view.transf->SetRotation(ToEtmQuat(rbTransform.getRotation())); // will also make flags dirty |
| 123 | } |
| 124 | |
| 125 | // write back transform changes to rigid body |
| 126 | //-------------------------------------------- |
| 127 | if (modified) |
| 128 | { |
| 129 | motionState->setWorldTransform(rbTransform); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 |
nothing calls this directly
no test coverage detected