gba-x3dtest

diff src/x3d.c @ 13:2070a81127f2

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Jun 2014 08:28:28 +0300
parents ecc022a21279
children c398d834d64a
line diff
     1.1 --- a/src/x3d.c	Mon Jun 23 06:44:04 2014 +0300
     1.2 +++ b/src/x3d.c	Mon Jun 23 08:28:28 2014 +0300
     1.3 @@ -19,9 +19,10 @@
     1.4  
     1.5  static int32_t proj_fov = M_PI_X16;
     1.6  static int32_t proj_aspect = 65536;
     1.7 +static int32_t inv_proj_aspect = 65536;
     1.8  static int32_t proj_near = ftox16(0.5);
     1.9  static int32_t proj_far = 500 << 16;
    1.10 -static int32_t tan_half_xfov, tan_half_yfov;
    1.11 +static int32_t inv_tan_half_xfov, inv_tan_half_yfov;
    1.12  
    1.13  #define ID_INIT {65536, 0, 0, 0, 0, 65536, 0, 0, 0, 0, 65536, 0}
    1.14  
    1.15 @@ -42,11 +43,12 @@
    1.16  {
    1.17  	proj_fov = (M_PI_X16 * fov) / 180;
    1.18  	proj_aspect = aspect;
    1.19 +	inv_proj_aspect = x16div(65536, proj_aspect);
    1.20  	proj_near = nearz;
    1.21  	proj_far = farz;
    1.22  
    1.23 -	tan_half_yfov = (int32_t)(tan(0.5 * proj_fov / 65536.0) * 65536.0);
    1.24 -	tan_half_xfov = x16mul(tan_half_yfov, aspect);
    1.25 +	inv_tan_half_yfov = (int32_t)(65536.0 / tan(0.5 * proj_fov / 65536.0));
    1.26 +	inv_tan_half_xfov = x16mul(inv_tan_half_yfov, aspect);
    1.27  }
    1.28  
    1.29  int x3d_push_matrix(void)
    1.30 @@ -214,11 +216,11 @@
    1.31  		for(j=0; j<pverts; j++) {
    1.32  			int32_t x, y;
    1.33  
    1.34 -			x = x16mul(vpos[j].x, tan_half_xfov);
    1.35 +			x = x16mul(vpos[j].x, inv_tan_half_xfov);
    1.36  			x = x16div(x, vpos[j].z);
    1.37 -			vpos[j].x = (x + 65536) * (WIDTH / 2);
    1.38 +			vpos[j].x = (x16mul(x, inv_proj_aspect) + 65536) * (WIDTH / 2);
    1.39  
    1.40 -			y = x16mul(vpos[j].y, tan_half_yfov);
    1.41 +			y = x16mul(vpos[j].y, inv_tan_half_yfov);
    1.42  			y = x16div(y, vpos[j].z);
    1.43  			vpos[j].y = (65536 - y) * (HEIGHT / 2);
    1.44  		}