Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I got stuck halfway throught this assignment. You are to write a program that will allow the user to view 4 viewports at a time,

I got stuck halfway throught this assignment.

You are to write a program that will allow the user to view 4 viewports at a time, and be able to change any viewport using the following viewports and keyboard keys:

  • Key 0 - Perspective View (glFrustrum)
  • Key 1 - Front View (glOrtho)
  • Key 2 - Back View (glOrtho)
  • Key 3 - Left View (glOrtho)
  • Key 4 - Right View (glOrtho)
  • Key 5 - Top View (glOrtho)
  • Key 6 - Bottom View (glOrtho)

For each viewport, a label of the viewport must be shown.The only view that should be movable is the Perspective View. The glutMouseFunc and the glutMotionFunc should be used to change the orientation of only that view. The glutKeyboardFunc will be used to modify the viewports from one type of viewport to another. Remember, the mouse cursor must be in the viewport you want to change to another view.

image text in transcribed

This is what i have so far:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Multiview Left View Perspective View Top View Front View # #ifdef APPLE # include // definitions for GL graphics routines # include // definitions for GL input device handling include // deginitions for the GLUT utility toolkit #else # include // definitions for GL graphics routines # include // definitions for GL input device handling # include // deginitions for the GLUT utility toolkit #endif // definitions for standard I/O routines // definitions for math library #include #include #include using namespace std; #define WIDTH 600 #define HEIGHT 600 #define ESC 27 // numeric code for keyboard Esc key #define NONE -1 // used to indicate no mouse button pressed #define DRAWWIDTH 300 // view volume sizes (note: width and #define DRAWHEIGHT 300 // height should be in same ratio as window) #define NEAR 10 // distance of near clipping plane #define FAR 1000 // distance of far clipping plane #define DEPTH -100 // initial z coord, of center of cube 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 #define ROTFACTOR 0.2 // degrees rotation per pixel of mouse movement #define XLATEFACTOR 0.5 // units of translation per pixel of mouse movement #define AMBIENT FRACTION 0.2 #define DIFFUSE_FRACTION 0.8 enum ViewType { PERSPECTIVE, FRONT, BACK, LEFT, RIGHT, TOP, BOTTOM }; ViewType theViewport[4]; int num char label[7][20] = { "Perspective View", "Front View", "Back View", "Left View", "Right View", "Top View", "Bottom View" }; // color for objects const static float LightBlue[4] = {0.5, 0.5, 1.0, 1.0}; // Camera position and orientation static double Pan; static double Tilt; static double Approach; // model orientation static double Thetax; static double Thetay; // global variables to track mouse and shift key static int MouseX; static int MouseY; static int Button = NONE; // Routine to initialize the state of the program to start-up defaults void setInitialState() { 3 void setInitialState(){ // initial camera viewing controls glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); // set up light o glEnable(GL_LIGHTC); // always leave light on // initial camera orientation and position Pan = 0; Tilt = 0; Approach = DEPTH; // initial model orientation Thetax = 0; Thetay = 0; } 7 3 3 Output text to screen { 2 3 void output (GLfloat x, GLfloat y, char *text) char *p; glPushMatrix(); glTranslatef(x, y, 0); glScalef(.1, .1, 1); for (p = text; *p; p++) glutstrokeCharacter (GLUT_STROKE_ROMAN, *p); glPopMatrix(); 3 1. Watch mouse motion 7 3 void m_Motion(int x, int y) { int delta; y = -y; int dy - y - Mousey; int dx = x - MouseX; switch (Button) { case GLUT LEFT BUTTON: ThetaX -= ROTFACTOR * dy; Thetay += ROTFACTOR * dx; glutPostredisplay(); break; case GLUT MIDDLE BUTTON: Pan -= ROTFACTOR * dx; Tilt += ROTFACTOR * dy; glutPostRedisplay(); break; case GLUT_RIGHT BUTTON: delta = (fabs(dx) > fabs (dy)? dx: dy); Approach += XLATEFACTOR * delta; glutPostRedisplay(); break; 3 delta; Approach += XLATEFACTOR glutPostRedisplay(); break; } MouseX = x; Mouse Y = y; } Watch mouse button presses and handle them void handleButton(int button, int state, int x, int y) { if(state == GLUT UP) Button = NONE; // no button pressed else{ Mouse Y = -y: // invert y window coordinate to correspond with OpenGL MouseX = x; Button = button; // store which button pressed } 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 10A Draw the Orthographic Model void draworthoModel() { float ambient_color[4]; float diffuse_color[4]; for(int i = 0; i & x & y 0 && X 300 & y // definitions for GL graphics routines # include // definitions for GL input device handling include // deginitions for the GLUT utility toolkit #else # include // definitions for GL graphics routines # include // definitions for GL input device handling # include // deginitions for the GLUT utility toolkit #endif // definitions for standard I/O routines // definitions for math library #include #include #include using namespace std; #define WIDTH 600 #define HEIGHT 600 #define ESC 27 // numeric code for keyboard Esc key #define NONE -1 // used to indicate no mouse button pressed #define DRAWWIDTH 300 // view volume sizes (note: width and #define DRAWHEIGHT 300 // height should be in same ratio as window) #define NEAR 10 // distance of near clipping plane #define FAR 1000 // distance of far clipping plane #define DEPTH -100 // initial z coord, of center of cube 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 #define ROTFACTOR 0.2 // degrees rotation per pixel of mouse movement #define XLATEFACTOR 0.5 // units of translation per pixel of mouse movement #define AMBIENT FRACTION 0.2 #define DIFFUSE_FRACTION 0.8 enum ViewType { PERSPECTIVE, FRONT, BACK, LEFT, RIGHT, TOP, BOTTOM }; ViewType theViewport[4]; int num char label[7][20] = { "Perspective View", "Front View", "Back View", "Left View", "Right View", "Top View", "Bottom View" }; // color for objects const static float LightBlue[4] = {0.5, 0.5, 1.0, 1.0}; // Camera position and orientation static double Pan; static double Tilt; static double Approach; // model orientation static double Thetax; static double Thetay; // global variables to track mouse and shift key static int MouseX; static int MouseY; static int Button = NONE; // Routine to initialize the state of the program to start-up defaults void setInitialState() { 3 void setInitialState(){ // initial camera viewing controls glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); // set up light o glEnable(GL_LIGHTC); // always leave light on // initial camera orientation and position Pan = 0; Tilt = 0; Approach = DEPTH; // initial model orientation Thetax = 0; Thetay = 0; } 7 3 3 Output text to screen { 2 3 void output (GLfloat x, GLfloat y, char *text) char *p; glPushMatrix(); glTranslatef(x, y, 0); glScalef(.1, .1, 1); for (p = text; *p; p++) glutstrokeCharacter (GLUT_STROKE_ROMAN, *p); glPopMatrix(); 3 1. Watch mouse motion 7 3 void m_Motion(int x, int y) { int delta; y = -y; int dy - y - Mousey; int dx = x - MouseX; switch (Button) { case GLUT LEFT BUTTON: ThetaX -= ROTFACTOR * dy; Thetay += ROTFACTOR * dx; glutPostredisplay(); break; case GLUT MIDDLE BUTTON: Pan -= ROTFACTOR * dx; Tilt += ROTFACTOR * dy; glutPostRedisplay(); break; case GLUT_RIGHT BUTTON: delta = (fabs(dx) > fabs (dy)? dx: dy); Approach += XLATEFACTOR * delta; glutPostRedisplay(); break; 3 delta; Approach += XLATEFACTOR glutPostRedisplay(); break; } MouseX = x; Mouse Y = y; } Watch mouse button presses and handle them void handleButton(int button, int state, int x, int y) { if(state == GLUT UP) Button = NONE; // no button pressed else{ Mouse Y = -y: // invert y window coordinate to correspond with OpenGL MouseX = x; Button = button; // store which button pressed } 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 10A Draw the Orthographic Model void draworthoModel() { float ambient_color[4]; float diffuse_color[4]; for(int i = 0; i & x & y 0 && X 300 & y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago

Question

What are some of the possible scenes from our future?

Answered: 1 week ago