/* * 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); // Reset view angle else if (ch == '0') { th = ph = 0; xOffset = 0; yOffset = 2.0; zOffset = -60.0; } else if (ch == '1') { gobowl(0); } else if (ch == '2') { gobowl(1); } else if (ch == '3') { gobowl(2); } else if (ch == '4') { gobowl(3); } else if (ch == '5') { gobowl(4); } else if (ch == '6') { gobowl(5); } else if (ch == '7') { gobowl(6); } else if (ch == '8') { gobowl(7); } // Toggle axes else if (ch == 'x' || ch == 'X') axes = 1-axes; // Toggle lighting else if (ch == 'l' || ch == 'L') light = 1-light; // Switch projection mode else if (ch == 'p' || ch == 'P') { mode = (mode+1)%3; th = ph = 0; xOffset = 0; yOffset = 0; zOffset = 2*dim; } // Change field of view angle else if (ch == '-' && ch>1) fov--; else if (ch == '+' && ch<179) fov++; else if (ch == 'r') { roll = 0; xOffset = -31.0; yOffset = 4.0; zOffset = 0.0; th = 0; ph = 180; } //FIRST PERSON NAVIGATION WITH WASD else if(ch == 'w' || ch == 'W') { xOffset -= 2*Sin(th); zOffset += 2*Cos(th); checkOffsets(); } else if(ch == 's' || ch == 'S') { xOffset += 2*Sin(th); zOffset -= 2*Cos(th); checkOffsets(); } else if(ch == 'a' || ch == 'A') { xOffset -= 2*Sin(th-90); zOffset += 2*Cos(th-90); checkOffsets(); } else if(ch == 'd' || ch == 'D') { xOffset += 2*Sin(th-90); zOffset -= 2*Cos(th-90); checkOffsets(); } else if(ch == '[') { yOffset += 1; checkOffsets(); } else if(ch == ']') { yOffset -= 1; checkOffsets(); } // Reproject Project(fov,asp,dim); // Tell GLUT it is necessary to redisplay the scene glutPostRedisplay(); }
void TileToRowsCCPacker::callGeneric(Array<POINT> &box, Array<POINT> &offset, double pageRatio) { OGDF_ASSERT(box.size() == offset.size()); // negative pageRatio makes no sense, // pageRatio = 0 will cause division by zero OGDF_ASSERT(pageRatio > 0); const int n = box.size(); int nRows = 0; Array<RowInfo<POINT> > row(n); // sort the box indices according to decreasing height of the // corresponding boxes Array<int> sortedIndices(n); int i; for(i = 0; i < n; ++i) sortedIndices[i] = i; DecrIndexComparer<POINT> comp(box); sortedIndices.quicksort(comp); // i iterates over all box indices according to decreasing height of // the boxes for(int iSI = 0; iSI < n; ++iSI) { int i = sortedIndices[iSI]; // Find the row which increases the covered area as few as possible. // The area measured is the area of the smallest rectangle that covers // all boxes and whose width / height ratio is pageRatio int bestRow = findBestRow(row,nRows,pageRatio,box[i]); // bestRow = -1 indictes that a new row is added if (bestRow < 0) { struct RowInfo<POINT> &r = row[nRows++]; r.m_boxes.pushBack(i); r.m_maxHeight = box[i].m_y; r.m_width = box[i].m_x; } else { struct RowInfo<POINT> &r = row[bestRow]; r.m_boxes.pushBack(i); r.m_maxHeight = max(r.m_maxHeight,box[i].m_y); r.m_width += box[i].m_x; } } // At this moment, we know which box is contained in which row. // The following loop sets the required offset of each box typename POINT::numberType y = 0; // sum of the heights of boxes 0,...,i-1 for(i = 0; i < nRows; ++i) { const RowInfo<POINT> &r = row[i]; typename POINT::numberType x = 0; // sum of the widths of the boxes to the left of box *it for(int j : r.m_boxes) { offset[j] = POINT(x,y); x += box[j].m_x; } y += r.m_maxHeight; } OGDF_ASSERT_IF(dlConsistencyChecks, checkOffsets(box,offset)); }
//Used to assign actions to keyboard presses. void key(unsigned char ch,int x,int y) { //change the mode of viewing the scene if(ch == '1') { mode = 0; dim = 860; th = 0; ph = 0; outside=1; } //change the mode of viewing the scene else if(ch == '2') { mode = 1; dim = 800; th = 0; ph = 0; xOffset = 0; yOffset = 0; zOffset = -1600; outside=1; } //reset angle using 4 if(ch == '4') { th=0; ph=0; } //reset zoom using 5 else if(ch == '5') dim=860; //reset first person location using 6 else if(ch == '6') { xOffset = 0; yOffset = 0; zOffset = -1600; outside = 1; } else if(ch == '7') { minHrOffset=0; } //exit using esc else if(ch == 27) exit(0); //zoom out else if(ch == '[') dim += 30; //zoom in else if(ch == ']') dim -= 30; //FIRST PERSON NAVIGATION WITH WASD else if(ch == 'w' || ch == 'W') { xOffset -= 20*Sin(th); zOffset += 20*Cos(th); checkOffsets(); } else if(ch == 's' || ch == 'S') { xOffset += 20*Sin(th); zOffset -= 20*Cos(th); checkOffsets(); } else if(ch == 'a' || ch == 'A') { xOffset -= 20*Sin(th-90); zOffset += 20*Cos(th-90); checkOffsets(); } else if(ch == 'd' || ch == 'D') { xOffset += 20*Sin(th-90); zOffset -= 20*Cos(th-90); checkOffsets(); } else if(ch == 't' || ch == 'T') { minHrOffset-=5; if(minHrOffset < -minOfHr) minHrOffset = -minOfHr; } else if(ch == 'y' || ch == 'Y') { minHrOffset+=5; if(minHrOffset > (59-minOfHr)) minHrOffset = (59-minOfHr); } else if(ch == 'g' || ch == 'G') { hrDayOffset--; if(hrDayOffset < 0) hrDayOffset = 0; } else if(ch == 'h' || ch == 'H') { hrDayOffset++; if(hrDayOffset > 24) hrDayOffset = 24; } else if(ch == 'u' || ch == 'U') { minHrOffset = 0; } else if(ch == 'j' || ch == 'J') { hrDayOffset = 0; } //ensures dimension is never too small to fit arch. if(dim < 0) dim = 0; Project(fov, asp, dim); //Tells GLUT to redisplay. glutPostRedisplay(); }