void playFile(int argc, char *argv[]) { unsigned long i=0; double alea; FILE *fic = fopen(argv[1], "r"); if (fic != NULL) { printf("INFO: file open\n"); while (!feof(fic)) { fscanf(fic, "%lf\n", &alea); randList[i] = alea; i++; } fclose(fic); printf("INFO: file close\n"); maxAll = calculateMaxTab(); minAll = calculateMinTab(); populatePoints(); populateHilbert(); populateFFT(); glmain(argc, argv); } else { printf("### ERROR open file error\n"); exit(EXIT_FAILURE); } }
void CCCatmullRomSprite::updateAtlas() { // populate points populatePoints(m_controlPoints, m_points); // clear m_atlas->removeAllQuads(); m_segmentQuadIndices.clear(); // basic check, at least we need two points int pc = m_points.getCount(); if(pc < 2) return; // append a point to avoid losting last segment CCPoint pLast0 = m_points.getPointAt(pc - 1); CCPoint pLast1 = m_points.getPointAt(pc - 2); CCPoint pAppend = ccpAdd(pLast0, ccpSub(pLast0, pLast1)); m_points.addPoint(pAppend); pc++; // first two points CCPoint p0 = m_points.getPointAt(0); CCPoint p1 = m_points.getPointAt(1); // half width of pattern float halfWidth = m_patternWidth / 2; // bl and br of first quad CCPoint bl, tl; { CCPoint v01 = ccpSub(p1, p0); float r01 = ccpToAngle(v01); bl.x = p0.x + halfWidth * sinf(r01); bl.y = p0.y - halfWidth * cosf(r01); tl.x = p0.x - halfWidth * sinf(r01); tl.y = p0.y + halfWidth * cosf(r01); } // current length float texStartP = 0; float texEndP; float headPos = 0; // populate quads int segIndex = 0; for(int i = 2; i < pc; i++) { // save quad index if(m_segmentPointIndices[segIndex] == i - 2) { m_segmentQuadIndices.push_back(m_atlas->getTotalQuads()); segIndex++; } // third point CCPoint p2 = m_points.getPointAt(i); // 3 vectors, from 0 to 1, from 1 to 2, from 1 to 0 CCPoint v01 = ccpSub(p1, p0); CCPoint v12 = ccpSub(p2, p1); CCPoint v10 = ccpSub(p0, p1); // angle in center of v01 and v12, then rotate 90 degrees float r = (ccpToAngle(v01) + ccpToAngle(v12)) / 2 - M_PI_2; // the vector of center divider CCPoint m = ccp(cosf(r), sinf(r)); // angle between center and v10 float rm01 = ccpToAngle(m) - ccpToAngle(v10); // the actual base width of joint // but we must prevent the base width to be too large float s = sinf(rm01); float w = MAX_FLOAT; if(s != 0) w = fabsf(halfWidth / s); w = MIN(halfWidth * 2, w); // a corner situation when v01 is in third quadrant and v12 is in fourth quadrant if(v01.x < 0 && SIGN(v01.x) == SIGN(v12.x) && SIGN(v01.y) != SIGN(v12.y)) { r = M_PI + r; } // populate tl and tr CCPoint br, tr; br.x = p1.x + w * cosf(r); br.y = p1.y + w * sinf(r); tr.x = p1.x - w * cosf(r); tr.y = p1.y - w * sinf(r); // calculate texcoords pencentage float segLen = ccpLength(v01); float remainLen = segLen; float initVerP = 0; float stepVerP = m_patternLength / segLen; while(remainLen > m_patternLength) { texEndP = texStartP; float p = (1 - texStartP) / (1 - texStartP + texEndP); populateQuad(bl, br, tl, tr, texStartP, 1, initVerP, initVerP + stepVerP * p); populateQuad(bl, br, tl, tr, 0, texEndP, initVerP + stepVerP * p, initVerP + stepVerP); initVerP += stepVerP; // cut pattern length remainLen -= m_patternLength; } // remaining length headPos += segLen; headPos = fmodf(headPos, m_patternLength); texEndP = headPos / m_patternLength; stepVerP = remainLen / segLen; if(texEndP <= texStartP) { float p = (1 - texStartP) / (1 - texStartP + texEndP); populateQuad(bl, br, tl, tr, texStartP, 1, initVerP, initVerP + stepVerP * p); populateQuad(bl, br, tl, tr, 0, texEndP, initVerP + stepVerP * p, initVerP + stepVerP); } else { populateQuad(bl, br, tl, tr, texStartP, texEndP, initVerP, 1); } // move forward p0 = p1; p1 = p2; bl = br; tl = tr; texStartP = texEndP; } }
int main(int argc, char* argv[]) { atexit(onExit); /****************************************/ /* Initialize GLUT and create window */ /****************************************/ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowPosition(50, 50); glutInitWindowSize(500, 500); main_window = glutCreateWindow("COMP 175 In Class Assignment 5"); glutDisplayFunc(myGlutDisplay); glutReshapeFunc(myGlutReshape); /****************************************/ /* Set up OpenGL lighting */ /****************************************/ glShadeModel(GL_SMOOTH); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); static float one[] = { 1, 1, 1, 1 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, one); /****************************************/ /* Enable z-buferring */ /****************************************/ glEnable(GL_DEPTH_TEST); glPolygonOffset(1, 1); /****************************************/ /* Here's the GLUI code */ /****************************************/ GLUI *glui = GLUI_Master.create_glui("GLUI"); /*** Create the bottom subwindow ***/ glui2 = GLUI_Master.create_glui_subwindow( main_window, GLUI_SUBWINDOW_BOTTOM ); // Create a rotation widget GLUI_Rotation *view_rot = new GLUI_Rotation(glui2, "Objects", view_rotate ); view_rot->set_spin( 1.0 ); // Navigate our scene new GLUI_Column( glui2, false ); GLUI_Translation *trans_x = new GLUI_Translation(glui2, "Objects X", GLUI_TRANSLATION_X, obj_pos ); trans_x->set_speed( .1 ); new GLUI_Column( glui2, false ); GLUI_Translation *trans_y = new GLUI_Translation( glui2, "Objects Y", GLUI_TRANSLATION_Y, &obj_pos[1] ); trans_y->set_speed( .1 ); new GLUI_Column( glui2, false ); GLUI_Translation *trans_z = new GLUI_Translation( glui2, "Objects Z", GLUI_TRANSLATION_Z, &obj_pos[2] ); trans_z->set_speed( .1 ); new GLUI_Checkbox(glui2, "Follow Coaster", &followCoaster); glui2->add_column(true); GLUI_Panel *render_panel = glui2->add_panel("Render"); new GLUI_Checkbox(render_panel, "Render Spline", &renderSpline); new GLUI_Checkbox(render_panel, "Render ControlPoints", &renderControlPoints); new GLUI_Checkbox(render_panel, "Render Roller Coaster", &renderRollerCoaster); new GLUI_Checkbox(render_panel, "Grid", &grid); resolution_spinner = new GLUI_Spinner( render_panel, "Resolution:", &resolution, RESOLUTION_ID, pointer_cb ); resolution_spinner->set_int_limits( 50, 500 ); new GLUI_Button(render_panel, "CalculateSpline", SPLINE_ID, pointer_cb); glui2->add_button("Quit", 0, (GLUI_Update_CB)exit); glui->set_main_gfx_window(main_window); /* We register the idle callback with GLUI, *not* with GLUT */ GLUI_Master.set_glutIdleFunc(myGlutIdle); // Setup the points for our spline populatePoints(); glutMainLoop(); return EXIT_SUCCESS; }