Ejemplo n.º 1
0
void Model::manageAnimations(float dt) {
	float lastFrame = _elapsedTime;
	float nextFrame = _elapsedTime + dt;
	_elapsedTime = nextFrame;

	// Start a new animation if scheduled
	if (_nextAnimation) {
		// Note that this interrupts the current animation!
		_currentAnimation = _nextAnimation;
		_nextAnimation = 0;
		_elapsedTime = 0;
		lastFrame = 0;
		nextFrame = 0;
	}

	// If there is no current animation, select a default animation
	if (!_currentAnimation)
		selectDefaultAnimation();

	// If the current animation has finished, start a default animation
	if (_currentAnimation && nextFrame >= _currentAnimation->getLength()) {
		// Debug output
		selectDefaultAnimation();
		_elapsedTime = 0.0f;
		lastFrame = 0;
		nextFrame = 0;
	}

	if (_currentAnimation)
		_currentAnimation->update(this, lastFrame, nextFrame);
}
Ejemplo n.º 2
0
void Model::finalize() {
	_currentState = 0;

	createStateNamesList();
	setState();

	createBound();

	// Order all node children lists
	for (StateList::iterator s = _stateList.begin(); s != _stateList.end(); ++s)
		for (NodeList::iterator n = (*s)->rootNodes.begin(); n != (*s)->rootNodes.end(); ++n)
			(*n)->orderChildren();

	_currentAnimation = selectDefaultAnimation();
}
Ejemplo n.º 3
0
void Model::manageAnimations(float dt) {
	float lastFrame = _elapsedTime;
	float nextFrame = _elapsedTime + dt;
	_elapsedTime = nextFrame;

	// Start a new animation if scheduled, interrupting the currently playing animation
	if (_nextAnimation) {
		_currentAnimation = _nextAnimation;
		_nextAnimation    = 0;

		_elapsedTime = 0.0f;
		lastFrame    = 0.0f;
		nextFrame    = 0.0f;
	}

	// Animation finished?
	if (_currentAnimation && (nextFrame >= _currentAnimation->getLength())) {
		// Update the loop counter. If it's 0, then end the animation; otherwise, restart it

		if (_loopAnimation != 0) {
			if (_loopAnimation > 0)
				_loopAnimation--;

			_elapsedTime = 0.0f;
			lastFrame    = 0.0f;
			nextFrame    = 0.0f;
		} else
			_currentAnimation = 0;
	}

	// No animation, select a default one
	if (!_currentAnimation) {
		_currentAnimation = selectDefaultAnimation();

		_elapsedTime = 0.0f;
		lastFrame    = 0.0f;
		nextFrame    = 0.0f;
	}

	// Update the animation, if we have any
	if (_currentAnimation)
		_currentAnimation->update(this, lastFrame, nextFrame);
}
Ejemplo n.º 4
0
void Model::playDefaultAnimation() {
	_nextAnimation = selectDefaultAnimation();
	_loopAnimation = 0;
}