50 float temporaryMatrix[16];
52 temporaryMatrix[12] =
x;
53 temporaryMatrix[13] =
y;
54 temporaryMatrix[14] = z;
63 for(i = 0; i < 4; i++)
65 for(j = 0; j < 4; j++)
67 theResult[4 * i + j] = operand1[j] * operand2[4 * i] + operand1[4 + j] * operand2[4 * i + 1] +
68 operand1[8 + j] * operand2[4 * i + 2] + operand1[12 + j] * operand2[4 * i + 3];
72 for(
int i = 0; i < 16; i++)
74 destination[i] = theResult[i];
80 float temp, xDistance, yDistance, zDistance;
82 xDistance = right -
left;
84 zDistance = zFar - zNear;
86 matrix[0] = temp / xDistance;
87 matrix[5] = temp / yDistance;
88 matrix[8] = (right +
left) / xDistance;
89 matrix[9] = (top +
bottom) / yDistance;
90 matrix[10] = (-zFar - zNear) / zDistance;
92 matrix[14] = (-temp * zFar) / zDistance;
96 void matrixPerspective(
float* matrix,
float fieldOfView,
float aspectRatio,
float zNear,
float zFar)
99 ymax = zNear * tanf(fieldOfView *
M_PI / 360.0);
100 xmax = ymax * aspectRatio;
101 matrixFrustum(matrix, -xmax, xmax, -ymax, ymax, zNear, zFar);
106 float tempMatrix[16];
118 float tempMatrix[16];
130 float tempMatrix[16];
142 float tempMatrix[16];
153 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.