Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is the code from The zipped file assignment1.zip #include ../shared/gltools.h // OpenGL toolkit GLfloat rot; void drawGrass(); void drawRoof(); void drawWireSphere(float inc); void drawCube();

image text in transcribed

this is the code from The zipped file assignment1.zip

#include "../shared/gltools.h" // OpenGL toolkit

GLfloat rot;

void drawGrass();

void drawRoof();

void drawWireSphere(float inc);

void drawCube();

///////////////////////////////////////////////////////////

// Called to draw scene

void RenderScene(void)

{

// Reset Model view matrix stack

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

rot+=1; //rotate 1 degree per frame

// Clear the window with current clearing color

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//view transformation

glTranslatef(0,-6,-80);

//draw grass

drawGrass();

//draw house

glTranslatef(-20, 5, 0);

glRotatef(45, 0, 1, 0);

drawCube();

glTranslatef(0, 5, 0);

drawRoof();

glTranslatef(0, -5, 0);

glRotatef(-45, 0, 1, 0);

glTranslatef(20, -5, 0);

//draw sun

glColor3f(1, 1, 0);

//rotate around the z-axis

glRotatef(rot, 0, 0, 1);

//init the sun 100 units to the right, 100 units back

glTranslatef(100, 0, -100);

glutSolidSphere(10, 20, 10);

glTranslatef(-100, 0, 100);

glRotatef(-rot, 0, 0, 1);

// Flush drawing commands

glutSwapBuffers();

}

void drawWireSphere(float inc)

{

glScalef(10, 10, 10);

//wire frame

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

glBegin(GL_QUADS);

const float pi = 3.14159;

for (float latitude = -90; latitude

float r = cos(latitude*pi / 180.0);

float rAbove = cos((latitude + inc)*pi / 180.0);

float y = sin(latitude*pi / 180.0);

float yAbove = sin((latitude + inc)*pi / 180.0);

for (float longitude = -180; longitude

float x = cos(longitude*pi / 180.0)*r;

float x2 = cos((longitude + inc)*pi / 180.0)*r;

float x3 = cos((longitude + inc)*pi / 180.0)*rAbove;

float x4 = cos(longitude*pi / 180.0)*rAbove;

float z = -sin(longitude*pi / 180.0)*r;

float z2 = -sin((longitude + inc)*pi / 180.0)*r;

float z3 = -sin((longitude + inc)*pi / 180.0)*rAbove;

float z4 = -sin(longitude*pi / 180.0)*rAbove;

glVertex3f(x, y, z);

glVertex3f(x2, y, z2);

glVertex3f(x3, yAbove, z3);

glVertex3f(x4, yAbove, z4);

}

}

glEnd();

glScalef(.1, .1, .1);

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

}

void drawCube()

{

//cube

glBegin(GL_QUADS);

glColor3f(1, 1, 0);

glVertex3f(-5.0f, 5.0f, 5.0f);

glVertex3f(-5.0f, -5.0f, 5.0f);

glVertex3f(5.0f, -5.0f, 5.0f);

glVertex3f(5.0f, 5.0f, 5.0f);

glColor3f(1, 0, 1);

glVertex3f(-5.0f, 5.0f, -5.0f);

glVertex3f(5.0f, 5.0f, -5.0f);

glVertex3f(5.0f, -5.0f, -5.0f);

glVertex3f(-5.0f, -5.0f, -5.0f);

glColor3f(1, 0, 0);

glVertex3f(-5.0f, 5.0f, 5.0f);

glVertex3f(5.0f, 5.0f, 5.0f);

glVertex3f(5.0f, 5.0f, -5.0f);

glVertex3f(-5.0f, 5.0f, -5.0f);

glColor3f(0, 1, 0);

glVertex3f(-5.0f, -5.0f, 5.0f);

glVertex3f(-5.0f, -5.0f, -5.0f);

glVertex3f(5.0f, -5.0f, -5.0f);

glVertex3f(5.0f, -5.0f, 5.0f);

glColor3f(0, 0, 1);

glVertex3f(5.0f, 5.0f, 5.0f);

glVertex3f(5.0f, -5.0f, 5.0f);

glVertex3f(5.0f, -5.0f, -5.0f);

glVertex3f(5.0f, 5.0f, -5.0f);

glColor3f(0, 1, 1);

glVertex3f(-5.0f, 5.0f, 5.0f);

glVertex3f(-5.0f, 5.0f, -5.0f);

glVertex3f(-5.0f, -5.0f, -5.0f);

glVertex3f(-5.0f, -5.0f, 5.0f);

glEnd();

}

