rayzor

diff src/min3d.c @ 17:79609d482762

the renderer renders, also fixed an unnoticed matrix conversion problem between scenegraph and min3d
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 14 Apr 2014 07:34:45 +0300
parents 70e332156d02
children 859ccadca671
line diff
     1.1 --- a/src/min3d.c	Sun Apr 13 09:54:51 2014 +0300
     1.2 +++ b/src/min3d.c	Mon Apr 14 07:34:45 2014 +0300
     1.3 @@ -126,6 +126,19 @@
     1.4  	memcpy(m3dctx->mstack[m3dctx->mmode].m[top], m, 16 * sizeof *m);
     1.5  }
     1.6  
     1.7 +void m3d_load_transpose_matrix(const float *m)
     1.8 +{
     1.9 +	int i, j, lin = 0;
    1.10 +	int top = m3dctx->mstack[m3dctx->mmode].top;
    1.11 +	float *dest = m3dctx->mstack[m3dctx->mmode].m[top];
    1.12 +
    1.13 +	for(i=0; i<4; i++) {
    1.14 +		for(j=0; j<4; j++) {
    1.15 +			*dest++ = m[j * 4 + i];
    1.16 +		}
    1.17 +	}
    1.18 +}
    1.19 +
    1.20  #define M(i,j)	(((i) << 2) + (j))
    1.21  void m3d_mult_matrix(const float *m2)
    1.22  {
    1.23 @@ -137,7 +150,7 @@
    1.24  
    1.25  	for(i=0; i<4; i++) {
    1.26  		for(j=0; j<4; j++) {
    1.27 -			dest[M(i,j)] = m1[M(0,j)] * m2[M(i,0)] +
    1.28 +			*dest++ = m1[M(0,j)] * m2[M(i,0)] +
    1.29  				m1[M(1,j)] * m2[M(i,1)] +
    1.30  				m1[M(2,j)] * m2[M(i,2)] +
    1.31  				m1[M(3,j)] * m2[M(i,3)];
    1.32 @@ -145,6 +158,24 @@
    1.33  	}
    1.34  }
    1.35  
    1.36 +void m3d_mult_transpose_matrix(const float *m2)
    1.37 +{
    1.38 +	int i, j, top = m3dctx->mstack[m3dctx->mmode].top;
    1.39 +	float m1[16];
    1.40 +	float *dest = m3dctx->mstack[m3dctx->mmode].m[top];
    1.41 +
    1.42 +	memcpy(m1, dest, sizeof m1);
    1.43 +
    1.44 +	for(i=0; i<4; i++) {
    1.45 +		for(j=0; j<4; j++) {
    1.46 +			*dest++ = m1[M(0,j)] * m2[M(0,i)] +
    1.47 +				m1[M(1,j)] * m2[M(1,i)] +
    1.48 +				m1[M(2,j)] * m2[M(2,i)] +
    1.49 +				m1[M(3,j)] * m2[M(3,i)];
    1.50 +		}
    1.51 +	}
    1.52 +}
    1.53 +
    1.54  void m3d_translate(float x, float y, float z)
    1.55  {
    1.56  	float m[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};