Beispiel #1
0
void proj_tests(void){
	mat4_t m = mat4_look_at(vec4_new(0, 0, 5, 0),
		vec4_new(0, 0, 0, 0), vec4_new(0, 1, 0, 0));
	printf("Look at matrix:\n");
	mat4_print(m);

	m = mat4_ortho(-1, 1, -1, 1, 1, 100);
	printf("ortho matrix:\n");
	mat4_print(m);

	m = mat4_perspective(90, 1, 1, 100);
	printf("perspective:\n");
	mat4_print(m);
}
Beispiel #2
0
Datei: view.c Projekt: ifbe/tool
void fixview(mat4 viewmatrix)
{
	//a X b = [ay*bz - az*by, az*bx-ax*bz, ax*by-ay*bx]
	float norm;
	float cx = 1.0;
	float cy = 2.0;
	float cz = 3.0;

	//uvn.n = front
	float nx = 0.0-cx;
	float ny = 10.0-cy;
	float nz = 0.0-cz;
	norm = sqrt(nx*nx + ny*ny + nz*nz);
	nx /= norm;
	ny /= norm;
	nz /= norm;

	//uvn.u = right = cross(front,(0,0,1))
	float ux = ny*1 - nz*0;
	float uy = nz*0 - nx*1;
	float uz = nx*0 - ny*0;
	norm = sqrt(ux*ux + uy*uy + uz*uz);
	ux /= norm;
	uy /= norm;
	uz /= norm;

	//uvn.v = above = cross(right, front)
	float vx = uy*nz - uz*ny;
	float vy = uz*nx - ux*nz;
	float vz = ux*ny - uy*nx;
	norm = sqrt(vx*vx + vy*vy + vz*vz);
	vx /= norm;
	vy /= norm;
	vz /= norm;

	viewmatrix[0][0] = ux;
	viewmatrix[0][1] = uy;
	viewmatrix[0][2] = uz;
	viewmatrix[0][3] = -cx*ux - cy*uy - cz*uz;

	viewmatrix[1][0] = vx;
	viewmatrix[1][1] = vy;
	viewmatrix[1][2] = vz;
	viewmatrix[1][3] = -cx*vx - cy*vy - cz*vz;

	viewmatrix[2][0] = -nx;
	viewmatrix[2][1] = -ny;
	viewmatrix[2][2] = -nz;
	viewmatrix[2][3] = cx*nx + cy*ny + cz*nz;

	viewmatrix[3][0] = 0.0f;
	viewmatrix[3][1] = 0.0f;
	viewmatrix[3][2] = 0.0f;
	viewmatrix[3][3] = 1.0f;
	mat4_print(viewmatrix);
}
Beispiel #3
0
void basic_test(void){
	float ALIGN_16 a_rows[16] = {
		1, 5, 0, 0,
		2, 1, 3, 5,
		6, 9, 0, 2,
		5, 3, 8, 9
	};
	float ALIGN_16 b_rows[16] = {
		4, 0, 2, 0,
		1, 2, 7, 1,
		0, 0, 2, 0,
		1, 2, 0, 1
	};
	mat4_t a = mat4_from_rows(a_rows);
	mat4_t b = mat4_from_rows(b_rows);
	printf("Multiplying a:\n");
	mat4_print(a);
	printf("With b:\n");
	mat4_print(b);

	printf("Multiplication result:\n");
	a = mat4_mult(a, b);
	mat4_print(a);

	vec4_t v = vec4_new(1, 2, 3, 1);
	a = mat4_translate(v);
	printf("translation matrix for [1, 2, 3]:\n");
	mat4_print(a);
	printf("Translated vector:\n");
	v = mat4_vec_mult(a, v);
	vec4_print(v);

	a = mat4_rotate(90, vec4_new(1, 0, 0, 0));
	printf("Rotation matrix:\n");
	mat4_print(a);
	v = mat4_vec_mult(a, vec4_new(0, 1, 0, 0));
	printf("+Y vec rotated 90 deg about +X:\n");
	vec4_print(v);
}