void myIdle(void) { ++day; if (day >= 360) day = 0; myDisplay(); }
void myIdle(void) { ++angle; if( angle >= 360.0f ) angle = 0.0f; myDisplay(); }
void myMouse(int button, int state, int x, int y){ int dtX, dtY; if (button == GLUT_LEFT_BUTTON) { if (state == GLUT_DOWN) { previousX = x; previousY = screenHeight - y; } else if (state == GLUT_UP) { currentX = x; currentY = screenHeight - y; dtX = currentX - previousX; dtY = currentY - previousY; yawDegree = yawDegree - (dtX * pi) / (displacement * 180.0); pitchDegree = pitchDegree + (dtY * pi) / (displacement * 180.0); sinYaw = sin(yawDegree); cosYaw = cos(yawDegree); sinPitch = sin(pitchDegree); cosPitch = cos(pitchDegree); coiX = cameraX + cosPitch * cosYaw; coiY = cameraY + sinPitch; coiZ = cameraZ + cosPitch * sinYaw; if (!mouse_yaw_picth) mouse_yaw_picth = true; myDisplay(); } } }
void timerProc(int id) { current_pos++; if(current_pos >= POINTS_NUM) { current_pos = 0; } myDisplay(); }
void myMenu( int value ) { printf("\nSelected menu value = %d", value); /*if (value ==1) { // // SHOW_POLYGON = true; // FILL_POLYGON = false; currChoice = POINTS; myDisplay(); }*/ if (value ==2 ) { // SHOW_POLYGON = false; // FILL_POLYGON = false; currChoice = LINES; myDisplay(); } if (value==3) { // SHOW_POLYGON = true; // FILL_POLYGON = true; currChoice = FILL; myDisplay(); } /*if (value == 4) { currChoice = LABEL; myDisplay(); }*/ if (value == 0) { // exit exit(1); } }
void performanceTest(void) { int start, end; int i; int curr_width, curr_height; /* Give a warning if the window has been resized */ curr_width = glutGet(GLUT_WINDOW_WIDTH); curr_height = glutGet(GLUT_WINDOW_HEIGHT); if ((curr_width != win_width) || (curr_height != win_height)) { printf("*** Warning ***\n"); printf("The window has been resized and results may be inaccurate.\n"); printf("First press 'z' to restore the default window size.\n"); printf("*** Warning ***\n"); } resetCamera(); printf("Initiating Performance Test\n"); start = glutGet(GLUT_ELAPSED_TIME); /* For every rotation, the display loop will be recalled */ for (i = 0; i < 360; i++) { rotateCamera(1.0, X_AXIS); myDisplay(); /* refresh the screen */ } for (i = 0; i < 360; i++) { rotateCamera(1.0, Y_AXIS); myDisplay(); /* refresh the screen */ } for (i = 0; i < 360; i++) { rotateCamera(1.0, Z_AXIS); myDisplay(); /* refresh the screen */ } end = glutGet(GLUT_ELAPSED_TIME); /* Return the number of milliseconds elapsed */ printf("Performance Test completed in %.2f sec\n", (end - start) / 1000.0f); }
int main() { myGreet(); double myTotal = 0.0; double hourlyPay = getHourlyPay(); int hoursWkd = getHoursWkd(); getTotal(hoursWkd, hourlyPay, myTotal); myDisplay(myTotal); return 0; }
void myIdle(void){ if(r < 0.1f){ isBiging = true; } if(r > 1.0f){ isBiging = false; } if(isBiging){ r = r+0.01f; }else{ r = r - 0.01f; } myDisplay(); }
static GC chgCache(XtermWidget xw, CgsEnum cgsId GCC_UNUSED, CgsCache * me, Bool both) { XGCValues xgcv; XtGCMask mask = (GCForeground | GCBackground | GCFont); memset(&xgcv, 0, sizeof(xgcv)); TRACE2(("chgCache(%s) old data fg=%s, bg=%s, font=%s cset %s\n", traceCgsEnum(cgsId), tracePixel(xw, THIS(fg)), tracePixel(xw, THIS(bg)), traceFont(THIS(font)), traceCSet(THIS(cset)))); #if OPT_TRACE > 1 if (!SameFont(THIS(font), NEXT(font))) TRACE2(("...chgCache new font=%s\n", traceFont(NEXT(font)))); if (!SameCSet(THIS(cset), NEXT(cset))) TRACE2(("...chgCache new cset=%s\n", traceCSet(NEXT(cset)))); if (!SameColor(THIS(fg), NEXT(fg))) TRACE2(("...chgCache new fg=%s\n", tracePixel(xw, NEXT(fg)))); if (!SameColor(THIS(bg), NEXT(bg))) TRACE2(("...chgCache new bg=%s\n", tracePixel(xw, NEXT(bg)))); #endif if (both) { THIS(font) = NEXT(font); THIS(cset) = NEXT(cset); } THIS(fg) = NEXT(fg); THIS(bg) = NEXT(bg); xgcv.font = THIS(font)->fs->fid; xgcv.foreground = THIS(fg); xgcv.background = THIS(bg); XChangeGC(myDisplay(xw), THIS(gc), mask, &xgcv); TRACE2(("...chgCache(%s) updated gc %p(%d)\n", traceCgsEnum(cgsId), THIS(gc), ITEM())); THIS(used) = 0; return THIS(gc); }
//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>> void main(int argc, char** argv) { glutInit(&argc, argv); // initialize the toolkit glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); // set display mode glutInitWindowSize(1000, 600); // set window size glutInitWindowPosition(100, 150); // set window position on screen glutCreateWindow("Spheres"); // open the screen window myDisplay(); // call initial function to create random positions/colors glutDisplayFunc(displaySolid); // register redraw function glEnable(GL_LIGHTING); // enable the light source glEnable(GL_LIGHT0); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // background color glutIdleFunc(displaySolid); // RedrawFunction glutMainLoop(); // go into a loop }
int main (int argc, char** argv) { window = inicia_glfw(3, 3, "Meu 1º Triângulo"); inicia_glew ( ); myInit(); // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); do{ myDisplay(); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); /* Before your application exits, you should terminate the GLFW library if it has been initialized. */ glfwTerminate(); }
static GC newCache(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId, CgsCache * me) { XGCValues xgcv; XtGCMask mask; THIS(font) = NEXT(font); THIS(cset) = NEXT(cset); THIS(fg) = NEXT(fg); THIS(bg) = NEXT(bg); memset(&xgcv, 0, sizeof(xgcv)); xgcv.font = NEXT(font)->fs->fid; mask = (GCForeground | GCBackground | GCFont); switch (cgsId) { case gcNorm: case gcBold: case gcNormReverse: case gcBoldReverse: #if OPT_WIDE_CHARS case gcWide: case gcWBold: case gcWideReverse: case gcWBoldReverse: #endif mask |= (GCGraphicsExposures | GCFunction); xgcv.graphics_exposures = True; /* default */ xgcv.function = GXcopy; break; #if OPT_BOX_CHARS case gcLine: mask |= (GCGraphicsExposures | GCFunction); xgcv.graphics_exposures = True; /* default */ xgcv.function = GXcopy; break; case gcDots: xgcv.fill_style = FillTiled; xgcv.tile = XmuCreateStippledPixmap(XtScreen((Widget) xw), THIS(fg), THIS(bg), xw->core.depth); THIS(tile) = xgcv.tile; mask = (GCForeground | GCBackground); mask |= (GCGraphicsExposures | GCFunction | GCTile | GCFillStyle); xgcv.graphics_exposures = True; /* default */ xgcv.function = GXcopy; break; #endif #if OPT_DEC_CHRSET case gcCNorm: case gcCBold: break; #endif case gcVTcursNormal: /* FALLTHRU */ case gcVTcursFilled: /* FALLTHRU */ case gcVTcursReverse: /* FALLTHRU */ case gcVTcursOutline: /* FALLTHRU */ break; #if OPT_TEK4014 case gcTKcurs: /* FALLTHRU */ /* FIXME */ #endif case gcMAX: /* should not happen */ return 0; } xgcv.foreground = NEXT(fg); xgcv.background = NEXT(bg); THIS(gc) = XCreateGC(myDisplay(xw), myDrawable(xw, cgsWin), mask, &xgcv); TRACE(("getCgsGC(%s) created gc %p(%d)\n", traceCgsEnum(cgsId), (void *) THIS(gc), ITEM())); THIS(used) = 0; return THIS(gc); }
/* Handle user input */ void myKeyHandler(unsigned char ch, int x, int y) { switch(ch) { case 'c': resetCamera(); printf("Camera reset.\n"); break; case 's': case 'S': if (disp_style == DS_SOLID) { disp_style = DS_WIRE; } else { disp_style = DS_SOLID; } print_disp_style(); break; case 'd': /* Cycle through the various display modes */ disp_mode = (disp_mode + 1) % DM_MAX; print_disp_mode(); break; case 'D': /* Cycle through the various display modes backwards */ /* By adding DM_MAX, the args to "%" wil never be negative */ disp_mode = (disp_mode + DM_MAX - 1) % DM_MAX; print_disp_mode(); break; case ',': rotateCamera(5, X_AXIS); break; case '<': rotateCamera(-5, X_AXIS); break; case '.': rotateCamera(5, Y_AXIS); break; case '>': rotateCamera(-5, Y_AXIS); break; case '/': rotateCamera(5, Z_AXIS); break; case '?': rotateCamera(-5, Z_AXIS); break; case '+': /* Zoom in */ zoomCamera(-0.1); break; case '=': /* Zoom out */ zoomCamera(0.1); break; case 'z': myResize(win_width, win_height); printf("Window set to default size.\n"); break; case 't': performanceTest(); break; case 'q': /* Quit with exit code 0 */ endCanvas(0); break; /*********************************************/ /* ADD ADDITIONAL KEYS HERE */ /*********************************************/ case 'i': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if // Increases the radius of triangles in draw_cone_tri_calc r += 0.1; printf("Radius increased by 0.1\n"); break; case 'I': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if r -= 0.1; if (r < 0.1) { r = 0.1; } // if else { printf("Radius decreased by 0.1\n"); } // else break; case 'o': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if // Increase the height of triangles in draw_cone_tri_calc h += 0.1; printf("Height increased by 0.1\n"); break; case 'O': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if h -= 0.1; if (h < 0.1) { h = 0.1; } // if else { printf("Height decreased by 0.1\n"); } // else break; case 'p': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if // Increase number of triangles in draw_cone_tri_calc n += 1; printf("Number of triangles increased by 1\n"); break; case 'P': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if n -= 1; if (n < 3) { n = 3; } // if else { printf("Number of triangles decreased by 1\n"); } // else break; case 'v': if (disp_mode != DM_VRML) { break; } // if vr_object = (vr_object + 1) % VR_MAX; print_vrml_object(); break; default: /* Unrecognized key press, just return */ return; break; } /* * If control reaches here, the key press was recognized. Refresh * the screen, since most key presses change the display in some way. */ myDisplay(); return; }
//***************************************************************************** void main( int argc, char** argv ) { // begin code for reading in arch data for building extruded arch // the data for the arch is read in from the file hlArch.dat // the file contains a number of points, and then a // set of x y points which will be extruded by the makeExtrudedQuadStrip // call /* char * filename = "hlArch.dat"; fstream inStream; inStream.open( filename ); //open needs a c-like string if(inStream.fail() || inStream.eof()) { cout << "can't open file or eof: " << filename << endl; return; } int numPts; // the number of points at the top of the file inStream >> numPts; // read it in Point2 * ptArr = new Point2[numPts]; int sizeArr = numPts; Vector3 upVector = Vector3( 0, 0, 3 ); //assert(pt != NULL); for(int i = 0; i < numPts; i++) // read in the vertices inStream >> ptArr[i].x >> ptArr[i].y ; // end code for building extruded arch // moved this up to myDisplay // This call makes the arch, it makes the arch // using the makeExtrudedQuadStrip method with the // point array the size array and the upVector I created above. //myMesh->makeExtrudedQuadStrip( ptArr, sizeArr, upVector ); */ glutInit(&argc, argv); glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB ); glutInitWindowSize( 640, 480 ); glutInitWindowPosition( 100, 150 ); glutCreateWindow( "castle" ); glutKeyboardFunc( myKeyboard ); glutDisplayFunc( myDisplay ); glutReshapeFunc( myReshape ); glShadeModel( GL_SMOOTH ); glEnable( GL_DEPTH_TEST ); glEnable( GL_NORMALIZE ); glViewport( 0, 0, 640, 480 ); //camera.set( 0, 6, -15, 0, 0, 0, 0, 1, 0 ); // added for camera use camera.set( 0, 0, 40, 0, 0, 0, 0, 1, 0 ); camera.setShape( 35.0f, 64.0f/48.0f, 0.5f, 140.0f ); // added for camera use // read in the stacked_cubes data file //scn.read("textcube.dat"); //scn.read("stacked_cubes2.dat"); //scn.read( "stacked_cubes.dat" ); //doesn't work // read in the myScene1 data file scn.read( "HLSCENE1.DAT" ); glEnable( GL_LIGHTING ); scn.makeLightsOpenGL(); double winHt = 1.0; myDisplay(); glutMainLoop(); }
void mouse(int button, int state, int x, int y) { printf("mouse:%d,%d,%d,%d\n", button, state, x, y); myDisplay(); }
void myKeyboard(unsigned char key, int x, int y){ int k=0; switch (key) { case 'a': //lighting light_setting[0] = light_setting[0] == OFF ? ON : OFF; break; case 'b': //light0 light_setting[1] = light_setting[1] == OFF ? ON : OFF; break; //handle other lights ON/OFF settings - write your code here case 'c': //light Cyan light_setting[2] = (light_setting[2] == OFF) ? ON : OFF; break; case 'd': //light Magenta light_setting[3] = (light_setting[3] == OFF) ? ON : OFF; break; case 'e': //light Yellow light_setting[4] = (light_setting[4] == OFF) ? ON : OFF; break; case 'f': //light Spot light_setting[5] = (light_setting[5] == OFF) ? ON : OFF; break; case 'g': //texture textureSetting = (textureSetting == OFF) ? ON : OFF; break; //handle fog ON/OFF setting - write your code here case 'h': //texture fogSetting = (fogSetting == OFF) ? ON : OFF; break; //handle shading FLAT/SMOOTH setting - write your code here case 'i': //texture shadeModelSetting = (shadeModelSetting == OFF) ? ON : OFF; break; case 'j': //zoomin cameraX = (cameraX - 0.5 > 1.0) ? cameraX - 0.5 : cameraX; cameraY = (cameraY - 0.5 > 1.0) ? cameraY - 0.5 : cameraY; cameraZ = (cameraZ - 0.5 > 1.0) ? cameraZ - 0.5 : cameraZ; if (mouse_yaw_picth) { coiX = cameraX + cosPitch * cosYaw; coiY = cameraY + sinPitch; coiZ = cameraZ + cosPitch * sinYaw; } break; case 'k': //zoomout cameraX = (cameraX + 0.5 < 8) ? cameraX + 0.5 : cameraX; cameraY = (cameraY + 0.5 < 8) ? cameraY + 0.5 : cameraY; cameraZ = (cameraZ + 0.5 < 8) ? cameraZ + 0.5 : cameraZ; if (mouse_yaw_picth) { coiX = cameraX + cosPitch * cosYaw; coiY = cameraY + sinPitch; coiZ = cameraZ + cosPitch * sinYaw; } break; case 'l': //reset cameraX = originalCameraX; cameraY = originalCameraY; cameraZ = originalCameraZ; coiX = originalCoiX; coiY = originalCoiY; coiZ = originalCoiZ; for(k=0;k<6;k++){light_setting[k] = ls_bak[k];} shadeModelSetting=ON; fogSetting =OFF; textureSetting =ON; break; case 'r': //rotate control delta=!delta; break; case 27: //escape key, exit the program exit(0); default: break; } glutDestroyMenu(menu); createMenu(); set_Lights_and_ShadeModel(); myDisplay(); }
/* Handle user input */ void myKeyHandler(unsigned char ch, int x, int y) { switch(ch) { case 'c': resetCamera(); printf("Camera reset.\n"); break; case 's': case 'S': if (disp_style == DS_SOLID) { disp_style = DS_WIRE; } else { disp_style = DS_SOLID; } print_disp_style(); break; case 'd': /* Cycle through the various display modes */ disp_mode = (disp_mode + 1) % DM_MAX; print_disp_mode(); break; case 'D': /* Cycle through the various display modes backwards */ /* By adding DM_MAX, the args to "%" wil never be negative */ disp_mode = (disp_mode + DM_MAX - 1) % DM_MAX; print_disp_mode(); break; case ',': rotateCamera(5, X_AXIS); break; case '<': rotateCamera(-5, X_AXIS); break; case '.': rotateCamera(5, Y_AXIS); break; case '>': rotateCamera(-5, Y_AXIS); break; case '/': rotateCamera(5, Z_AXIS); break; case '?': rotateCamera(-5, Z_AXIS); break; case '+': /* Zoom in */ zoomCamera(-0.1); break; case '=': /* Zoom out */ zoomCamera(0.1); break; case 'z': myResize(win_width, win_height); printf("Window set to default size.\n"); break; case 't': performanceTest(); break; case 'q': /* Quit with exit code 0 */ endCanvas(0); break; /*********************************************/ /* ADD ADDITIONAL KEYS HERE */ /*********************************************/ //Controls for cone triangle calculation case 'I': radius += 0.1; printf("Radius increased to %.1f.\n", radius); break; case 'i': if(radius > 0.1) { radius -= 0.1; } printf("Radius decreased to %.1f.\n", radius); break; case 'O': height += 0.1; printf("Height increased to %.1f.\n", height); break; case 'o': if(height > 0.1) { height -= 0.1; } printf("Height decreased to %.1f.\n", height); break; case 'P': sides += 1; printf("Sides increased to %d.\n", sides); break; case 'p': if(sides > 3) { sides -= 1; } printf("Sides decreased to %d.\n", sides); break; //Controls for switching between vrml objects case 'v': vr_object++; if(vr_object >= VR_MAX) { vr_object = 0; } print_vrml_object(); break; /* Switching between free scene modes */ case 'f': free_scene_mode++; break; case 'F': free_scene_mode--; case 'a': animate = !animate; if(animate) { printf("Animation engaged.\n"); } else { printf("Animation disengaged.\n"); } break; /* Allows mathematical shading on display mode 7 */ case 'y': color_change = !color_change; if(color_change) { printf("Mathematical shading for Display Mode 7.\n"); } else { printf("Regular displace in Display Mode 7.\n"); } break; case 'l': lighting = !lighting; if(lighting) { printf("Lighting Engaged. \n"); light_me_up(); glutPostRedisplay(); } else { printf("Lighting Disengaged. \n"); turn_out_lights(); glutPostRedisplay(); } default: /* Unrecognized key press, just return */ return; break; } /* * If control reaches here, the key press was recognized. Refresh * the screen, since most key presses change the display in some way. */ myDisplay(); return; }