module gedo.math.matrix;



public import gedo.math.vector;
private import gedo.video.ggl;



typedef float[16] Matrix;
// 00 04 08 12
// 01 05 09 13
// 02 06 10 14
// 03 07 11 15



public void multiply(Matrix m)
{
	GGL_multiplyMatrix(cast(GGL_Matrix*)m.ptr);
}



public void multiply(Matrix m, Matrix a, Matrix b)
{
	foreach(i, inout c; m)
	{
		auto x = i & ~3;
		auto y = i & 3;

		c = a[y]*b[x] + a[y+4]*b[x+1] + a[y+8]*b[x+2] + a[y+12]*b[x+3];
	}
}



public void transform(Matrix m, Vector vi, Vector vo)
{
	vo[0] = m[0] * vi[0] + m[4] * vi[1] + m[8]  * vi[2] + m[12];
	vo[1] = m[1] * vi[0] + m[5] * vi[1] + m[9]  * vi[2] + m[13];
	vo[2] = m[2] * vi[0] + m[6] * vi[1] + m[10] * vi[2] + m[14];
}



public void transform(Matrix m, Vector v)
{
	Vector i = v[];

	transform(m, i, v);
}

