51 float temporaryMatrix[16];
53 temporaryMatrix[12] =
x;
54 temporaryMatrix[13] =
y;
55 temporaryMatrix[14] = z;
64 for(i = 0; i < 4; i++)
66 for(j = 0; j < 4; j++)
68 theResult[4 * i + j] = operand1[j] * operand2[4 * i] + operand1[4 + j] * operand2[4 * i + 1] +
69 operand1[8 + j] * operand2[4 * i + 2] + operand1[12 + j] * operand2[4 * i + 3];
73 for(
int i = 0; i < 16; i++)
75 destination[i] = theResult[i];
81 float temp, xDistance, yDistance, zDistance;
83 xDistance = right -
left;
85 zDistance = zFar - zNear;
87 matrix[0] = temp / xDistance;
88 matrix[5] = temp / yDistance;
89 matrix[8] = (right +
left) / xDistance;
90 matrix[9] = (top +
bottom) / yDistance;
91 matrix[10] = (-zFar - zNear) / zDistance;
93 matrix[14] = (-temp * zFar) / zDistance;
97 void matrixPerspective(
float* matrix,
float fieldOfView,
float aspectRatio,
float zNear,
float zFar)
100 ymax = zNear * tanf(fieldOfView *
M_PI / 360.0);
101 xmax = ymax * aspectRatio;
102 matrixFrustum(matrix, -xmax, xmax, -ymax, ymax, zNear, zFar);
107 float tempMatrix[16];
119 float tempMatrix[16];
131 float tempMatrix[16];
143 float tempMatrix[16];
154 return M_PI * degrees / 180.0f;
void matrixMultiply(float *destination, float *operand1, float *operand2)
Takes 2 matrices and multiplies them together. Then stores the result in a third matrix.
void matrixScale(float *matrix, float x, float y, float z)
Scales a matrix by a given factor in the x, y and z axis.
float matrixDegreesToRadians(float degrees)
Function to convert degrees into Radians.
void matrixIdentityFunction(float *matrix)
Takes a 4 * 4 and sets the elements to the Identity function.
void matrixPerspective(float *matrix, float fieldOfView, float aspectRatio, float zNear, float zFar)
Create a perspective projection matrix and store the results in the first parameter.
void matrixRotateX(float *matrix, float angle)
Rotates a matrix around the x axis by a given angle.
#define M_PI
The value of pi.
void matrixTranslate(float *matrix, float x, float y, float z)
Takes in a 4 * 4 matrix and translates it by the vector defined by x y and z.
void matrixRotateZ(float *matrix, float angle)
Rotates a matrix around the Z axis by a given angle.
GLint GLint GLint GLint GLint x
void matrixFrustum(float *matrix, float left, float right, float bottom, float top, float zNear, float zFar)
Create a viewing frustum and store the result in the first parameter. This is usually called by matri...
void matrixRotateY(float *matrix, float angle)
Rotates a matrix around the y axis by a given angle.