Below, my current C++ code for this assignment (see pdf attachement earlier) …please comment if you are willing to look at c code
thanks
bernie
ps, yes, I’ve pulled down the Gears demo and am getting into it. Thanks
#include
#include
#include <glut.h>
using namespace std;
class Point{
double x;
double y;
Point (double x=0, double y=0){this.x=x;this.y=y;}
//constructor connects x and y values of the calling object
//‘this’
};
class House{
private:
double w; //width
double h; // height
double p; //the peak
Point O; //House origin. bottom left corner of the shell of
//the house
public:
House(double w, double h, double p, Point origin); // constructor
//for a house
/* void draw_shell();
void draw_door();
void draw_chimney();
void draw_window();
*/
void draw_shell(){
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 1.0); .
glBegin (GL_LINES);
glVertex2i(O.x, O.y); //vertices of shell in terms of origin(O.x, O.y)
glVertex2i(O.x, O.y+h);
glVertex2i(O.x+w, O.y);
glVertex2i(O.x+(1/2)w, p);
glVertex2i(O.x+w, O.y+h);
glEnd ( );
glFlush ( );
}
void draw_door(){
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 1.0); .
glBegin (GL_LINES);
glVertex2i(O.x+(1/8)w, O.y);
glVeretex2i(O.x+(1/8)w, O.y+h);
glVertex2i(O.x+(1/4)w, O.y+h);
glVertex2i(O.x+(1/4)w, O.y);
glEnd ( );
glFlush ( );
}
void draw_window(){
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 1.0); .
glBegin (GL_LINES);
glVertex2i(O.x+(5/8)w, O.y+(1/2)h);
glVertex2i(O.x+(5/8)w, O.y+(3/4)h);
glVertex2i(O.x+(7/8)w, O.y+(3/4)h);
glVertex2i(O.x+(7/8)w, O.y+(1/2)h);
glEnd ( );
glFlush ( );
}
void draw_chimney(){
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 1.0); .
glBegin (GL_LINES);
glVertex2i(O.x+(1/8)w, O.y+((1/4)*(p-h)+h);
glVertex2i(O.x+(1/8)w, O.y+p);
glVertex2i(O.x+(3/16)w, O.y+p);
glVertex2i(O.x+(3/16)w, O.y+((3/8)*(p-h)+h);
glEnd ( );
glFlush ( );
}
void init(){
glClearColor (1.0, .0, .0, 0.6);
//glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 200.0);
}
void display_house(){
draw_shell();
draw_door();
draw_window();
draw_chimney();
}
void display(){
House h1(100, 150, 200, Point (0,0) );
House h2 (100, 200, 280, Point(150,0) );
House h3 (50, 70, 90, Point (0, 300) );
//some gl code
h1.display_house();
//maybe some more gl code
h2.display_house();
h3.display_house();
}
};
void main (int argc, char** argv)
{
Point origin(20,20);
House h4(2, 10, 15, origin);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (50, 100);
glutInitWindowSize (400, 300);
glutCreateWindow (“Bernie Project 1”);
//init ( ); //
glutDisplayFunc (display_house);
glutMainLoop ( );
}