Question: The objective of this programming assignment is to load a 3D data from a file and display it using OpenGL. You will also implement some
The objective of this programming assignment is to load a 3D data from a file and display it using OpenGL. You will also implement some basic keyboard interaction.
1. Download the test.txt file from blackboard. This file contains a set 3D points. The file format is as follows: #number of point x1 y1 z1 r1 g1 b1 x2 y2 z2 r2 g2 b2 . xn yn zn rn gn bn
2. Write an OpenGL code to load and display the content of this file.
3. Implement simple navigation system using the keyboard. a. Use the arrows to move left, right, forward and backward. b. Use PgDn, and PgUP to move the model up and down.
using Visual Studio 17 #ifdef __APPLE__ #include#include #include #else #include #include #endif #define kWindowWidth 400 #define kWindowHeight 300 GLvoid InitGL(void); GLvoid DrawGLScene(void); GLvoid ReSizeGLScene(int Width, int Height); int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (kWindowWidth, kWindowHeight); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); InitGL(); glutDisplayFunc(DrawGLScene); glutReshapeFunc(ReSizeGLScene); glutMainLoop(); return 0; } GLvoid ReSizeGLScene(int width, int height) { if(height == 0) { height = 1; } glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } GLvoid InitGL(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); } GLvoid DrawGLScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5f, 0.0f, -6.0f); glColor3f(1.0, 0.0, 0.0); glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); glTranslatef(1.0, 1.0, 1.0); glColor3f(0.0, 1.0, 0.0); glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glEnd(); glutSwapBuffers(); }
test.txt file:
542258 48.95 49.03 9.98 0.27 0.27 0.27 49.21 48.89 9.99 0.27 0.27 0.27 48.20 49.02 9.98 0.27 0.27 0.33 48.45 48.87 9.98 0.27 0.27 0.27 48.72 48.72 10.01 0.27 0.27 0.27 48.98 48.57 10.03 0.27 0.27 0.27 49.25 48.41 10.06 0.27 0.27 0.27 49.24 48.43 9.25 0.27 0.27 0.27 47.29 49.07 9.94 0.20 0.27 0.27 47.55 48.92 9.96 0.20 0.27 0.27 47.80 48.77 9.95 0.20 0.27 0.27 48.07 48.62 9.98 0.27 0.27 0.27 48.34 48.47 10.02 0.27 0.27 0.27 48.59 48.32 10.01 0.27 0.27 0.33 48.85 48.17 10.03 0.27 0.27 0.27 48.88 48.16 9.34 0.27 0.27 0.27 48.97 48.12 8.79 0.27 0.27 0.27 49.26 47.95 8.91 0.27 0.27 0.27 49.18 48.01 7.84 0.27 0.27 0.27 49.30 47.95 7.41 0.27 0.27 0.27 49.34 47.94 6.72 0.27 0.27 0.27 46.64 48.99 9.95 0.53 0.53 0.47 46.90 48.84 9.97 0.40 0.40 0.40 47.16 48.69 9.98 0.27 0.33 0.33 47.41 48.55 9.97 0.20 0.27 0.27 47.68 48.39 9.99 0.27 0.27 0.27 47.94 48.25 10.01 0.27 0.27 0.27 48.20 48.10 10.02 0.20 0.27 0.27 48.46 47.95 10.04 0.27 0.27 0.27 48.53 47.91 9.46 0.20 0.27 0.27 48.59 47.89 8.84 0.27 0.27 0.27 48.70 47.84 8.35 0.27 0.27 0.27 48.79 47.79 7.85 0.27 0.27 0.27 48.93 47.72 7.45 0.27 0.27 0.33 48.96 47.71 6.74 0.27 0.27 0.33 49.21 47.57 6.71 0.27 0.27 0.27 45.61 49.01 9.99 0.47 0.47 0.47 45.86 48.86 9.99 0.47 0.47 0.47 46.11 48.72 9.98 0.53 0.53 0.47 46.37 48.57 9.98 0.47 0.53 0.47 46.63 48.42 9.99 0.53 0.53 0.53 46.89 48.27 9.99 0.47 0.53 0.47 47.14 48.13 9.98 0.47 0.47 0.47 47.41 47.98 10.01 0.40 0.40 0.40 47.67 47.82 10.04 0.27 0.27 0.27 47.93 47.68 10.06 0.27 0.27 0.27 47.98 47.66 9.43 0.27 0.27 0.27 48.13 47.58 9.09 0.20 0.27 0.27 48.37 47.44 9.02 0.20 0.27 0.27 48.59 47.32 8.92 0.27 0.27 0.27 48.39 47.45 7.45 0.20 0.27 0.27 47.98 47.72 5.32 0.27 0.27 0.27 48.07 47.68 4.78 0.20 0.27 0.27 48.14 47.64 4.21 0.20 0.27 0.27 49.17 47.02 6.68 0.53 0.53 0.47 48.80 47.32 0.47 0.27 0.27 0.27 49.04 47.18 0.39 0.20 0.27 0.27 44.58 49.10 11.42 0.47 0.53 0.47 44.60 49.09 10.70 0.47 0.53 0.47 44.64 49.08 10.04 0.47 0.53 0.47 44.89 48.94 10.03 0.47 0.47 0.47 45.14 48.79 10.01 0.47 0.47 0.47 45.40 48.64 10.01 0.53 0.47 0.47 45.66 48.50 10.01 0.47 0.47 0.47 45.91 48.35 10.01 0.47 0.47 0.47 46.17 48.21 10.01 0.53 0.53 0.53 46.42 48.06 9.99 0.53 0.53 0.53 46.68 47.91 10.01 0.53 0.53 0.47 46.94 47.77 10.01 0.47 0.53 0.47 47.20 47.62 10.03 0.53 0.53 0.47 47.46 47.47 10.04 0.47 0.53 0.47 47.70 47.33 9.99 0.40 0.40 0.40 47.70 47.34 9.19 0.40 0.40 0.40 47.97 47.19 9.24 0.27 0.27 0.27 48.19 47.06 9.13 0.27 0.27 0.27 47.76 47.33 7.75 0.33 0.33 0.33 47.96 47.22 7.59 0.27 0.27 0.27 48.11 47.14 7.24 0.27 0.27 0.27 47.56 47.48 5.48 0.47 0.47 0.47 47.61 47.46 4.83 0.40 0.47 0.40 47.74 47.39 4.41 0.40 0.40 0.40 47.92 47.29 4.17 0.27 0.27 0.33 48.50 46.94 5.20 0.20 0.27 0.27 48.43 47.00 4.14 0.20 0.27 0.27 48.22 47.14 2.63 0.20 0.27 0.27 48.01 47.27 1.97 0.27 0.27 0.27 48.26 47.12 1.92 0.27 0.27 0.27 48.44 47.03 1.65 0.20 0.27 0.27 48.33 47.11 0.46 0.27 0.27 0.27 48.57 46.97 0.38 0.20 0.27 0.27 48.82 46.83 0.37 0.27 0.33 0.33 49.09 46.68 0.38 0.60 0.53 0.47 49.34 46.53 0.36 0.73 0.53 0.47 43.79 49.11 11.45 0.53 0.53 0.47 44.05 48.96 11.48 0.53 0.53 0.53 44.31 48.81 11.49 0.47 0.53 0.47 44.57 48.66 11.51 0.47 0.47 0.47 44.82 48.52 11.49 0.47 0.47 0.47 44.88 48.50 10.87 0.47 0.47 0.47 44.89 48.51 10.10 0.47 0.47 0.47 45.13 48.37 10.06 0.47 0.47 0.47 45.38 48.22 10.05 0.47 0.47 0.47 45.64 48.08 10.06 0.53 0.47 0.47 45.89 47.94 10.03 0.47 0.47 0.47 46.15 47.79 10.03 0.53 0.53 0.53 46.41 47.64 10.05 0.53 0.53 0.53 46.67 47.49 10.06 0.47 0.53 0.47 46.93 47.34 10.08 0.47 0.53 0.53 47.18 47.20 10.07 0.53 0.53 0.53 47.16 47.23 9.19 0.53 0.53 0.53 47.36 47.11 9.04 0.53 0.53 0.47 47.64 46.95 9.11 0.47 0.47 0.47 47.51 47.04 7.88 0.47 0.47 0.47 47.62 46.99 7.41 0.47 0.47 0.47 47.22 47.25 5.30 0.53 0.53 0.47 47.32 47.20 4.80 0.53 0.53 0.47 47.39 47.17 4.21 0.53 0.53 0.47 47.98 46.82 5.25 0.27 0.27 0.27 47.72 47.00 2.78 0.47 0.47 0.47 46.98 47.46 0.38 0.47 0.53 0.47 47.73 47.01 1.96 0.47 0.47 0.47 48.00 46.85 2.02 0.20 0.20 0.27 48.00 46.86 1.18 0.20 0.20 0.27 47.82 46.98 0.58 0.33 0.33 0.33 48.03 46.86 0.42 0.20 0.20 0.27 48.29 46.71 0.40 0.27 0.27 0.27 48.54 46.57 0.39 0.53 0.53 0.47 48.80 46.42 0.39 0.67 0.53 0.47 49.06 46.27 0.39 0.73 0.53 0.47 49.32 46.13 0.37 0.73 0.47 0.40 43.14 49.04 11.40 0.47 0.47 0.47 43.40 48.89 11.41 0.47 0.53 0.47 43.66 48.75 11.41 0.47 0.53 0.47 43.93 48.59 11.44 0.47 0.47 0.47 44.19 48.45 11.44 0.47 0.47 0.47 44.46 48.29 11.49 0.47 0.47 0.47 44.71 48.15 11.49 0.47 0.47 0.47 44.97 48.00 11.51 0.47 0.47 0.47 45.11 47.93 11.12 0.47 0.47 0.47 45.12 47.93 10.37 0.47 0.47 0.47 45.27 47.85 10.05 0.47 0.47 0.47 45.53 47.70 10.05 0.53 0.53 0.53 45.79 47.56 10.05 0.53 0.53 0.53 46.04 47.41 10.04 0.47 0.47 0.47 46.30 47.26 10.06 0.47 0.47 0.47 46.56 47.12 10.06 0.53 0.53 0.53 46.81 46.97 10.05 0.53 0.53 0.53 46.83 46.98 9.30 0.53 0.53 0.53 46.92 46.93 8.80 0.47 0.53 0.53 47.04 46.87 8.35 0.47 0.53 0.47 47.14 46.82 7.88 0.47 0.53 0.47 47.26 46.76 7.44 0.47 0.53 0.47 46.97 46.95 5.68 0.47 0.53 0.53 46.99 46.95 4.92 0.47 0.53 0.53 47.02 46.94 4.20 0.47 0.53 0.53 47.28 46.79 4.19 0.47 0.53 0.47 47.53 46.65 4.16 0.53 0.53 0.47 47.64 46.59 3.71 0.47 0.53 0.47 47.52 46.68 2.49 0.53 0.53 0.47 47.58 46.66 1.83 0.53 0.53 0.47 47.67 46.61 1.29 0.53 0.53 0.53 47.69 46.61 0.50 0.53 0.53 0.53 47.91 46.49 0.37 0.47 0.47 0.47 48.17 46.34 0.38 0.27 0.20 0.20 48.43 46.19 0.37 0.47 0.40 0.40 48.68 46.05 0.36 0.73 0.60 0.53 48.95 45.90 0.37 0.73 0.47 0.40 49.21 45.75 0.36 0.73 0.47 0.40 42.16 49.04 11.30 0.40 0.47 0.47 42.43 48.89 11.32 0.47 0.47 0.47 42.69 48.74 11.34 0.47 0.47 0.47 42.95 48.59 11.35 0.47 0.47 0.47 43.21 48.44 11.37 0.47 0.47 0.47 43.47 48.29 11.38 0.47 0.47 0.47 43.74 48.14 11.40 0.47 0.47 0.47 44.00 47.99 11.41 0.47 0.47 0.47 44.26 47.85 11.42 0.47 0.47 0.47 44.52 47.70 11.44 0.47 0.47 0.47 44.78 47.55 11.45 0.47 0.47 0.47 45.04 47.40 11.46 0.47 0.47 0.47 45.30 47.26 11.48 0.47 0.47 0.47 45.57 47.10 11.51 0.47 0.47 0.47 45.78 46.98 11.37 0.47 0.47 0.47 45.77 47.00 10.53 0.47 0.47 0.47 45.88 46.95 10.07 0.47 0.53 0.47 46.12 46.81 10.04 0.47 0.47 0.47 46.38 46.67 10.03 0.47 0.47 0.47 46.35 46.69 9.16 0.47 0.47 0.47 46.46 46.64 8.67 0.47 0.47 0.47 46.57 46.58 8.22 0.47 0.47 0.47 46.67 46.54 7.73 0.47 0.47 0.47 46.81 46.46 7.38 0.47 0.53 0.53 46.50 46.66 5.56 0.47 0.47 0.47 46.50 46.68 4.73 0.47 0.47 0.47 46.91 46.43 5.22 0.47 0.53 0.53 47.16 46.29 5.19 0.53 0.53 0.53 46.53 46.68 3.18 0.47 0.47 0.47 47.26 46.24 4.70 0.53 0.53 0.53 46.54 46.69 1.56 0.47 0.47 0.47 46.57 46.69 0.81 0.47 0.47 0.47 46.70 46.62 0.38 0.47 0.53 0.47 47.18 46.34 1.08 0.53 0.53 0.53 46.95 46.48 0.37 0.53 0.53 0.53 47.21 46.33 0.37 0.53 0.53 0.53 47.47 46.19 0.35 0.53 0.53 0.53 47.73 46.04 0.35 0.53 0.53 0.53 47.99 45.89 0.34 0.60 0.53 0.47 48.24 45.75 0.33 0.67 0.53 0.47 48.50 45.60 0.32 0.73 0.53 0.47 48.76 45.45 0.32 0.73 0.53 0.47 49.02 45.30 0.32 0.73 0.53 0.47 49.28 45.16 0.31 0.80 0.53 0.47 41.36 49.12 11.29 0.33 0.40 0.40 41.62 48.98 11.31 0.40 0.40 0.40 41.89 48.83 11.32 0.40 0.40 0.47 42.15 48.68 11.35 0.40 0.47 0.47 42.42 48.52 11.37 0.47 0.47 0.47 42.68 48.37 11.40 0.47 0.47 0.47 42.95 48.23 11.40 0.47 0.47 0.47 43.21 48.08 11.42 0.47 0.47 0.47 43.47 47.93 11.44 0.47 0.47 0.47 43.73 47.78 11.46 0.47 0.47 0.47 43.99 47.63 11.48 0.47 0.47 0.47 44.26 47.48 11.51 0.47 0.47 0.47 44.52 47.33 11.51 0.47 0.47 0.47 44.77 47.19 11.51 0.47 0.47 0.47 45.03 47.04 11.52 0.47 0.47 0.47 45.29 46.89 11.53 0.47 0.47 0.47 45.56 46.74 11.56 0.47 0.47 0.47 45.82 46.59 11.56 0.47 0.47 0.47 45.92 46.54 11.08 0.47 0.47 0.47 45.93 46.55 10.31 0.47 0.47 0.47 45.95 46.55 9.58 0.47 0.47 0.47 45.98 46.54 8.86 0.47 0.47 0.47 46.09 46.48 8.42 0.47 0.47 0.47 46.20 46.43 7.96 0.47 0.53 0.53 46.33 46.36 7.54 0.47 0.47 0.47 46.03 46.56 5.80 0.47 0.47 0.47 46.04 46.56 5.02 0.47 0.47 0.47 46.06 46.56 4.24 0.47 0.47 0.47 46.06 46.57 3.44 0.47 0.47 0.47 46.08 46.57 2.67 0.47 0.47 0.47 46.10 46.57 1.88 0.47 0.47 0.47 46.12 46.57 1.12 0.47 0.47 0.47 46.33 46.45 0.96 0.47 0.47 0.47 46.43 46.40 0.45 0.47 0.47 0.47 46.68 46.26 0.41 0.47 0.47 0.47 46.94 46.12 0.40 0.53 0.53 0.53 47.20 45.97 0.40 0.53 0.53 0.53 47.46 45.82 0.39 0.53 0.53 0.47 47.72 45.68 0.39 0.60 0.47 0.47 47.97 45.53 0.37 0.73 0.53 0.47 48.23 45.38 0.37 0.73 0.53 0.47 48.49 45.24 0.35 0.73 0.53 0.47 48.75 45.09 0.35 0.73 0.53 0.47 49.00 44.95 0.34 0.80 0.53 0.47 49.26 44.80 0.34 0.80 0.53 0.47 40.62 49.10 11.23 0.53 0.53 0.53 40.89 48.95 11.26 0.47 0.47 0.47 41.15 48.80 11.27 0.40 0.47 0.40 41.42 48.65 11.29 0.40 0.40 0.40 41.68 48.50 11.30 0.40 0.40 0.40 41.95 48.35 11.33 0.40 0.47 0.47 42.21 48.20 11.35 0.47 0.47 0.47 42.48 48.05 11.38 0.47 0.47 0.47 42.74 47.90 11.38 0.47 0.47 0.47 43.00 47.75 11.40 0.47 0.47 0.47 43.26 47.60 11.41 0.47 0.47 0.47 43.53 47.45 11.43 0.47 0.47 0.47 43.79 47.31 11.45 0.47 0.47 0.47 44.05 47.16 11.46 0.47 0.47 0.47 44.31 47.01 11.48 0.47 0.47 0.47 44.58 46.86 11.51 0.47 0.47 0.47 44.83 46.72 11.51 0.47 0.47 0.47 45.09 46.57 11.51 0.47 0.47 0.47 45.36 46.42 11.53 0.47 0.47 0.47 45.81 46.15 12.15 0.47 0.47 0.47 45.62 46.27 11.56 0.47 0.47 0.47 45.97 46.07 11.87 0.53 0.53 0.53 45.67 46.26 10.13 0.47 0.47 0.47 45.68 46.27 9.36 0.47 0.47 0.47 45.69 46.27 8.59 0.47 0.47 0.47 45.71 46.27 7.84 0.47 0.47 0.47 45.79 46.23 7.30 0.47 0.47 0.47 45.74 46.28 6.32 0.47 0.47 0.47 45.75 46.28 5.53 0.47 0.47 0.47 45.76 46.29 4.75 0.47 0.47 0.47 45.77 46.29 3.95 0.47 0.47 0.47 45.78 46.30 3.16 0.47 0.47 0.47 45.80 46.30 2.38 0.47 0.47 0.47 45.80 46.31 1.57 0.47 0.47 0.47 45.86 46.29 0.91 0.47 0.53 0.47
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
