int main(int argc, char **argv) { glutInit(&argc, argv); if (--argc != 1) { printf("Usage: %s file.scn\n", argv[0]); exit(-1); } glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(framebuffer_width, framebuffer_height); glutInitWindowPosition(20, 100); glutCreateWindow("Ray tracing"); glutDisplayFunc(&draw_scene); glutIdleFunc(&draw_scene); glutReshapeFunc(&resize); //glutSpecialFunc(&specialKeyPressed); glutKeyboardFunc(&key_pressed); glutMouseFunc(&mouse_func); glutMotionFunc(&motion_func); read_scene(argv[1]); init_opengl(); init_noise(); glutMainLoop(); return 1; }
int main(int ac, char **av) { t_env e; t_obj obj; if (init_env(&e, &obj) == -1) return (-1); if (ac != 2) return (-1); if (read_scene(&e, &obj, av[1]) == -1) return (-1); raylaunch(&e, &obj); hook_event(&e); return (0); }
/***************************************************************************** Função que configura as cenas contidas no cartão sd *****************************************************************************/ void cmd_scene(char *par) { char i,addr,erro = __FALSE, str[30]; if(par[0] == '?') /*Solicitando a alguma cena?*/ { if(par[1] >= '0' && par[1] <= '3') /*Cenas de 0 a 3?*/ { if(read_scene(par[1]-48,FILE_DIMMER_SCENE)) sprintf(buf_tx,"%s%u",aux_scene,par[1]-48); else sprintf(buf_tx,"ERROR %u",ERROR_SD); }else { sprintf(buf_tx,"%s%u", (current_scene[0]==0) ? "SET 0000000000007" : current_scene, current_id_scene); if(strcmp(current_scene,scene[current_id_scene])/*strlen(current_scene) < 15*/) sprintf(current_scene,"%s%u",scene[current_id_scene], current_id_scene); } return; } memset(str,0,sizeof(str)); strncpy(str,par,17); /*Cena ex: 0SET 020020020000*/ addr = str[0]-48; for(i=0;i<20;i++) /*Loop para eliminar o id da cena da string...Ex: SET 020020020000*/ str[i] = str[i+1]; for(i=4;i<16;i++) /*Loop para verificar possiveis erros de parâmetro*/ { if(str[i] < '0' || str[i] > '9' || addr > 7) erro = __TRUE; if(str[i] == '\r' || str[i] == '\n') /*Elimina caracteres indesejados da cena*/ str[i] = 0; } //printf("str:%s\r",str); //fflush(stdout); if(strlen(str) != 16 || !strstr(str,"SET") || erro) /*Há erro?*/ sprintf(buf_tx,"ERROR %u",ERROR_PARAMETER); else { if(save_scene(str,addr)) /*A cena foi salva no cartão sd?*/ { init_scene(addr); /*Lê a cena para se certificar que foi escrita no sd*/ sprintf(buf_tx,"%s%u",scene[addr],addr); if(rcv_cmd == RCV_CMD_UART_0) { /*Envia imediatamente para o LPC1113 a alteração da cena 'addr' */ uart_putString(UART_LINK_LPC,scene[addr]); uart_putString(UART_LINK_LPC,"!\0"); strcpy(current_scene,scene[addr]); /*Copia para a cena atual*/ current_id_scene = addr; }else { printf("Cena %u configurada: %s\r",addr,str); fflush(stdout); } }else sprintf(buf_tx,"ERROR %u",ERROR_SD); /*Error permitido para cartão SD*/ } }
struct SceneIO * request_composer_scene(void) { char *filename; time_t time_1, time_2; unsigned long nitems, left; int format, *ready, ready2; Atom type; if (TheDisplay == NULL) { TheDisplay = XOpenDisplay(NULL); GET_COMPOSER_DATA = XInternAtom(TheDisplay, "Get Composer Data", FALSE); NAME_OF_COMPOSER_FILE = XInternAtom(TheDisplay, "Name of Composer File", FALSE); COMPOSER_DATA_READY = XInternAtom(TheDisplay, "Composer Data Ready", FALSE); } /* Reset the shared flag that indicates progress */ ready2 = COMPOSER_EXPORT_REQUESTED; ready = &ready2; XChangeProperty(TheDisplay, DefaultRootWindow(TheDisplay), COMPOSER_DATA_READY, XA_INTEGER, 32, PropModeReplace, (unsigned const char *)ready, 1); /* Ask for the data to be sent */ ready2 = TRUE; XChangeProperty(TheDisplay, DefaultRootWindow(TheDisplay), GET_COMPOSER_DATA, XA_INTEGER, 32, PropModeReplace, (unsigned const char *)ready, 1); time(&time_1); while (*ready != COMPOSER_EXPORT_DONE) { if (XGetWindowProperty(TheDisplay, DefaultRootWindow(TheDisplay), COMPOSER_DATA_READY, 0, sizeof(int), FALSE, XA_INTEGER, &type, &format, &nitems, &left, (unsigned char **)(&ready)) != Success) { return NULL; } /* Use two timeouts: a short timeout until we get a response * (so we know that composer is running), and a longer timeout to save * the scene (don''t want an infinite timeout in case composer crashed). */ time(&time_2); /* printf( "time = %d, ready = %d\n", time_2 - time_1, *ready ); */ if (((long)time_2 - (long)time_1) > (*ready == COMPOSER_EXPORT_SENDING ? TIME_OUT_DONE : TIME_OUT_SEND )) { printf ("\nUnable to find 'composer'. Reading from file: ./%s\n", COMPOSER_DEFAULT_EXPORT_NAME); return read_scene(COMPOSER_DEFAULT_EXPORT_NAME); } } /* Get the filename that the scene was saved in */ XGetWindowProperty(TheDisplay, DefaultRootWindow(TheDisplay), NAME_OF_COMPOSER_FILE, 0, PATH_MAX, FALSE, XA_STRING, &type, &format, &nitems, &left, (unsigned char **)(&filename)); return read_scene(filename); }