Source

puma / matrix.h

/** \file
 * 4x4 matrix math
 */

#pragma once

typedef struct
{
	double v[4][4];
} m44_t;


static inline void
m44_mult(
	m44_t * c,
	const m44_t * a,
	const m44_t * b
)
{
	int i, j, k;

	for (i = 0 ; i < 4 ; i++)
	{
		for (j = 0 ; j < 4 ; j++)
		{
			double s = 0;
			for (k = 0 ; k < 4 ; k++)
				s += a->v[k][j] * b->v[i][k];
			c->v[i][j] = s;
		}
	}
}


static inline void
m44_mult4v(
	double * const c,
	const m44_t * const a,
	const double * const b
)
{
	int i, j;

	for (i = 0 ; i < 4 ; i++)
	{
		double v = 0;

		for (j = 0 ; j < 4 ; j++)
			v += a->v[i][j] * b[j];

		c[i] = v;
	}
}


static inline m44_t
m44_eye(void)
{
	return (m44_t) { .v = {
		{ 1, 0, 0, 0},
		{ 0, 1, 0, 0},
		{ 0, 0, 1, 0},
		{ 0, 0, 0, 1},
	}};
}


static inline m44_t
m44_zero(void)
{
	return (m44_t) { .v = {
		{ 0, 0, 0, 0},
		{ 0, 0, 0, 0},
		{ 0, 0, 0, 0},
		{ 0, 0, 0, 0},
	}};
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.