void Orientation::activate()
{	
	if(isActive())
		return;

	m_start = utils::getEntityRotation(m_agent_eID);
	utils::radToDegV(&m_start);
	m_current = m_start;	

	if(!m_targetIsRotation)
	{
		//if the target is a point, then this is a "turn towards" action and we must compute the rotation
		Vec3f direction = m_target - utils::getEntityPosition(m_agent_eID);
		
		//This h3d function assumes that the view direction is (0,0,-1)
		//correct the rotation value based on the agent's forward view direction
		m_target = direction.toRotation();
		utils::radToDegV(&m_target);

		Vec3f fwdView(Config::getParamF(Agent_Param::FwdViewX_F), Config::getParamF(Agent_Param::FwdViewY_F), Config::getParamF(Agent_Param::FwdViewZ_F));
		if(fwdView.z > 0)
			m_target.y += 180.0f; //TODO: do corrections for other axis too	
	}

	//optimize rotations
	m_target.x = optimizeRotation(m_current.x, m_target.x);
	m_target.y = optimizeRotation(m_current.y, m_target.y);
	m_target.z = optimizeRotation(m_current.z, m_target.z);	

	m_distance = (m_target - m_start).length();
	
	if(utils::isEmpty(m_animationName)) chooseAnimation();
	startMovement(Config::getParamF(Agent_Param::OrientationSpeedMult_F));
}
示例#2
0
void Locomotion::activate()
{
	if(isActive())
		return;

	m_start = utils::getEntityPosition(m_agent_eID);
	m_current = m_start;
	m_distance = (m_target - m_start).length();

	startMovement(Config::getParamF(Agent_Param::LocomotionSpeedMult_F));
}
	/**
	 * Moves the motor to the given position.
	 *
	 * @param motorRotation The rotational data for the motor.
	 **/
	void StepperMotor::moveTo(const DataTypes::MotorRotation<double>& motorRotation){
		writeRotationData(motorRotation);
		startMovement();
	}
