gba-x3dtest

diff src/x3d.c @ 7:158d23956801

started adding rendering pipeline stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 18 Jun 2014 06:20:07 +0300
parents
children fb0a0d6a8b52
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/x3d.c	Wed Jun 18 06:20:07 2014 +0300
     1.3 @@ -0,0 +1,84 @@
     1.4 +#include <string.h>
     1.5 +#include "x3d.h"
     1.6 +#include "fixed.h"
     1.7 +#include "sincos.h"
     1.8 +
     1.9 +#define MAT_STACK_SIZE	4
    1.10 +
    1.11 +struct matrix {
    1.12 +	int32_t m[3][4];
    1.13 +};
    1.14 +
    1.15 +static int32_t proj_fov = M_PI_X16;
    1.16 +static int32_t proj_aspect = 65536;
    1.17 +static int32_t proj_near = ftox16(0.5);
    1.18 +static int32_t proj_far = 500 << 16;
    1.19 +
    1.20 +static struct matrix identity = {
    1.21 +	{{65536, 0, 0, 0}, {0, 65536, 0, 0}, {0, 0, 65536, 0}}
    1.22 +};
    1.23 +
    1.24 +static short mtop;
    1.25 +static struct matrix mstack[MAT_STACK_SIZE] = {
    1.26 +	{{{65536, 0, 0, 0}, {0, 65536, 0, 0}, {0, 0, 65536, 0}}},
    1.27 +	{{{65536, 0, 0, 0}, {0, 65536, 0, 0}, {0, 0, 65536, 0}}}
    1.28 +};
    1.29 +
    1.30 +void x3d_projection(int32_t fov, int32_t aspect, int32_t nearz, int32_t farz)
    1.31 +{
    1.32 +	proj_fov = fov;
    1.33 +	proj_aspect = aspect;
    1.34 +	proj_near = nearz;
    1.35 +	proj_far = farz;
    1.36 +}
    1.37 +
    1.38 +int x3d_push_matrix(void)
    1.39 +{
    1.40 +	short newtop = mtop + 1;
    1.41 +	if(newtop >= MAT_STACK_SIZE) {
    1.42 +		return -1;
    1.43 +	}
    1.44 +	memcpy(mstack + newtop, mstack + mtop, sizeof *mstack);
    1.45 +	mtop = newtop;
    1.46 +	return 0;
    1.47 +}
    1.48 +
    1.49 +int x3d_pop_matrix(void)
    1.50 +{
    1.51 +	if(mtop <= 0) {
    1.52 +		return -1;
    1.53 +	}
    1.54 +	--mtop;
    1.55 +	return 0;
    1.56 +}
    1.57 +
    1.58 +void x3d_load_matrix(int32_t *m)
    1.59 +{
    1.60 +	memcpy(mstack[mtop].m[0], m, sizeof *mstack);
    1.61 +}
    1.62 +
    1.63 +
    1.64 +#define M(i,j)	(((i) << 2) + (j))
    1.65 +void x3d_mult_matrix(int32_t *m)
    1.66 +{
    1.67 +	int i, j;
    1.68 +	struct matrix tmp;
    1.69 +
    1.70 +	memcpy(tmp.m[0], mstack[mtop].m[0], sizeof tmp);
    1.71 +
    1.72 +	for(i=0; i<3; i++) {
    1.73 +		for(j=0; j<4; j++) {
    1.74 +			mstack[mtop].m[i][j] = x16mul(tmp.m[0][j], m[M(i, 0)]) +
    1.75 +				x16mul(tmp.m[1][j], m[M(i, 1)]) +
    1.76 +				x16mul(tmp.m[2][j], m[M(i, 2)]) +
    1.77 +				m[M(i, 3)];
    1.78 +		}
    1.79 +	}
    1.80 +}
    1.81 +
    1.82 +void x3d_load_identity(void)
    1.83 +{
    1.84 +	memcpy(mstack[mtop].m[0], identity.m[0], sizeof identity);
    1.85 +}
    1.86 +
    1.87 +/* TODO cont... */