0% found this document useful (0 votes)
136 views6 pages

Assignment 1: Due Date: 23 June 2020

Assignment 1 is due on June 23, 2020 and contains two questions. Question 1 asks to draw a face using OpenGL output primitives. Question 2 provides OpenGL code to display axes and asks for code snippets to draw and manipulate wireframe cubes at different positions and with different rotations, transformations, and projections. The goal is to recreate specific images showing cubes and axes from different viewpoints.

Uploaded by

frank musa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views6 pages

Assignment 1: Due Date: 23 June 2020

Assignment 1 is due on June 23, 2020 and contains two questions. Question 1 asks to draw a face using OpenGL output primitives. Question 2 provides OpenGL code to display axes and asks for code snippets to draw and manipulate wireframe cubes at different positions and with different rotations, transformations, and projections. The goal is to recreate specific images showing cubes and axes from different viewpoints.

Uploaded by

frank musa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 1

Due Date: 23 June 2020


Question 1
• Make use of different types of output
primitives to draw a face.
• An example is shown below:

[20]
Question 2
Write an OpenGL program that is going to display some axis as shown below, and answer the questions that follow:

# include<GL/glut.h>

void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}

void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0,1.0, 0.0);

glBegin(GL_LINES);
glColor3f(1.0, 0.0, 0.0); //Red
glVertex3i(0, 2, 0);
glVertex3i(0, -2, 0);

glColor3f(0.0, 1.0, 0.0); //Green


glVertex3i(2, 0, 0);
glVertex3i(-2, 0, 0);

glColor3f(0.0, 0.0, 1.0); //Blue


glVertex3i(0, 0, 2);
glVertex3i(0, 0, -2);

glEnd();

glFlush();

void reshape(int w, int h)


{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv)


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize( 500, 500 ); /* A x A pixel screen window */
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]); /* window title */
init();
glutDisplayFunc(Display); /* tell OpenGL main loop what */
glutReshapeFunc(reshape);
//Initialize(); /* set attributes */
glutMainLoop(); /* pass control to the main loop */

}
Write code snippets for the relevant
function for each of the following cases:
a) Use a new Color to draw a wirecube whose center
is at (0,0,0) with a size of 1.0. [2]
b) Move this cube so that it is centered at (1,0,0)[2]
c) Draw a second cube and rotate it 450 around the
y-axis. [4]
d)i. Place this rotated cube directly above the first
cube. It should be centered at (1,1,0) [4]
ii. Also change the projection to orthographic
because perspective will make the cubes to look
awkward. [2]
Question 2 (Cont…)
To this end, your picture should be as
demonstrated below:

e) Rotate everrything so that you are looking down at the


top of the boxes and seeing the blue z-axis and not red
y-axis as shown below using
i. gluLookAt
ii. Modelling transformations [5]
Question 2 (Cont…)
f) Leave the x and y axes unchanged, but view
the top of the boxes like this: [2]

g) Rotate everything so that you can see all


the 3 axes along with the 2 cubes: [3]

You might also like