public void Update(ComponentizedEntity entity, IGameContext gameContext, IUpdateContext updateContext)
        {
            if (!Enabled)
            {
                return;
            }

            if (_jitterWorld != _physicsEngine.GetInternalPhysicsWorld())
            {
                // TODO: Deregister rigid bodies from old world.
                if (_jitterWorld != null && _physicsControllerConstraint != null)
                {
                    _jitterWorld.RemoveConstraint(_physicsControllerConstraint);
                    _physicsControllerConstraint = null;
                }
                _jitterWorld = _physicsEngine.GetInternalPhysicsWorld();
            }

            if (_physicalComponent.RigidBodies.Length > 0 && _physicalComponent.RigidBodies[0] != _rigidBody)
            {
                if (_physicsControllerConstraint != null)
                {
                    _jitterWorld.RemoveConstraint(_physicsControllerConstraint);
                    _physicsControllerConstraint = null;
                }
            }

            if (_physicalComponent.RigidBodies.Length > 0)
            {
                if (_physicsControllerConstraint == null)
                {
                    _physicsControllerConstraint = new PhysicsControllerConstraint(
                        _jitterWorld,
                        _physicalComponent.RigidBodies[0]);
                    _jitterWorld.AddConstraint(_physicsControllerConstraint);
                }

                _physicsControllerConstraint.TargetVelocity = TargetVelocity.ToJitterVector();
                _physicsControllerConstraint.TryJump        = TryJump;
                _physicsControllerConstraint.JumpVelocity   = JumpVelocity;
                _physicsControllerConstraint.Stiffness      = Stiffness;

                if (TargetVelocity.LengthSquared() > 0f)
                {
                    // Wake up the rigid body.
                    _physicalComponent.RigidBodies[0].IsActive = true;
                }
            }
        }
        public void SyncPendingChanges()
        {
            var physicsWorld = _physicsEngine.GetInternalPhysicsWorld();

            if (physicsWorld != null)
            {
                if (_pendingGravity != null)
                {
                    physicsWorld.Gravity = _pendingGravity.Value.ToJitterVector();
                    _pendingGravity      = null;
                }

                if (_pendingSpeculativeContacts != null)
                {
                    physicsWorld.CollisionSystem.EnableSpeculativeContacts = _pendingSpeculativeContacts.Value;
                    _pendingSpeculativeContacts = null;
                }

                if (_pendingCoefficientMixingType != null)
                {
                    physicsWorld.ContactSettings.MaterialCoefficientMixing = _pendingCoefficientMixingType.Value;
                    _pendingCoefficientMixingType = null;
                }

                if (_pendingConsiderAngularVelocityCallback != null)
                {
                    physicsWorld.ContactSettings.ConsiderAngularVelocityCallback = _pendingConsiderAngularVelocityCallback;
                    _pendingConsiderAngularVelocityCallback = null;
                }

                if (_pendingCalculateStaticFrictionCallback != null)
                {
                    physicsWorld.ContactSettings.CalculateStaticFrictionCallback = _pendingCalculateStaticFrictionCallback;
                    _pendingCalculateStaticFrictionCallback = null;
                }

                if (_pendingCalculateDynamicFrictionCallback != null)
                {
                    physicsWorld.ContactSettings.CalculateDynamicFrictionCallback = _pendingCalculateDynamicFrictionCallback;
                    _pendingCalculateDynamicFrictionCallback = null;
                }

                if (_pendingCalculateRestitutionCallback != null)
                {
                    physicsWorld.ContactSettings.CalculateRestitutionCallback = _pendingCalculateRestitutionCallback;
                    _pendingCalculateRestitutionCallback = null;
                }
            }
        }