#include using namespace std; #include #include #include "CPUTimer.h" CPUTimer ct; int width = 792, height = 559; //int width = 1274, height = 970; int main_window; double ortho_factor = 5.0; double aspectRatio = 3/4; double L, R, B, T, N, F; double last_x = 0.0, last_y = 0.0; double rotationX = 0.0, rotationY = 0.0; // Disables lighting, then draws RGB axes void draw_axes(double scale){ glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPushMatrix(); glScaled(scale, scale, scale); glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); // Letter X glVertex3f(.9, 0.05, 0.0); glVertex3f(1.0, 0.15, 0.0); glVertex3f(0.9, .15, 0.0); glVertex3f(1.0, 0.05, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); /* X axis */ glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); /* Y axis */ glColor3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 1.0); /* Z axis */ glEnd(); glPopMatrix(); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); } void display(){ ct.reset(); glClearColor(0.0, 0.0, 0.0, 1.0); glColor3d(1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (int i = 0; i < 3; i++){ if (i == 0){ glViewport(0, height - 100, width, 100); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3d(0.5, 0.5, 0.5); glScaled(ortho_factor, ortho_factor, ortho_factor); glBegin(GL_POLYGON); glVertex2d(-1.0, -1.0); glVertex2d(-1.0, 1.0); glVertex2d(1.0, 1.0); glVertex2d(1.0, -1.0); glEnd(); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); }else if (i == 1){ glViewport(0, 0, width/2, height - 100); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3d(1.0, 1.0, 1.0); glScaled(ortho_factor, ortho_factor, ortho_factor); glBegin(GL_POLYGON); glVertex2d(-1.0, -1.0); glVertex2d(-1.0, 1.0); glVertex2d(1.0, 1.0); glVertex2d(1.0, -1.0); glEnd(); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); }else if (i == 2){ glColor3d(0.0, 0.0, 0.0); glViewport(width/2, 0, width/2, height - 100); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3d(0.0, 0.0, 0.0); glScaled(ortho_factor, ortho_factor, ortho_factor); glBegin(GL_POLYGON); glVertex2d(-1.0, -1.0); glVertex2d(-1.0, 1.0); glVertex2d(1.0, 1.0); glVertex2d(1.0, -1.0); glEnd(); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); } if (i != 0){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* if (width > height){ L = -ortho_factor*aspectRatio; R = ortho_factor*aspectRatio; B = -ortho_factor; T = ortho_factor; N = -ortho_factor; F = ortho_factor; }else{ L = -ortho_factor; R = ortho_factor; B = -ortho_factor*aspectRatio; T = ortho_factor*aspectRatio; N = -ortho_factor; F = ortho_factor; } */ L = -ortho_factor; R = ortho_factor; B = -ortho_factor; T = ortho_factor; N = -ortho_factor; F = ortho_factor; glOrtho(L, R, B, T, N, F); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPushMatrix(); glLoadIdentity(); glRotated(rotationY, 0.0, 1.0, 0.0); glRotated(rotationX, 1.0, 0.0, 0.0); draw_axes(ortho_factor); glPopMatrix(); glPopMatrix(); } } glutSwapBuffers(); cerr<<"CPU time: "<= 1080.0){ rotationX = rotationX - 360.0; } while (rotationX <= 360.0){ rotationX = rotationX + 360.0; } while (rotationY >= 1080.0){ rotationY = rotationY - 360.0; } while (rotationY <= 360.0){ rotationY = rotationY + 360.0; } last_x = x; last_y = y; glutPostRedisplay(); } void mouse(int button, int state, int x, int y){ if ((button == GLUT_LEFT_BUTTON || button == GLUT_RIGHT_BUTTON) && state == GLUT_DOWN){ last_x = x; last_y = y; } } void reshape(int w, int h){ width = w; height = h; cerr<<"Width: "<