Exemplo n.º 1
0
//see http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class
void SimpleCamera::getLookAt(MATRIX &look)
{
	MATRIX m1, m2, m3, translation;
	QUATERNION q;

	// Make the Quaternions that will represent our rotations
	MatrixQuaternionRotationAxis(_qPitch, Vec3(1.0f, 0.0f, 0.0f), _pitchRadians);
	MatrixQuaternionRotationAxis(_qHeading, Vec3(0.0f, 1.0f, 0.0f), _headingRadians);

	// Combine the pitch and heading rotations and store the results in q
	MatrixQuaternionMultiply(q, _qHeading, _qPitch);
	MatrixRotationQuaternion(m1, q);
	
	// Create a matrix from the pitch Quaternion and get the j vector 
	// for our direction.
	MatrixRotationQuaternion(m3, _qPitch);
	_direction.y = m3.f[9];

	// Combine the heading and pitch rotations and make a matrix to get
	// the i and j vectors for our direction.
	MatrixQuaternionMultiply(q, _qPitch, _qHeading);
	MatrixRotationQuaternion(m2, q);
	_direction.x = m2.f[8];
	_direction.z = -m2.f[10];

	// Increment our position by the vector
	_position += (_direction * _forwardVelocity);

	// Translate to our new position.
	MatrixTranslation(translation, -_position.x, -_position.y, -_position.z);
	MatrixMultiply(look, translation, m1);
}
const MATRIX &TransformInterpolator::current() const
{
	btScalar progress(1.0);
	if (d->totalSteps) {
		progress = (float)d->currentStep / (float)d->totalSteps;
	}
	
	QUATERNION qOut;
	MatrixQuaternionSlerp(qOut, d->startRotation, d->endRotation, progress);
	MatrixRotationQuaternion(d->currentTransform, qOut);
	MatrixTranslationLerp(d->currentTransform, d->startTransform, d->endTransform, progress);
	
	return d->currentTransform;
}