/* * GLUT calls this routine when an arrow key is pressed */ void special(int key,int x,int y) { if(!fp) { // Right arrow key - increase angle by 5 degrees if (key == GLUT_KEY_RIGHT) th += 5; // Left arrow key - decrease angle by 5 degrees else if (key == GLUT_KEY_LEFT) th -= 5; // Up arrow key - increase elevation by 5 degrees else if (key == GLUT_KEY_UP) ph += 5; // Down arrow key - decrease elevation by 5 degrees else if (key == GLUT_KEY_DOWN) ph -= 5; // PageUp key - increase dim else if (key == GLUT_KEY_PAGE_UP && dim>1) dim -= 0.1; // PageDown key - decrease dim else if (key == GLUT_KEY_PAGE_DOWN) dim += 0.1; // Keep angles to +/-360 degrees th %= 360; ph %= 360; } // Update projection myProject(); // Tell GLUT it is necessary to redisplay the scene glutPostRedisplay(); }
/* * GLUT calls this routine when the window is resized */ void reshape(int width,int height) { // Ratio of the width to the height of the window asp = (height>0) ? (double)width/height : 1; // Set the viewport to the entire window glViewport(0,0, width,height); // Set projection myProject(); }
/// /// CUDA-lizable /// void projectAllParticles(std::vector<Particle> &pars3d, std::vector<Particle> &pars2d) { pars2d.clear(); for(int i = 0; i < pars3d.size(); i++) { double vPrjPos[3] = {0}; if(!myProject( pars3d[i]._pos[0], pars3d[i]._pos[1], pars3d[i]._pos[2], modelview, projection, viewport, vPrjPos + 0, vPrjPos + 1, vPrjPos + 2) ) { printf("gluProject fail.. %d\n", i); } float vFvPrjPos[3] = {vPrjPos[0], vPrjPos[1], vPrjPos[2]}; float vel[3] = {0}; pars2d.push_back(Particle(pars3d[i].nId, vFvPrjPos, vel, pars3d[i]._color)); } }
/* * GLUT calls this routine when a key is pressed */ void key(unsigned char ch,int x,int y) { // Exit on ESC if (ch == 27) exit(0); // Toggle axes else if (ch == '9') axes = 1-axes; // Pause Light else if (ch == ' ') { move = 1-move; } // Move light else if (ch == '<') zh += 3; else if (ch == '>') zh -= 3; // Toggle first person else if (ch == 'f' || ch == 'F') { fp = 1-fp; } if (fp) { double dt = 0.05; if (ch == 'w' || ch == 'W'){ Ex += Cx*dt; //Update the eye vector based on the camera vector Ez += Cz*dt; } else if (ch == 'a' || ch == 'A'){ rot -= 3; } else if (ch == 's' || ch == 'S'){ Ex -= Cx*dt; Ez -= Cz*dt; } else if (ch == 'd' || ch == 'D'){ rot += 3; } // Keep angles to +/-360 degrees rot %= 360; } else { // Reset view angle if (ch == '0') th = ph = 0; // Switch display mode else if (ch == 'm' || ch == 'M') mode = 1-mode; // Change field of view angle else if (ch == '1') fov--; else if (ch == '2') fov++; } // Reproject myProject(); // Animate if requested glutIdleFunc(move?idle:NULL); // Tell GLUT it is necessary to redisplay the scene glutPostRedisplay(); }