animator stops animating while camera is re-positioning?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
fargoth
Posts: 22
Joined: Fri May 01, 2015 7:43 pm

animator stops animating while camera is re-positioning?

Post by fargoth »

I've made a little camera controller class which makes the camera fly to wherever it's pointed at.
But my circular motion animator stops animating while the camera is on the move... am I doing something wrong?

Here's my code:

Code: Select all

_levelStartTime = _timer->getRealTime();
        unsigned int lastFrameTime = _timer->getRealTime();
        bool isPlayerPossingCamera = false;
        //first run while _finishPointWatchTime has not elapsed yet, than wait for player to
        //possess the camera, and finaly wait for the camera to finish it's movement.
        while (((_timer->getRealTime() - _finishPointWatchTime  < _levelStartTime || !isPlayerPossingCamera)
                    && _device->run()) || _camera.isMoving())
        {
            if ((_timer->getRealTime() - _finishPointWatchTime >= _levelStartTime)
                && !isPlayerPossingCamera)
            {
                isPlayerPossingCamera = true;
                if (_playerViews.size())
                    _playerViews.front().possesCamera(&_camera);
            }
            _videoDriver->beginScene(true, true, irr::video::SColor(255, 100, 101, 140));
            _sceneManager->drawAll();
            _guiEnvironment->drawAll();
            _videoDriver->endScene();
            unsigned int dt = _timer->getRealTime() - lastFrameTime;
            if (dt < _minTimeBetweenFrames*1000.0f)
                _device->sleep((_minTimeBetweenFrames*1000.0f) - dt);
            dt = _timer->getRealTime() - lastFrameTime;
            _camera.evolve(static_cast<float>(dt) / 1000.0f);
            lastFrameTime = _timer->getRealTime();
        }


the possesCamera function set a new target for the camera controller, and the camera.evolve function simply flies the camera to the appropriate position while maintaining the position-target vector constant.

Code: Select all

void CCameraController::evolve(float deltaT)
    {
        if (_isPositionNeedsModifying)
        {   
            //accelerate until x = 0.5v^2/a
            irr::core::vector3df currentPosition = _camera->getPosition();
            float reminingDistance = currentPosition.getDistanceFrom(_desiredPos);
            if (reminingDistance > 0.5 * _positionTransitionSpeed*_positionTransitionSpeed / Acceleratoin)
                if (_positionTransitionSpeed + Acceleratoin*deltaT < MaxSpeed)
                    _positionTransitionSpeed += Acceleratoin*deltaT;
                else
                    _positionTransitionSpeed = MaxSpeed;
            else if (_positionTransitionSpeed - Acceleratoin*deltaT > 0)
                _positionTransitionSpeed -= Acceleratoin*deltaT;
            else
                _positionTransitionSpeed = 0;
            if (reminingDistance <= _positionTransitionSpeed * deltaT)
            {
                _camera->setPosition(_desiredPos);
                _isPositionNeedsModifying = false;
            }
            else
            {
                _camera->setPosition(_camera->getPosition() + _posChangeDir * _positionTransitionSpeed * deltaT);
            }
            currentPosition = _camera->getPosition();
        }
        if (_isTargetNeedsModifying)
        {
            irr::core::vector3df currentTarget = _camera->getTarget();
            float reminingDistance = currentTarget.getDistanceFrom(_desiredTarget);
            //accelerate until x = 0.5v^2/a
            if (reminingDistance > 0.5 * _targetTransitionSpeed*_targetTransitionSpeed / Acceleratoin)
                if (_targetTransitionSpeed + Acceleratoin*deltaT < MaxSpeed)
                    _targetTransitionSpeed += Acceleratoin*deltaT;
                else
                    _targetTransitionSpeed = MaxSpeed;
            else if (_targetTransitionSpeed - Acceleratoin*deltaT > 0)
                _targetTransitionSpeed -= Acceleratoin*deltaT;
            else
                _targetTransitionSpeed = 0;
            if (reminingDistance <= _targetTransitionSpeed * deltaT)
            {
                _camera->setTarget(_desiredTarget);
                _isTargetNeedsModifying = false;
            }
            else
            {
                _camera->setTarget(_camera->getTarget() + _targetChangeDir * _targetTransitionSpeed * deltaT);
            }
        }
        if (_isPositionNeedsModifying || _isTargetNeedsModifying)
        {
            
            if (_posToTarget.crossProduct(_desiredUpVector) != _leftVector)
            {
                _camera->setUpVector(_leftVector.crossProduct(_posToTarget));
            }
        }
        
    }
Post Reply