示例#4
0
void MadsPlayer::move() {
	bool routeFlag = false;

	if (_moving) {
		int idx = _routeCount; 
		while (!_v844C0 && (_destPos.x == _playerPos.x) && (_destPos.y == _playerPos.y)) {
			if (idx != 0) {
				--idx;
				SceneNode &node = _madsVm->scene()->getSceneResources()._nodes[_routeIndexes[idx]];
				_destPos = node.pt;
				routeFlag = true;
			} else if (_v844BE == idx) {
				// End of walking path
				_routeCount = 0;
				_moving = false;
				turnToDestFacing();
				routeFlag = true;
				idx = _routeCount;
			} else {
				_v844C0 = _v844BE;
				_v844BC = true;
				_v844BE = 0;
				_stepEnabled = true;
				routeFlag = false;
			}

			if (!_moving)
				break;
		}
		_routeCount = idx;
	}

	if (routeFlag && _moving)
		startMovement();

	if (_newDirection != _direction)
		dirChanged();
	else if (!_moving)
		updateFrame();

	int var1 = _unk1;
	if (_unk4 && (_hypotenuse > 0)) {
		int v1 = -(_currentScale - 100) * (_posDiff.x - 1) / _hypotenuse + _currentScale;
		var1 = MAX(1, 10000 / (v1 * _currentScale * var1));
	}

	if (!_moving || (_direction != _newDirection))
		return;

	Common::Point newPos = _playerPos;

	if (_v8452E < var1) {
		do {
			if (_v8452C < _posDiff.x)
				_v8452C += _posDiff.y;
			if (_v8452C >= _posDiff.x) {
				if ((_posChange.y > 0) || (_v844C0 != 0))
					newPos.y += _yDirection;
				--_posChange.y;
				_v8452C -= _posDiff.x;
			}

			if (_v8452C < _posDiff.x) {
				if ((_posChange.x > 0) || (_v844C0 != 0))
					newPos.x += _xDirection;
				--_posChange.x;
			}

			if ((_v844BC == 0) && (_v844C0 == 0) && (_v844BE == 0)) {
				routeFlag = _madsVm->scene()->getDepthHighBit(newPos);

				if (_special == 0)
					_special = _madsVm->scene()->getDepthHighBits(newPos);
			}

			_v8452E += _v84530;

		} while ((_v8452E < var1) && !routeFlag && ((_posChange.x > 0) || (_posChange.y > 0) || (_v844C0 != 0)));
	}

	_v8452E -= var1;

	if (routeFlag)
		moveComplete();
	else {
		if (!_v844C0) {
			// If the move is complete, make sure the position is exactly on the given destination
			if (_posChange.x == 0)
				newPos.x = _destPos.x;
			if (_posChange.y == 0)
				newPos.y = _destPos.y;
		}

		_playerPos = newPos;
	}
}
示例#5
0
文件: player.cpp 项目: Cruel/scummvm
void Player::move() {
	Scene &scene = _vm->_game->_scene;
	Rails &rails = scene._rails;
	bool newFacing = false;

	if (_moving) {
		while (!_walkOffScreen && _playerPos == _targetPos) {
			bool isRouteEmpty = rails.empty();
			if (!isRouteEmpty) {
				const WalkNode &node = rails.popNode();

				_targetPos = node._walkPos;
				newFacing = true;
			} else if (!_walkOffScreenSceneId) {
				// End of walking path
				rails.resetRoute();
				_moving = false;
				setFinalFacing();
				newFacing = true;
			} else {
				_walkOffScreen = _walkOffScreenSceneId;
				_walkAnywhere = true;
				_walkOffScreenSceneId = 0;
				_stepEnabled = false;
				newFacing = false;
			}

			if (!_moving)
				break;
		}
	}

	if (newFacing && _moving)
		startMovement();

	if (_turnToFacing != _facing) {
		changeFacing();
	} else if (!_moving) {
		updateFrame();
		activateTrigger();
	}

	int velocity = _velocity;
	if (_scalingVelocity && (_totalDistance > 0)) {
		int angleRange = 100 - _currentScale;
		int angleScale = angleRange * (_posDiff.x - 1) / _totalDistance + _currentScale;
		velocity = MAX(1L, (angleScale * _currentScale * velocity) / 10000L);
	}

	if (!_moving || (_facing != _turnToFacing))
		return;

	Common::Point newPos = _playerPos;
	newFacing = false;
	_special = 0;

	if (_distAccum < velocity) {
		do {
			if (_pixelAccum < _posDiff.x)
				_pixelAccum += _posDiff.y;
			if (_pixelAccum >= _posDiff.x) {
				if ((_posChange.y > 0) || _walkOffScreen)
					newPos.y += _yDirection;
				--_posChange.y;
				_pixelAccum -= _posDiff.x;
			}

			if (_pixelAccum < _posDiff.x) {
				if ((_posChange.x > 0) || _walkOffScreen)
					newPos.x += _xDirection;
				--_posChange.x;
			}

			if (!_walkAnywhere && !_walkOffScreen && (_walkOffScreenSceneId == 0)) {
				newFacing = scene._depthSurface.getDepthHighBit(newPos);

				if (_special == 0)
					_special = scene.getDepthHighBits(newPos);
			}

			_distAccum += _deltaDistance;

		} while ((_distAccum < velocity) && !newFacing && ((_posChange.x > 0) || (_posChange.y > 0) || (_walkOffScreen != 0)));
	}

	_distAccum -= velocity;

	if (newFacing) {
		cancelCommand();
	} else {
		if (!_walkOffScreen) {
			// If the move is complete, make sure the position is exactly on the given destination
			if (_posChange.x == 0)
				newPos.x = _targetPos.x;
			if (_posChange.y == 0)
				newPos.y = _targetPos.y;
		}

		_playerPos = newPos;
	}
}