fdf/src/mat4_init_funcs.c
2017-03-14 00:09:03 +02:00

98 lines
No EOL
1.8 KiB
C

#include "fdf.h"
t_mat4 *mat4_init(void)
{
t_mat4 *mat;
if ((mat = (t_mat4 *)malloc(sizeof(t_mat4))))
{
mat->mx[0][0] = 1;
mat->mx[0][1] = 0;
mat->mx[0][2] = 0;
mat->mx[0][3] = 0;
mat->mx[1][0] = 0;
mat->mx[1][1] = 1;
mat->mx[1][2] = 0;
mat->mx[1][3] = 0;
mat->mx[2][0] = 0;
mat->mx[2][1] = 0;
mat->mx[2][2] = 1;
mat->mx[2][3] = 0;
mat->mx[3][0] = 0;
mat->mx[3][1] = 0;
mat->mx[3][2] = 0;
mat->mx[3][3] = 1;
}
return (mat);
}
t_trnsf *trnsf_mat_init()
{
t_trnsf *trnsf;
if ((trnsf = malloc(sizeof(t_trnsf))))
{
trnsf->tr = mat4_init();
trnsf->sc = mat4_init();
trnsf->vp = mat4_init();
trnsf->pr = mat4_init();
trnsf->xr = mat4_init();
trnsf->yr = mat4_init();
trnsf->zr = mat4_init();
trnsf->vp_pr_tr = mat4_init();
trnsf->fin = mat4_init();
}
return (trnsf);
}
t_mat4 *viewport_mat_init(int x, int y)
{
t_mat4 *m;
if ((m = malloc(sizeof(t_mat4))))
{
m->mx[0][0] = (double)x / 2.0f;
m->mx[0][1] = 0;
m->mx[0][2] = 0;
m->mx[0][3] = 0;
m->mx[1][0] = 0;
m->mx[1][1] = (double)y / 2.0f;
m->mx[1][2] = 0;
m->mx[1][3] = 0;
m->mx[2][0] = 0;
m->mx[2][1] = 0;
m->mx[2][2] = 1;
m->mx[2][3] = 0;
m->mx[3][0] = ((double)x - 1) / 2.0f;
m->mx[3][1] = ((double)y - 1) / 2.0f;
m->mx[3][2] = 0;
m->mx[3][3] = 1;
}
return (m);
}
t_mat4 *orth_mat_init(float r, float t, float f)
{
t_mat4 *orth;
if ((orth = malloc(sizeof(t_mat4))))
{
orth->mx[0][0] = 2.0f / r;
orth->mx[0][1] = 0;
orth->mx[0][2] = 0;
orth->mx[0][3] = 0;
orth->mx[1][0] = 0;
orth->mx[1][1] = 2.0f / t;
orth->mx[1][2] = 0;
orth->mx[1][3] = 0;
orth->mx[2][0] = 0;
orth->mx[2][1] = 0;
orth->mx[2][2] = 2.0f / f;
orth->mx[2][3] = 0;
orth->mx[3][0] = -1;
orth->mx[3][1] = -1;
orth->mx[3][2] = 1;
orth->mx[3][3] = 1;
}
return (orth);
}