add Makefile, SConstruct, fix compiler errors

This commit is contained in:
Josh Holtrop 2011-05-09 16:38:31 -04:00
parent 26bc6781cb
commit e76503001e
3 changed files with 38 additions and 13 deletions

10
glslUtil/Makefile Normal file
View File

@ -0,0 +1,10 @@
export SCONSFLAGS := -Q
all:
@scons
install:
@scons $@
clean:
@scons -c

4
glslUtil/SConstruct Normal file
View File

@ -0,0 +1,4 @@
# vim:filetype=python
env = Environment()
env.Object('glslUtil.o', 'glslUtil.c')

View File

@ -1,38 +1,48 @@
#include <string.h>
#include "glslUtil.h" #include "glslUtil.h"
void guMatrixLoadIdentity(guMatrix4x4 *m) void guMatrixLoadIdentity(guMatrix4x4 *m)
{ {
for (int i = 0; i < 4; i++) int i, j;
for (i = 0; i < 4; i++)
{ {
for (int j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
m[i][j] = (i == j) ? 1.0 : 0.0; (*m)[i][j] = (i == j) ? 1.0 : 0.0;
} }
} }
} }
void guMatrixMult(guMatrix4x4 *m, guMatrix4x4 *a, guMatrix4x4 *b) void guMatrixMult(guMatrix4x4 *m, guMatrix4x4 *a, guMatrix4x4 *b)
{ {
for (int i = 0; i < 4; i++) guMatrix4x4 tmp;
int i, j, p;
if (m == a)
{ {
for (int j = 0; j < 4; j++) memcpy(&tmp, a, sizeof(tmp));
a = &tmp;
}
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{ {
float v = 0.0; float v = 0.0;
for (int p = 0; p < 4; p++) for (p = 0; p < 4; p++)
{ {
v += a[i][p] * b[p][j]; v += (*a)[i][p] * (*b)[p][j];
} }
m[i][j] = v; (*m)[i][j] = v;
} }
} }
} }
void guMatrixTranslate(guMatrix4x4 *m, float x, float y, float z) void guMatrixTranslate(guMatrix4x4 *m, float x, float y, float z)
{ {
for (int i = 0; i < 4; i++) int i;
for (i = 0; i < 4; i++)
{ {
m[i][3] += m[i][0] * x + m[i][1] * y + m[i][2] * z; (*m)[i][3] += (*m)[i][0] * x + (*m)[i][1] * y + (*m)[i][2] * z;
} }
} }
@ -41,10 +51,11 @@ void guMatrixFrustum(guMatrix4x4 *m,
float bottom, float top, float bottom, float top,
float near, float far) float near, float far)
{ {
int i, j;
guMatrix4x4 mult; guMatrix4x4 mult;
for (int i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
for (int j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
mult[i][j] = 0.0; mult[i][j] = 0.0;
} }
@ -56,5 +67,5 @@ void guMatrixFrustum(guMatrix4x4 *m,
mult[2][2] = - (far + near) / (far - near); mult[2][2] = - (far + near) / (far - near);
mult[2][3] = - 2 * far * near / (far - near); mult[2][3] = - 2 * far * near / (far - near);
mult[3][2] = -1.0; mult[3][2] = -1.0;
guMatrixMult(m, &mult); guMatrixMult(m, m, &mult);
} }