Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a 3D drawing using OpenGL and C or C++ for the following code for a 3D house: #include #include using namespace std; float ORG[3]

Create a 3D drawing using OpenGL and C or C++ for the following code for a 3D house:

#include #include

using namespace std;

float ORG[3] = {0,0,0}; float XP[3] = {10,0,0}, XN[3] = {-10,0,0}, YP[3] = {0,10,0}, YN[3] = {0,-10,0}, ZP[3] = {0, 0, 10}, ZN[3] = {0, 0, -10};

int x_rotation, y_rotation, z_rotation;

void drawHouse(void);

void displayMe(void) { glPushMatrix();

glRotatef((GLfloat) x_rotation, 1, 0, 0); glRotatef((GLfloat) y_rotation, 0, 1, 0); glRotatef((GLfloat) z_rotation, 0, 0, 1);

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_LINES); glColor3f(1,0,0); //Red x-axis glVertex3fv(XN); glVertex3fv(XP);

glColor3f(0,1,0); //Green y-axis glVertex3fv(YN); glVertex3fv(YP);

glColor3f(0,0,1); //Blue z-axis glVertex3fv(ZN); glVertex3fv(ZP);

glEnd();

drawHouse(); glPopMatrix(); glFlush(); }

void drawHouse(){ glBegin(GL_QUADS);//front wall glColor3f(0, 1, 0); glVertex3f(0.6,-0.4, -0.4); //bottom right glVertex3f(0.6, 0.4, -0.4); //top right glVertex3f(-0.6,0.4, -0.4); //top left glVertex3f(-0.6, -0.4, -0.4); //bottom left glEnd();

glBegin(GL_QUADS);//back wall glColor3f(1, 0, 1); glVertex3f(0.6,-0.4, 0.4); //bottom right glVertex3f(0.6, 0.4, 0.4); //top right glVertex3f(-0.6,0.4, 0.4); //top left glVertex3f(-0.6, -0.4, 0.4); //bottom left glEnd();

glBegin(GL_QUADS);//back window glColor3f(0, 0, 0); glVertex3f(0.4,-0.2, 0.4); //bottom right glVertex3f(0.4, 0.2, 0.4); //top right glVertex3f(0.1,0.2, 0.4); //top left glVertex3f(0.1, -0.2, 0.4); //bottom left glEnd();

glBegin(GL_QUADS); glColor3f(0, 0, 1);//side1 glVertex3f(-0.6, -0.4, -0.4); //bottom right glVertex3f(-0.6,0.4, -0.4); //top right glVertex3f(-0.6,0.4, 0.4); //top left glVertex3f(-0.6, -0.4, 0.4); //bottom left glEnd();

glBegin(GL_QUADS);//side2 glColor3f(0, 0, 1); glVertex3f(0.6,-0.4, 0.4); //bottom right glVertex3f(0.6, 0.4, 0.4); //top right glVertex3f(0.6, 0.4, -0.4); //top left glVertex3f(0.6,-0.4, -0.4); //bottom left glEnd();

glBegin(GL_TRIANGLES);//roof back glColor3f(1, 0, 0); glVertex3f(0.6, 0.4, -0.4); //bottom right glVertex3f(0.0, 0.7, 0.0); //top glVertex3f(-0.6,0.4, -0.4); //bottom left glEnd();

glBegin(GL_TRIANGLES);//roof front glColor3f(1, 0, 0); glVertex3f(0.6, 0.4, 0.4); //bottom right glVertex3f(0.0, 0.7, 0.0); //top glVertex3f(-0.6,0.4, 0.4); //bottom left glEnd();

glBegin(GL_TRIANGLES);//roof side1 glColor3f(1, 0, 0); glVertex3f(-0.6,0.4, 0.4); //bottom right glVertex3f(0.0, 0.7, 0.0); //top glVertex3f(-0.6,0.4, -0.4); //bottom left glEnd();

glBegin(GL_TRIANGLES);//roof side2 glColor3f(1, 0, 0); glVertex3f(0.6, 0.4, -0.4); //bottom right glVertex3f(0.0, 0.7, 0.0); //top glVertex3f(0.6, 0.4, 0.4); //bottom left glEnd();

glBegin(GL_POLYGON);//front window glColor3f(1, 1, 1); glVertex3f(0.4,-0.2, -0.4); //bottom right glVertex3f(0.4, 0.2, -0.4); //top right glVertex3f(0.1,0.2, -0.4); //top left glVertex3f(0.1, -0.2, -0.4); //bottom left glEnd();

glBegin(GL_POLYGON);//front door glColor3f(0, 0, 0); glVertex3f(-0.4,-0.4, -0.4); //bottom right glVertex3f(-0.4, 0.0, -0.4); //top right glVertex3f(-0.1,0.0, -0.4); //top left glVertex3f(-0.1, -0.4, -0.4); //bottom left glEnd();

glBegin(GL_QUADS); glColor3f(1, 1, 1);//bottom glVertex3f(0.6,-0.4, -0.4); //bottom right glVertex3f(0.6,-0.4, 0.4); //top right glVertex3f(-0.6, -0.4, 0.4); //top left glVertex3f(-0.6, -0.4, -0.4); //bottom left glEnd();

}

void keyboard(unsigned char key, int x, int y){

switch(key){ case 'x': x_rotation++; glutPostRedisplay(); break;

case 'y': y_rotation++; glutPostRedisplay(); break;

case 'z': z_rotation++; glutPostRedisplay(); break;

} } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(800, 800); glutInitWindowPosition(100, 100); glutCreateWindow("Week 3"); glutDisplayFunc(displayMe); glutKeyboardFunc(keyboard); glutMainLoop();

return 0; }

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago