Exemple #1
0
/* Perform translation operations on a matrix */
void translate(GLfloat *matrix, GLfloat x, GLfloat y, GLfloat z) {
	GLfloat newmatrix[16] = IDENTITY_MATRIX4;

	newmatrix[12] = x;
	newmatrix[13] = y;
	newmatrix[14] = z;

	multiply4x4(matrix, newmatrix);
}
Exemple #2
0
void
scale(float *matrix, float x, float y, float z)
{
    float newmatrix[16] =
    {
        x, 0.f, 0.f, 0.f,
        0.f, y, 0.f, 0.f,
        0.f, 0.f, z, 0.f,
        0.f, 0.f, 0.f, 1.f
    };

    multiply4x4(matrix, newmatrix);
}
Exemple #3
0
/* Rotate a matrix by an angle on a X, Y, or Z axis */
void rotate(GLfloat *matrix, GLfloat angle, AXIS axis) {
	const GLfloat d2r = 0.0174532925199; /* PI / 180 */
	const int cos1[3] = { 5, 0, 0 };
	const int cos2[3] = { 10, 10, 5 };
	const int sin1[3] = { 6, 2, 1 };
	const int sin2[3] = { 9, 8, 4 };
	GLfloat newmatrix[16] = IDENTITY_MATRIX4;

	newmatrix[cos1[axis]] = cos(d2r * angle);
	newmatrix[sin1[axis]] = -sin(d2r * angle);
	newmatrix[sin2[axis]] = -newmatrix[sin1[axis]];
	newmatrix[cos2[axis]] = newmatrix[cos1[axis]];

	multiply4x4(matrix, newmatrix);
}