void drawRoof()

{

glColor3f(1, 1, 1);

glBegin(GL_TRIANGLES);

glVertex3f(-5, 0, 5);

glVertex3f(5, 0, 5);

glVertex3f(0, 5, 5);

glVertex3f(-5, 0, -5);

glVertex3f(0, 5, -5);

glVertex3f(5, 0, -5);

glEnd();

glColor3f(1, 0, 0);

glBegin(GL_QUADS);

glVertex3f(5, 0, 5);

glVertex3f(5, 0, -5);

glVertex3f(0, 5, -5);

glVertex3f(0, 5, 5);

glVertex3f(-5, 0, 5);

glVertex3f(0, 5, 5);

glVertex3f(0, 5, -5);

glVertex3f(-5, 0, -5);

glEnd();

}

void drawGrass()

{

glColor3f(0, 1, 0);

glBegin(GL_QUADS);

glVertex3f(-100, 0, 100);

glVertex3f(100, 0, 100);

glVertex3f(100, 0, -100);

glVertex3f(-100, 0, -100);

glEnd();

glColor3f(0.5, 0.5, 0.5);

glBegin(GL_QUADS);

glVertex3f(-10, 0.01, 100);

glVertex3f(10, 0.01, 100);

glVertex3f(10, 0.01, -100);

glVertex3f(-10, 0.01, -100);

glEnd();

}

void TimerFunction(int value)

{

// Redraw the scene with new coordinates

glutPostRedisplay();

glutTimerFunc(16,TimerFunction, 1);

}

///////////////////////////////////////////////////////////

// Setup the rendering context

void SetupRC(void)

{

// White background

glClearColor(0.8f, 0.9f, 1.f, 1.0f );

//front face is ccw

glFrontFace(GL_CCW);

//culling turned on (off by default)

glEnable(GL_CULL_FACE);

//depth test turned on (on be default)

glEnable(GL_DEPTH_TEST);

}

void ChangeSize(int w, int h)

{

//GLfloat nRange = 100.0f;

// Prevent a divide by zero

if(h == 0)

h = 1;

// Set Viewport to window dimensions

glViewport(0, 0, w, h);

// Reset projection matrix stack

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

GLfloat fAspect;

fAspect = (GLfloat)w / (GLfloat)h;

//frustum that is 45 degrees fovy, aspect ratio of w/h, 1 unit away from the camera, and will clip anything beyond 1000 units

gluPerspective(45,fAspect,0.1,200);

// Reset Model view matrix stack

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

}

///////////////////////////////////////////////////////////

// Main program entry point

int main(int argc, char* argv[])

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(500,500);

glutCreateWindow("Assignment 1");

glutReshapeFunc(ChangeSize);

glutDisplayFunc(RenderScene);

glutTimerFunc(33, TimerFunction, 1);

SetupRC();

glutMainLoop();

return 0;

}

In this assignment, you are to create a simple OpenGL 3D scene of your choosing such as a house, car, etc. Use The zipped file assignmentl.zip contains a Visual Studio 2017 C++ solution to get you started, including a skeleton file named assignmentl.cpp where all your code should go. It includes a grass plain, a house, a road, and sphere to represent the sun. This is simply an example, so none of these should be in your solution besides perhaps the plain (but use a different color). In this assignment, you are to create a simple OpenGL 3D scene of your choosing such as a house, car, etc. Use The zipped file assignmentl.zip contains a Visual Studio 2017 C++ solution to get you started, including a skeleton file named assignmentl.cpp where all your code should go. It includes a grass plain, a house, a road, and sphere to represent the sun. This is simply an example, so none of these should be in your solution besides perhaps the plain (but use a different color)

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

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

Can PERT charts have more depth than the WBS?

Answered: 1 week ago

Question

10. What is a bus cycle?

Answered: 1 week ago

Question

plan and structure your literature review;

Answered: 1 week ago

Question

establish an effective note-taking and recording system;

Answered: 1 week ago

Question

identify what you need to read and where to find it;

Answered: 1 week ago