Beispiel #1
0
void Interpolator::Update(uint32 frame_time) {
	if (_ValidMethod() == false) {
		if (VIDEO_DEBUG)
			cerr << "VIDEO WARNING: " << __FUNCTION__ << " was called when an invalid method was set" << endl;
		return;
	}

	// update current time
	_current_time += frame_time;

	if (_current_time > _end_time) {
		_current_time = _end_time;
		_finished = true;
	}

	// Calculate a value from 0.0f to 1.0f that tells how far we are in the interpolation
	float progress;

	if (_end_time == 0) {
		progress = 1.0f;
	}
	else {
		progress = static_cast<float>(_current_time) / static_cast<float>(_end_time);
	}

	if (progress > 1.0f) {
		if (VIDEO_DEBUG)
			cerr << "VIDEO WARNING: " << __FUNCTION__ << " calculated a progress value greater than 1.0" << endl;
		progress = 1.0f;
	}

	// Apply a transformation based on the interpolation method
	switch(_method) {
		case VIDEO_INTERPOLATE_EASE:
			progress = _EaseTransform(progress);
			break;
		case VIDEO_INTERPOLATE_SRCA:
			progress = 0.0f;
			break;
		case VIDEO_INTERPOLATE_SRCB:
			progress = 1.0f;
			break;
		case VIDEO_INTERPOLATE_FAST:
			progress = _FastTransform(progress);
			break;
		case VIDEO_INTERPOLATE_SLOW:
			progress = _SlowTransform(progress);
			break;
		case VIDEO_INTERPOLATE_LINEAR:
			// Nothing to do, just use progress value as it is
			break;
		default:
			if (VIDEO_DEBUG)
				cerr << "VIDEO WARNING: " << __FUNCTION__ << " the current method did not match any supported methods" << endl;
			return;
	};

	_current_value = Lerp(progress, _a, _b);
} // void Interpolator::Update(uint32 frame_time)
Beispiel #2
0
void Interpolator::SetMethod(InterpolationMethod method) {
	if (_finished == false) {
		if (VIDEO_DEBUG)
			cerr << "VIDEO WARNING: " << __FUNCTION__ << " was called when an interpolation was still in progress" << endl;
		return;
	}

	_method = method;
	if (_ValidMethod() == false) {
		if (VIDEO_DEBUG)
			cerr << "VIDEO WARNING: " << __FUNCTION__ << " was passed an invalid method argument" << endl;
	}
}
Beispiel #3
0
void Interpolator::SetMethod(InterpolationMethod method)
{
    if(_finished == false) {
        IF_PRINT_WARNING(MODE_MANAGER_DEBUG)
                << " was called when an interpolation was still in progress" << std::endl;
        return;
    }

    _method = method;
    if(_ValidMethod() == false) {
        IF_PRINT_WARNING(MODE_MANAGER_DEBUG)
                << " was passed an invalid method argument" << std::endl;
    }
}
Beispiel #4
0
void Interpolator::Start(float a, float b, uint32 milliseconds) {
	if (_ValidMethod() == false) {
		if (VIDEO_DEBUG)
			cerr << "VIDEO WARNING: " << __FUNCTION__ << " was called when an invalid interpolation method was set" << endl;
		return;
	}

	_a = a;
	_b = b;

	_current_time = 0;
	_end_time = milliseconds;
	_finished = false;

	Update(0);  // Do an initial update so that we have a valid value for GetValue()
}
Beispiel #5
0
void Interpolator::Start(float a, float b, uint32 milliseconds)
{
    if(_ValidMethod() == false) {
        IF_PRINT_WARNING(MODE_MANAGER_DEBUG)
                << " was called when an invalid interpolation method was set" << std::endl;
        return;
    }

    _a = a;
    _b = b;

    _current_time = 0;
    _end_time = milliseconds;
    _finished = false;

    Update(0);  // Do an initial update so that we have a valid value for GetValue()
}