//http://en.wikipedia.org/wiki/Rotation_matrix]http://en.wikipedia.org/wiki/Rotation_matrix
static void createRotationMatrixZ(float angle, matrix_t rotation_matrix)
{
float radians = angle * M_PI / 180.f;
float c = cos(radians);
float s = sin(radians);
rotationMatrix[0]= c; rotationMatrix[4] = -s; rotationMatrix[ 8] = 0; rotationMatrix[12] = 0;
rotationMatrix[1]= s; rotationMatrix[5] = c; rotationMatrix[ 9] = 0; rotationMatrix[13] = 0;
rotationMatrix[2]= 0; rotationMatrix[6] = 0; rotationMatrix[10] = 1; rotationMatrix[14] = 0;
rotationMatrix[3]= 0; rotationMatrix[7] = 0; rotationMatrix[11] = 0; rotationMatrix[15] = 1;
}
// "optimized" versions
static void createRotationMatrixRotateLeft(matrix_t rotation_matrix)
{
rotationMatrix[0]= 0; rotationMatrix[4] = -1; rotationMatrix[ 8] = 0; rotationMatrix[12] = 0;
rotationMatrix[1]= 1; rotationMatrix[5] = 0; rotationMatrix[ 9] = 0; rotationMatrix[13] = 0;
rotationMatrix[2]= 0; rotationMatrix[6] = 0; rotationMatrix[10] = 1; rotationMatrix[14] = 0;
rotationMatrix[3]= 0; rotationMatrix[7] = 0; rotationMatrix[11] = 0; rotationMatrix[15] = 1;
}
static void createRotationMatrixRotateRight(matrix_t rotation_matrix)
{
rotationMatrix[0]= 0; rotationMatrix[4] = 1; rotationMatrix[ 8] = 0; rotationMatrix[12] = 0;
rotationMatrix[1]=-1; rotationMatrix[5] = 0; rotationMatrix[ 9] = 0; rotationMatrix[13] = 0;
rotationMatrix[2]= 0; rotationMatrix[6] = 0; rotationMatrix[10] = 1; rotationMatrix[14] = 0;
rotationMatrix[3]= 0; rotationMatrix[7] = 0; rotationMatrix[11] = 0; rotationMatrix[15] = 1;
}
void gluPerspective(float fovy, float aspect, float zNear, float zFar,matrix_t projectionMatrixRotated)
{
aspect = 1/aspect; //swap with/height
matrix_t rotation_matrix; //holds the rotation matrix
matrix_t projectionMatrix;
createRotationMatrixRotateLeft(rotation_matrix);
// could also be:
// createRotationMatrixRotateRight(rotation_matrix);
float f = (float)(1 / tan(fovy*DEG_TO_RAD/2));
projectionMatrix[0]= f/aspect; projectionMatrix[4]= 0; projectionMatrix[ 8]= 0; projectionMatrix[12]= 0;
projectionMatrix[1]= 0; projectionMatrix[5]= f; projectionMatrix[ 9]= 0; projectionMatrix[13]= 0;
projectionMatrix[2]= 0; projectionMatrix[6]= 0; projectionMatrix[10]=(zFar+zNear)/(zNear-zFar) ; projectionMatrix[14]= 2*(zFar*zNear)/(zNear-zFar);
projectionMatrix[3]= 0; projectionMatrix[7]= 0; projectionMatrix[11]=-1; projectionMatrix[15]= 0;
matrix_multiply(rotation_matrix, projectionMatrix, projectionMatrixRotated);
// could also be:
// matrix_multiply(projectionMatrix, rotationMatrix, projectionMatrixRotated);
}