Exemple #1
0
/*	FUNCTION:		GLCreateModelViewMatrix
	ARGUMENTS:		m			destination matrix
					x,y,z		position
					yaw			compass direction, 0-north, 90-east, 180-south, 270-west
					pitch		azimuth, -90 down, 0 forwad, 90 up
					roll		rotation around forward axis
	RETURN:			n/a
	DESCRIPTION:	Position camera
*/
void GLCreateModelViewMatrix(float *m, float x, float y, float z, float yaw, float pitch, float roll)
{
	//	same as gluLookAt
	Quaternion q, qDir, qAzim;
	qAzim.GenerateLocalRotation(pitch + 90.0f, -1.0f, 0.0f, 0.0f);
	qDir.GenerateLocalRotation(yaw, 0.0f, 0.0f, 1.0f);
	q = qAzim * qDir;
	
	if (roll != 0)
	{
		Quaternion qTilt;
		qTilt.GenerateLocalRotation(roll, 0, 0, 1);
		q = qTilt * q;
	}
	q.CreateRotatedQuaternion(m);

	//	move camera
	float mov[16];
	GLCreateIdentityMatrix(mov);
	mov[12] = -x;
	mov[13] = -y;
	mov[14] = -z;
	GLMatrixMultiply(m, m, mov);
}