# HG changeset patch # User John Tsiombikas # Date 1408894960 -10800 # Node ID 7a2041ddb7e74224138fd1dceddc2de5eb2a85c0 # Parent 9b0db7dbde6e70d50d2807dfe1fa8958aac681a6 fixed line endings diff -r 9b0db7dbde6e -r 7a2041ddb7e7 src/game.cc --- a/src/game.cc Sun Aug 24 14:36:00 2014 +0300 +++ b/src/game.cc Sun Aug 24 18:42:40 2014 +0300 @@ -340,12 +340,12 @@ } static void draw_pyramid(float basesz, float height) -{ - float hsz = basesz / 2.0; - float theta = atan(hsz / height); - float nx = cos(theta); - float ny = sin(theta); - +{ + float hsz = basesz / 2.0; + float theta = atan(hsz / height); + float nx = cos(theta); + float ny = sin(theta); + glBegin(GL_TRIANGLES); glNormal3f(0, ny, nx); glVertex3f(-hsz, 0, hsz); @@ -364,4 +364,4 @@ glVertex3f(-hsz, 0, hsz); glVertex3f(0, height, 0); glEnd(); -} \ No newline at end of file +} diff -r 9b0db7dbde6e -r 7a2041ddb7e7 src/vr/mathutil.c --- a/src/vr/mathutil.c Sun Aug 24 14:36:00 2014 +0300 +++ b/src/vr/mathutil.c Sun Aug 24 18:42:40 2014 +0300 @@ -1,78 +1,78 @@ -#include -#include -#include "mathutil.h" - -#define M(i, j) ((i) * 4 + (j)) - -static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - -void rotation_matrix(const float *quat, float *matrix) -{ - matrix[0] = 1.0 - 2.0 * quat[1] * quat[1] - 2.0 * quat[2] * quat[2]; - matrix[1] = 2.0 * quat[0] * quat[1] + 2.0 * quat[3] * quat[2]; - matrix[2] = 2.0 * quat[2] * quat[0] - 2.0 * quat[3] * quat[1]; - matrix[3] = 0.0f; - - matrix[4] = 2.0 * quat[0] * quat[1] - 2.0 * quat[3] * quat[2]; - matrix[5] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[2]*quat[2]; - matrix[6] = 2.0 * quat[1] * quat[2] + 2.0 * quat[3] * quat[0]; - matrix[7] = 0.0f; - - matrix[8] = 2.0 * quat[2] * quat[0] + 2.0 * quat[3] * quat[1]; - matrix[9] = 2.0 * quat[1] * quat[2] - 2.0 * quat[3] * quat[0]; - matrix[10] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[1]*quat[1]; - matrix[11] = 0.0f; - - matrix[12] = matrix[13] = matrix[14] = 0.0f; - matrix[15] = 1.0f; - - transpose_matrix(matrix); -} - -void translation_matrix(const float *vec, float *matrix) -{ - memcpy(matrix, idmat, sizeof idmat); - matrix[12] = vec[0]; - matrix[13] = vec[1]; - matrix[14] = vec[2]; -} - -void mult_matrix(float *dest, const float *m1, const float *m2) -{ - int i, j; - float tmp[16]; - - for(i=0; i<4; i++) { - for(j=0; j<4; j++) { - tmp[M(i, j)] = m1[M(i, 0)] * m2[M(0, j)] + m1[M(i, 1)] * m2[M(1, j)] + - m1[M(i, 2)] * m2[M(2, j)] + m1[M(i, 3)] * m2[M(3, j)]; - } - } - memcpy(dest, tmp, sizeof tmp); -} - -void transpose_matrix(float *matrix) -{ - int i, j; - float tmp[16]; - - for(i=0; i<4; i++) { - for(j=0; j<4; j++) { - tmp[M(i, j)] = matrix[M(j, i)]; - } - } - memcpy(matrix, tmp, sizeof tmp); -} - -void print_matrix(const float *matrix) -{ - int i, j; - - for(i=0; i<4; i++) { - putchar('['); - for(j=0; j<4; j++) { - printf("%6.3f ", matrix[M(i, j)]); - } - printf("]\n"); - } -} \ No newline at end of file +#include +#include +#include "mathutil.h" + +#define M(i, j) ((i) * 4 + (j)) + +static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + +void rotation_matrix(const float *quat, float *matrix) +{ + matrix[0] = 1.0 - 2.0 * quat[1] * quat[1] - 2.0 * quat[2] * quat[2]; + matrix[1] = 2.0 * quat[0] * quat[1] + 2.0 * quat[3] * quat[2]; + matrix[2] = 2.0 * quat[2] * quat[0] - 2.0 * quat[3] * quat[1]; + matrix[3] = 0.0f; + + matrix[4] = 2.0 * quat[0] * quat[1] - 2.0 * quat[3] * quat[2]; + matrix[5] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[2]*quat[2]; + matrix[6] = 2.0 * quat[1] * quat[2] + 2.0 * quat[3] * quat[0]; + matrix[7] = 0.0f; + + matrix[8] = 2.0 * quat[2] * quat[0] + 2.0 * quat[3] * quat[1]; + matrix[9] = 2.0 * quat[1] * quat[2] - 2.0 * quat[3] * quat[0]; + matrix[10] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[1]*quat[1]; + matrix[11] = 0.0f; + + matrix[12] = matrix[13] = matrix[14] = 0.0f; + matrix[15] = 1.0f; + + transpose_matrix(matrix); +} + +void translation_matrix(const float *vec, float *matrix) +{ + memcpy(matrix, idmat, sizeof idmat); + matrix[12] = vec[0]; + matrix[13] = vec[1]; + matrix[14] = vec[2]; +} + +void mult_matrix(float *dest, const float *m1, const float *m2) +{ + int i, j; + float tmp[16]; + + for(i=0; i<4; i++) { + for(j=0; j<4; j++) { + tmp[M(i, j)] = m1[M(i, 0)] * m2[M(0, j)] + m1[M(i, 1)] * m2[M(1, j)] + + m1[M(i, 2)] * m2[M(2, j)] + m1[M(i, 3)] * m2[M(3, j)]; + } + } + memcpy(dest, tmp, sizeof tmp); +} + +void transpose_matrix(float *matrix) +{ + int i, j; + float tmp[16]; + + for(i=0; i<4; i++) { + for(j=0; j<4; j++) { + tmp[M(i, j)] = matrix[M(j, i)]; + } + } + memcpy(matrix, tmp, sizeof tmp); +} + +void print_matrix(const float *matrix) +{ + int i, j; + + for(i=0; i<4; i++) { + putchar('['); + for(j=0; j<4; j++) { + printf("%6.3f ", matrix[M(i, j)]); + } + printf("]\n"); + } +} diff -r 9b0db7dbde6e -r 7a2041ddb7e7 src/vr/mathutil.h --- a/src/vr/mathutil.h Sun Aug 24 14:36:00 2014 +0300 +++ b/src/vr/mathutil.h Sun Aug 24 18:42:40 2014 +0300 @@ -1,13 +1,13 @@ -#ifndef MATHUTIL_H_ -#define MATHUTIL_H_ - -void rotation_matrix(const float *quat, float *matrix); -void translation_matrix(const float *vec, float *matrix); - -void mult_matrix(float *dest, const float *m1, const float *m2); - -void transpose_matrix(float *matrix); - -void print_matrix(const float *matrix); - -#endif /* MATHUTIL_H_ */ \ No newline at end of file +#ifndef MATHUTIL_H_ +#define MATHUTIL_H_ + +void rotation_matrix(const float *quat, float *matrix); +void translation_matrix(const float *vec, float *matrix); + +void mult_matrix(float *dest, const float *m1, const float *m2); + +void transpose_matrix(float *matrix); + +void print_matrix(const float *matrix); + +#endif /* MATHUTIL_H_ */