void canblend(canvas *dst, canvas *src, float fr, float fg, float fb, float fa) { if(!cansizecheck(dst, src, "canmult: canvases must be the same size\n")) return; unsigned int *dptr = dst->data; unsigned int *sptr = src->data; int npix = dst->sizex*dst->sizey; while(npix--) { float fas = fa*AVAL(*sptr)/255.0; int rd = round(fr*RVAL(*sptr) + (1.0-fas)*RVAL(*dptr)); int gd = round(fg*GVAL(*sptr) + (1.0-fas)*GVAL(*dptr)); int bd = round(fb*BVAL(*sptr) + (1.0-fas)*BVAL(*dptr)); int ad = round(fa*AVAL(*sptr) + (1.0-fas)*AVAL(*dptr)); *dptr++ = CPACK(rd, gd, bd, ad); sptr++; } }
void canmult(canvas *a, canvas *b) { if(!cansizecheck(a, b, "canmult: canvases must be the same size\n")) return; int npix = a->sizex*a->sizey; unsigned int *aptr = a->data; unsigned int *bptr = b->data; while(npix--) { int ir = round(RVAL(*aptr)*RVAL(*bptr)/255.0); int ig = round(GVAL(*aptr)*GVAL(*bptr)/255.0); int ib = round(BVAL(*aptr)*BVAL(*bptr)/255.0); int ia = round(AVAL(*aptr)*AVAL(*bptr)/255.0); *aptr = CPACK(ir,ig,ib,ia); aptr++; bptr++; } }
void menu_et_function_set_from_linear(u8 n, s16 lin_val) { et_functions_s *etf = &et_functions[n]; s16 val; if (n == 0 || n >= ET_FUNCTIONS_SIZE) return; // OFF or bad // map lin_val between min and max val = (s16)((s32)(lin_val + PPM(500)) * (etf->max - etf->min + 1) / PPM(1000)) + etf->min; if (val > etf->max) val = etf->max; // lin_val was full right AVAL(val); }
void canscalergba(canvas *c, float r, float g, float b, float a) { int npix = c->sizex*c->sizey; unsigned int *lptr = c->data; while(npix--) { int ir = round(r*RVAL(*lptr)); int ig = round(g*GVAL(*lptr)); int ib = round(b*BVAL(*lptr)); int ia = round(a*AVAL(*lptr)); *lptr++ = CPACK(ir,ig,ib,ia); } }
// reset value to reset_value static void kf_reset(u8 *id, u8 *param, u8 flags, s16 *prev_val) { u8 *name = param ? param : id; et_functions_s *etf = menu_et_function_find_name(name); s16 val; if (!etf) return; val = etf->reset; AVAL(val); if (flags & FF_SHOW) { BEEP_RESET; menu_et_function_show_id(etf); lcd_char_num3(val); } }
int cantofile(canvas *c, const char *outfilename) { FILE *fptr = fopen(outfilename, "wb"); if(!fptr) { fprintf(stderr, " Error: cantofile: can't open output file\n"); fprintf(stderr, " [%s]\n",outfilename); return 0; } int sizex = c->sizex; int sizey = c->sizey; // from http://paulbourke.net/dataformats/tga/ putc(0,fptr); putc(0,fptr); putc(2,fptr); /* uncompressed RGB */ putc(0,fptr); putc(0,fptr); putc(0,fptr); putc(0,fptr); putc(0,fptr); putc(0,fptr); putc(0,fptr); /* X origin */ putc(0,fptr); putc(0,fptr); /* y origin */ putc((sizex & 0x00FF),fptr); putc((sizex & 0xFF00) / 256,fptr); putc((sizey & 0x00FF),fptr); putc((sizey & 0xFF00) / 256,fptr); putc(32,fptr); /* 32 bit bitmap */ putc(0,fptr); for(int y=0; y<sizey; y++) { unsigned int *lptr = c->data+((sizey-1-y)*sizex); for(int x=0; x<sizex; x++) { putc(BVAL(*lptr),fptr); putc(GVAL(*lptr),fptr); putc(RVAL(*lptr),fptr); putc(AVAL(*lptr),fptr); lptr++; } } fclose(fptr); return 1; }
// set channel value to one endpoint (also to middle with 3-pos CH3) static void kf_set_switch(u8 *id, u8 *param, u8 flags, s16 *prev_val) { u8 *name = param ? param : id; et_functions_s *etf = menu_et_function_find_name(name); s16 val; if (!etf) return; RVAL(val); if (flags & FF_MID) { // middle if (flags & FF_PREVIOUS) val = *prev_val; else val = etf->reset; } else if (flags & FF_ON) { // ON *prev_val = val; // always save previous val val = (s8)(flags & FF_REVERSE ? etf->min : etf->max); } else { // OFF if ((flags & FF_PREVIOUS) && !(flags & FF_HAS_MID)) // use previous only when there is no middle state val = *prev_val; else { // save previous only when there is middle state if (flags & FF_HAS_MID) *prev_val = val; val = (s8)(flags & FF_REVERSE ? etf->max : etf->min); } } AVAL(val); if (flags & FF_SHOW) { menu_et_function_show_id(etf); lcd_char_num3(val); } }
void gleTwistExtrusion (int ncp, /* number of contour points */ gleDouble contour[][2], /* 2D contour */ gleDouble cont_normal[][2], /* 2D contour normals */ gleDouble up[3], /* up vector for contour */ int npoints, /* numpoints in poly-line */ gleDouble point_array[][3], /* polyline */ gleColor color_array[], /* color of polyline */ gleDouble twist_array[]) /* countour twists (in degrees) */ { int j; double angle; double si, co; gleAffine *xforms; /* build 2D affine matrices from radius array */ xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine)); for (j=0; j<npoints; j++) { angle = (M_PI/180.0) * twist_array[j]; si = sin (angle); co = cos (angle); AVAL(xforms,j,0,0) = co; AVAL(xforms,j,0,1) = -si; AVAL(xforms,j,0,2) = 0.0; AVAL(xforms,j,1,0) = si; AVAL(xforms,j,1,1) = co; AVAL(xforms,j,1,2) = 0.0; } gleSuperExtrusion (ncp, /* number of contour points */ contour, /* 2D contour */ cont_normal, /* 2D contour normals */ up, /* up vector for contour */ npoints, /* numpoints in poly-line */ point_array, /* polyline */ color_array, /* color of polyline */ xforms); free (xforms); }
void glePolyCone (int npoints, gleDouble point_array[][3], gleColor color_array[], gleDouble radius_array[]) { gleAffine * xforms; int j; /* build 2D affine matrices from radius array */ xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine)); for (j=0; j<npoints; j++) { AVAL(xforms,j,0,0) = radius_array[j]; AVAL(xforms,j,0,1) = 0.0; AVAL(xforms,j,0,2) = 0.0; AVAL(xforms,j,1,0) = 0.0; AVAL(xforms,j,1,1) = radius_array[j]; AVAL(xforms,j,1,2) = 0.0; } gen_polycone (npoints, point_array, color_array, 1.0, xforms); free (xforms); }
static u8 menu_popup_et(u8 trim_id) { u16 delay_time; s16 val; u8 step; u16 buttons_state_last; u16 btn_l = ETB_L(trim_id); u16 btn_r = ETB_R(trim_id); u16 btn_lr = btn_l | btn_r; config_et_map_s *etm = &ck.et_map[trim_id]; #define SF_ROTATE etm->rotate et_functions_s *etf = &et_functions[etm->function]; u8 *mbs = &menu_buttons_state[NUM_KEYS + 2 * trim_id]; // read value RVAL(val); // remember buttons state buttons_state_last = buttons_state & ~btn_lr; // handle momentary keys // when something changed, show value for 5s while checking buttons // during initialize show nothing if (etm->buttons == ETB_MOMENTARY) { s16 *pv = &menu_buttons_previous_values[NUM_KEYS + 2 * trim_id]; u8 value_showed = 0; u8 state; while (1) { // set actual state of btn_lr to buttons_state_last buttons_state_last &= ~btn_lr; buttons_state_last |= buttons_state & btn_lr; // check buttons if (btns(btn_l)) { // left if (*mbs == MBS_LEFT) break; // already was left state = MBS_LEFT; *pv = val; // save previous value val = etm->reverse ? etf->max : etf->min; } else if (btns(btn_r)) { // right if (*mbs == MBS_RIGHT) break; // already was right state = MBS_RIGHT; *pv = val; // save previous value val = etm->reverse ? etf->min : etf->max; } else { // center if (*mbs == MBS_RELEASED) break; // already was center state = MBS_RELEASED; if (etm->previous_val) { if (*mbs != MBS_INITIALIZE) val = *pv; } else val = etf->reset; } AVAL(val); if (*mbs == MBS_INITIALIZE) { // show nothing when doing initialize *mbs = state; break; } *mbs = state; btnr(btn_lr); key_beep(); // if another button was pressed, leave this screen if (buttons) break; if (buttons_state != buttons_state_last) break; // show function id first time if (!value_showed) { value_showed = 1; menu_et_function_show_id(etf); } // show current value if (etf->show_func) etf->show_func(etf->name, val); else lcd_char_num3(val); lcd_update(); // sleep 5s, and if no button was changed during, end this screen delay_time = POPUP_DELAY * 200; while (delay_time && !(buttons & ~btn_lr) && (buttons_state == buttons_state_last)) delay_time = delay_menu(delay_time); if ((buttons_state & btn_lr) == (buttons_state_last & btn_lr)) break; } btnr(btn_lr); if (value_showed) lcd_menu(0); // set MENU off return value_showed; } // if button is not initialized, do it if (*mbs == MBS_INITIALIZE) { // set value to default only for non-config values (mixes, channels...) if (etf->flags & EF_NOCONFIG) { val = etf->reset; AVAL(val); } *mbs = MBS_RELEASED; } // return when key was not pressed if (!btn(btn_lr)) return 0; // convert steps step = steps_map[etm->step]; // show MENU and CHANNEL menu_et_function_show_id(etf); while (1) { u8 val_set_to_reset = 0; // check value left/right if (btnl_all(btn_lr)) { // both long keys together key_beep(); if (etf->long_func && etm->buttons == ETB_SPECIAL) // special handling etf->long_func(etf->name, &val, btn_l, btn_r); else { // reset to given reset value val = etf->reset; } AVAL(val); if (val == etf->reset) val_set_to_reset = 1; btnr(btn_lr); } else if (btn(btn_lr)) { if (!btns_all(btn_lr)) { // only one key is currently pressed key_beep(); if (etf->long_func && etm->buttons == ETB_SPECIAL && btnl(btn_lr)) // special handling etf->long_func(etf->name, &val, btn_l, btn_r); else if ((etm->buttons == ETB_LONG_RESET || etm->buttons == ETB_LONG_ENDVAL) && btnl(btn_lr)) { // handle long key press if (etm->buttons == ETB_LONG_RESET) { val = etf->reset; } else { // set side value if ((u8)(btn(btn_l) ? 1 : 0) ^ etm->reverse) val = etf->min; else val = etf->max; } } else { // handle short key press if ((u8)(btn(btn_l) ? 1 : 0) ^ etm->reverse) { val -= step; if (val < etf->min) { if (etm->rotate) val = etf->max; else val = etf->min; } if (etm->opposite_reset && val > etf->reset) val = etf->reset; } else { val += step; if (val > etf->max) { if (etm->rotate) val = etf->min; else val = etf->max; } if (etm->opposite_reset && val < etf->reset) val = etf->reset; } } AVAL(val); if (val == etf->reset) val_set_to_reset = 1; btnr(btn_lr); } else btnr_nolong(btn_lr); // keep long-presses for testing-both } else if (btn(BTN_ROT_ALL)) { s16 val2 = val; val = menu_change_val(val, etf->min, etf->max, etf->rot_fast_step, etm->rotate); // if encoder skipped reset value, set it to reset value if (val2 < etf->reset && val > etf->reset || val2 > etf->reset && val < etf->reset) val = etf->reset; AVAL(val); if (val == etf->reset) val_set_to_reset = 1; } btnr(BTN_ROT_ALL); // longer beep at value reset value if (val_set_to_reset) BEEP_RESET; // if another button was pressed, leave this screen if (buttons) break; if ((buttons_state & ~btn_lr) != buttons_state_last) break; // show current value if (etf->show_func) etf->show_func(etf->name, val); else lcd_char_num3(val); lcd_update(); // if reset value was reached, ignore rotate/btn_lr for some time delay_time = POPUP_DELAY * 200; if (val_set_to_reset) { u8 delay = RESET_VALUE_DELAY; while (delay && !(buttons & ~(btn_lr | BTN_ROT_ALL)) && ((buttons_state & ~btn_lr) == buttons_state_last)) delay = (u8)delay_menu(delay); btnr(BTN_ROT_ALL | btn_lr); delay_time -= RESET_VALUE_DELAY; } // sleep 5s, and if no button was changed during, end this screen while (delay_time && !buttons && ((buttons_state & ~btn_lr) == buttons_state_last)) delay_time = delay_menu(delay_time); if (!buttons) break; // timeouted without button press } btnr(btn_lr); // reset also long values // set MENU off lcd_menu(0); // save model config config_model_save(); return 1; }
void En_Bird_f7( struct z64_actor_t * a, u32 z_gp ) { AVAL(a,f32,188) += ( sinf( AVAL(a,f32,436) ) * AVAL(a,f32,416) ); func_80078310(AADDR(a,104), AVAL(a,f32,424), 0.1f, AVAL(a,f32,428), 0.0f); f32 v = func_80078028(AADDR(a,36), AADDR(a, 8)); if (AVAL(a,f32,432) < v || AVAL(a,u32,408) < 4) { func_80077B58(AADDR(a,50), (u16)func_80078068(AADDR(a,36), AADDR(a,8)), AVAL(a,u16,448)); } else { a->rotation_2.y += (u32)( AVAL(a,f32,420) * sinf(AVAL(a,f32,436)) ); } AVAL(a,u16,182) = a->rotation_2.y; func_800A49FC(AADDR(a,332)); if(AVAL(a,u32,408)-- <= 0) { En_Bird_f4(a, a->variable); } }
void En_Bird_f2 ( void * _a0, void * _a1 ) { struct z64_actor_t * a0; u32 * a1; a0 = (struct z64_actor_t*)_a0; a1 = (u32*)_a1; func_800780DC( a0, En_Bird_dat1 ); func_8002D62C( a0, 0.03f ); /* Scale - .01 = original */ /* Animation init */ func_800A457C( a1, AADDR(a0,0x014C), 0x06002190, 0x0600006C, 0, 0, 0 ); func_8002B1E0( AADDR(a0,180), 0x45ABE000, 0x8002B5EC, 0x40800000 ); AVAL(a0,u8,174) = 0; AVAL(a0,u32,404) = 0; AVAL(a0,u32,408) = 0; AVAL(a0,u32,416) = 0; AVAL(a0,u32,420) = 0; AVAL(a0,f32,424) = 1.5f; /* Animation speed */ AVAL(a0,f32,428) = 0.5f; AVAL(a0,f32,432) = 40.0f; AVAL(a0,u16,0x0B6) = 0; AVAL(a0,f32,0x5C) = AVAL(a0,f32,0x24); AVAL(a0,f32,0x60) = AVAL(a0,f32,0x2C); AVAL(a0,f32,0x64) = 0.1953125f; AVAL(a0,f32,0x80) = 200.0f; AVAL(a0,f32,0x84) = 0.0f; AVAL(a0,u32,440) = 0; AVAL(a0,u32,444) = 70.0f; AVAL(a0,u16,448) = 0x09C4; En_Bird_f4( a0, (void*)(int)a0->variable ); }