add guMatrixRotate()

This commit is contained in:
Josh Holtrop 2011-05-09 16:56:19 -04:00
parent fe93dffab0
commit 2d7bafe23b
2 changed files with 38 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include <math.h>
#include <string.h>
#include "glslUtil.h"
@ -58,6 +59,41 @@ void guMatrixScale(guMatrix4x4 *m, GLfloat x, GLfloat y, GLfloat z)
}
}
void guMatrixRotate(guMatrix4x4 *m, GLfloat angle,
GLfloat x, GLfloat y, GLfloat z)
{
GLfloat lx = x, ly = y, lz = z, p;
p = lx*lx + ly*ly + lz*lz;
if (p != 1.0)
{
GLfloat scale = sqrt(p);
lx /= scale;
ly /= scale;
lz /= scale;
}
GLfloat c = cos(angle);
GLfloat s = sin(angle);
guMatrix4x4 mult;
GLfloat oc = 1 - c;
mult[0][0] = lx * lx * oc + c;
mult[0][1] = lx * ly * oc - lz * s;
mult[0][2] = lx * lz * oc + ly * s;
mult[0][3] = 0.0;
mult[1][0] = ly * lx * oc + lz * s;
mult[1][1] = ly * ly * oc + c;
mult[1][2] = ly * lz * oc - lx * s;
mult[1][3] = 0.0;
mult[2][0] = lx * lz * oc - ly * s;
mult[2][1] = ly * lz * oc + lx * s;
mult[2][2] = lz * lz * oc + c;
mult[2][3] = 0.0;
mult[3][0] = 0.0;
mult[3][1] = 0.0;
mult[3][2] = 0.0;
mult[3][3] = 1.0;
guMatrixMult(m, m, &mult);
}
void guMatrixFrustum(guMatrix4x4 *m,
GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,

View File

@ -18,6 +18,8 @@ void guMatrixLoadIdentity(guMatrix4x4 *m);
void guMatrixMult(guMatrix4x4 *m, guMatrix4x4 *a, guMatrix4x4 *b);
void guMatrixTranslate(guMatrix4x4 *m, GLfloat x, GLfloat y, GLfloat z);
void guMatrixScale(guMatrix4x4 *m, GLfloat x, GLfloat y, GLfloat z);
void guMatrixRotate(guMatrix4x4 *m, GLfloat angle,
GLfloat x, GLfloat y, GLfloat z);
void guMatrixFrustum(guMatrix4x4 *m,
GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,