Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 773136b3ea
Fetching contributors…

Cannot retrieve contributors at this time

103 lines (87 sloc) 2.001 kb
#include <stdlib.h>
#include <math.h>
#include "gl-matrix.h"
mat3_t mat3_create(mat3_t mat) {
mat3_t dest = calloc(sizeof(double), 9);
if (mat) {
dest[0] = mat[0];
dest[1] = mat[1];
dest[2] = mat[2];
dest[3] = mat[3];
dest[4] = mat[4];
dest[5] = mat[5];
dest[6] = mat[6];
dest[7] = mat[7];
dest[8] = mat[8];
}
return dest;
}
mat3_t mat3_set(mat3_t mat, mat3_t dest) {
dest[0] = mat[0];
dest[1] = mat[1];
dest[2] = mat[2];
dest[3] = mat[3];
dest[4] = mat[4];
dest[5] = mat[5];
dest[6] = mat[6];
dest[7] = mat[7];
dest[8] = mat[8];
return dest;
}
mat3_t mat3_identity(mat3_t dest) {
if (!dest) { dest = mat3_create(NULL); }
dest[0] = 1;
dest[1] = 0;
dest[2] = 0;
dest[3] = 0;
dest[4] = 1;
dest[5] = 0;
dest[6] = 0;
dest[7] = 0;
dest[8] = 1;
return dest;
}
mat3_t mat3_transpose(mat3_t mat, mat3_t dest) {
// If we are transposing ourselves we can skip a few steps but have to cache some values
if (!dest || mat == dest) {
double a01 = mat[1], a02 = mat[2],
a12 = mat[5];
mat[1] = mat[3];
mat[2] = mat[6];
mat[3] = a01;
mat[5] = mat[7];
mat[6] = a02;
mat[7] = a12;
return mat;
}
dest[0] = mat[0];
dest[1] = mat[3];
dest[2] = mat[6];
dest[3] = mat[1];
dest[4] = mat[4];
dest[5] = mat[7];
dest[6] = mat[2];
dest[7] = mat[5];
dest[8] = mat[8];
return dest;
}
mat4_t mat3_toMat4(mat3_t mat, mat4_t dest) {
if (!dest) { dest = mat4_create(NULL); }
dest[15] = 1;
dest[14] = 0;
dest[13] = 0;
dest[12] = 0;
dest[11] = 0;
dest[10] = mat[8];
dest[9] = mat[7];
dest[8] = mat[6];
dest[7] = 0;
dest[6] = mat[5];
dest[5] = mat[4];
dest[4] = mat[3];
dest[3] = 0;
dest[2] = mat[2];
dest[1] = mat[1];
dest[0] = mat[0];
return dest;
}
Jump to Line
Something went wrong with that request. Please try again.