void acc_update( void ) { volatile avr32_adc_t *adc = &AVR32_ADC; // start + get from adc acc_get_value(adc, &acc.m) ; // ak = acceleration = m - k xyz_diff( acc.m , acc.k, &acc.ak ) ; acc.ak2 = xyz_sumsq( acc.ak ) ; if ( is_acc_slow() ) { // update g for next move acc.g.x = acc.m.x ; acc.g.y = acc.m.y ; acc.g.z = acc.m.z ; } else { xyz_diff( acc.m , acc.g, &acc.ag ) ; xyz_round0( acc.ag , 16, &acc.ag ) ; xyz_add( acc.s , acc.ag, &acc.s ) ; //xyz_round0( acc.s , 256, &acc.s ) ; //print_dbg("m = "); print_xyz( acc.m ) ; //print_dbg("k = "); print_xyz( acc.k ) ; //print_dbg("g = "); print_xyz( acc.g ) ; //print_dbg("ag = "); print_xyz( acc.ag ) ; //print_dbg("s = "); print_xyz( acc.s ) ; //print_dbg("\r\n"); ////acc.s2 = xyz_sumsq( acc.s ) ; //print_dbg("s2 = 0x"); print_dbg_hex(acc.s2); print_dbg("\r\n"); } }
/* ray_position: interpreting direction as velocity, calculate position * of ray r after time t. */ xyz ray_position(ray r, double t) { return xyz_add(r.origin, xyz_scale(t, r.dir)); }
int main() { /* xyz */ printf(" *** testing xyz *** \n"); xyz v = xyz_expr(1,2,3); xyz add = xyz_add(v,v); xyz vv = xyz_expr(5,5,5); xyz sub = xyz_sub(v,vv); xyz n = xyz_neg(sub); xyz sc = xyz_scale(1.5,v); xyz sc2 = xyz_scale(-3.33,n); double dt = xyz_dot(v,sc); double mag = xyz_mag(v); xyz z = xyz_expr(0,0,0); xyz zn = xyz_norm(z); xyz vn = xyz_norm(v); printf("xyz_expr(1,2,3) =>\t%s\n",xyz_tos(v)); printf("(1,2,3)+(1,2,3) =>\t%s\n",xyz_tos(add)); printf("(1,2,3)-(5,5,5) =>\t%s\n",xyz_tos(sub)); printf("-(-4,-3,-2) =>\t%s\n",xyz_tos(n)); printf("scale (1,2,3) by 1.5 =>\t%s\n",xyz_tos(sc)); printf("scale (4,3,2) by -3.33 =>\t%s\n",xyz_tos(sc2)); printf("(1,2,3)*(1.5,3,4.5) =>\t%.2lf\n",dt); printf("magnitude of (1,2,3) =>\t%.2lf\n",mag); printf("norm (0,0,0) =>\t%s\n",xyz_tos(zn)); printf("norm (1,2,3) =>\t%s\n",xyz_tos(vn)); printf(" *****\n"); /* color */ printf(" *** testing color *** \n"); color c = color_expr(1,0.5,0); color cc = color_expr(0.75,0,0.25); color mod = color_modulate(c,cc); color scc = color_scale(1.5, cc); color addc = color_add(c,cc); printf("color_expr(1,0.5,0) =>\t%s\n",color_tos(c)); printf("(1,0.5,0)*(0.75,0,0.25) =>\t%s\n",color_tos(mod)); printf("scale (0.75,0,0.25) by 1.5 =>\t%s\n",color_tos(scc)); printf("(1,0.5,0)+(0.75,0,0.25) =>\t%s\n",color_tos(addc)); printf("(0.75,0,0.25) on [0,255] =>"); color_show_bytes(stdout,cc); printf(" *****\n"); /* ray */ printf(" *** testing ray *** \n"); ray testray = {v,vv}; printf("ray from (1,2,3) to (5,5,5) =>\t%s\n",ray_tos(testray)); printf(" *****\n"); /* sphere */ printf(" *** testing sphere *** \n"); sphere testsph = sphere_expr(v, 3.2, get_sc, c); printf("sphere at (1,2,3) with radius 3.2:\n"); sphere_show(stdout,testsph); printf("\n *****\n"); /* poster */ printf(" *** testing poster *** \n"); poster testpst = poster_expr(v, 4, 5.25, get_sc, c); printf("poster at (1,2,3) with width 4 and height 5.25:\n"); poster_show(stdout,testpst); printf("\n *****\n"); /* object */ printf(" *** testing object *** \n"); object objs = {SPHERE,{.s = testsph},NULL};