/* Demo exhibiting the use of lighting on a stillframe scene */ #include #include #include #include "tw.h" #include //variables for bedside lamp location GLfloat xVal = 12; GLfloat yVal = 8; GLfloat zVal = 5; GLfloat light[4]={xVal,yVal,zVal,1}; /*bedside table lamp position*/ //variables for table lamp location //(22,10,10); GLfloat xVal1 = 22; GLfloat yVal1 = 8; GLfloat zVal1 = 10; GLfloat light1[4]={xVal1,yVal1,zVal1,1}; /*spotlight position*/ /* for texture mapping */ GLuint textureIDs[10]; GLfloat sgenparams1[] = {1,0,0,0}; GLfloat sgenparams2[] = {0,1,1,0}; //for table; higher numbers gets more dramatic spotlight effect GLfloat sgenparams3[] = {80,0,0,0}; GLfloat sgenparams4[] = {0,80,80,0}; //sets up lighting void lamp() { //GLfloat lightPosition [] = {xVal,yVal,zVal,1.0}; GLfloat ambient [] = {0.8,0.8,0.8,1}; GLfloat diffuse [] = {0.5,0.5,0.5,1}; GLfloat specular [] = {1,1,1,1}; glShadeModel(GL_SMOOTH); glLightfv(GL_LIGHT0, GL_POSITION, light); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); //table lamp GLfloat ambient1 [] = {1,0.5,0,1}; GLfloat diffuse1 [] = {1,0.5,0,1}; GLfloat specular1 [] = {0.8,0.8,0.8,1}; GLfloat direction [] = {0,-1,0}; GLfloat lightExponent = 0; GLfloat lightCutoff = 30; glLightfv(GL_LIGHT1, GL_POSITION, light1); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1); glLightfv(GL_LIGHT1, GL_SPECULAR, specular1); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction); glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, lightCutoff); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, lightExponent); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.1); glEnable(GL_LIGHT1); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glEnable(GL_LIGHTING); } //draws lamp from bedside table void drawLamp() { twTriple gray = {0.6, 0.6, 0.6}; twColor(gray,0.4,60); glPushMatrix(); glutSolidSphere(0.8,20,20); glTranslatef(0,0.9,0); glRotatef(-90,1,0,0); twTriple lightGray = {0.7, 0.7, 0.7}; twColor( lightGray,0.2,30); twCylinder(1.3,0.8,1.5,20,20); glPopMatrix(); } //draws lamp from big table void drawLamp2() { twTriple greenGray = { 0.5, 0.7, 0.5 }; twColor(greenGray,1,128); //light base glPushMatrix(); twSolidCylinder(0.5,0.8,0.8,20,20); glPopMatrix(); //bottom arm glPushMatrix(); glRotatef(155,0,0,1); twSolidCylinder(0.1,0.1,2,20,20); glPopMatrix(); //top arm glPushMatrix(); glTranslatef(0.8,1.8,0); glRotatef(90,0,0,1); twSolidCylinder(0.1,0.1,2,20,20); glPopMatrix(); //light head glPushMatrix(); glTranslatef(2.8,1.8,0); twSolidCylinder(0.1,0.5,0.5,20,20); glPopMatrix(); } //draws a leg of the table void drawLeg(GLdouble top, GLdouble base, GLdouble height) { // twColor(0.8,0.3,0.3,128); twTriple brown = {0.5, 0.1, 0}; twColor(brown,0.9,100); glBindTexture(GL_TEXTURE_2D, textureIDs[3]); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S,GL_OBJECT_PLANE,sgenparams3); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T,GL_OBJECT_PLANE,sgenparams4); glPushMatrix(); twSolidCylinder(top,base,height,20,20); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } void drawTable() { glPushMatrix(); glScalef(1.5,1.5,1.5); drawLeg(3.8,4,0.5); //actually not a leg (table top) //draw table top /* twTriple brown = {0.6, 0.4, 0}; twColor(brown,0.1,15); glBindTexture(GL_TEXTURE_2D, textureIDs[3]); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(-2.5,0.05,-2.4); glScalef(5.1,0.1,5.1); twDrawUnitSquare(70,70); glPopMatrix(); glDisable(GL_TEXTURE_2D);*/ glDisable(GL_LIGHT1); glPushMatrix(); glTranslatef(3*cos(M_PI/4.5),-0.01,-3*sin(M_PI/4.5)); drawLeg(0.4,0.4,3.5); glPopMatrix(); glPushMatrix(); glTranslatef(-3*cos(M_PI/4.5),-0.01,-3*sin(M_PI/4.5)); drawLeg(0.4,0.4,3.5); glPopMatrix(); //front left glPushMatrix(); glTranslatef(-3*cos(M_PI/4.5),-0.01,3*sin(M_PI/4.5)); drawLeg(0.4,0.4,3.5); glPopMatrix(); //front right glPushMatrix(); glTranslatef(3*cos(M_PI/4.5),-0.01,3*sin(M_PI/4.5)); drawLeg(0.4,0.4,3.5); glPopMatrix(); glPopMatrix(); //undoes scaling glTranslatef(-2,1,-1); glRotatef(-45,0,1,0); drawLamp2(); } //draws a post of dimensions x*y*z //post centered at origin in x,y,z directions void drawPost(GLdouble x, GLdouble y, GLdouble z) { twTriple gray = {0.7, 0.7, 0.7}; twColor(gray,0.8,100); glPushMatrix(); glRotatef(90,1,0,0); //necessary??? glScalef(x,y,z); glutSolidCube(1); glPopMatrix(); } void drawBedsideTable() { glBindTexture(GL_TEXTURE_2D, textureIDs[3]); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S,GL_OBJECT_PLANE,sgenparams1); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T,GL_OBJECT_PLANE,sgenparams2); glPushMatrix(); drawPost(5,5,2); //table top glTranslatef(0,0,2.5); twTriple darkGray = {0.5, 0.5, 0.5}; twColor( darkGray,0.8,100); glutSolidSphere(0.3,15,15); //knob glPopMatrix(); glPushMatrix(); glTranslatef(-2,-2,2); //front left leg drawPost(0.5,0.5,5); glPopMatrix(); glPushMatrix(); glTranslatef(2,-2,2); //front right leg drawPost(0.5,0.5,5); glPopMatrix(); glPushMatrix(); glTranslatef(2,-2,-2); //back right leg drawPost(0.5,0.5,5); glPopMatrix(); glPushMatrix(); glTranslatef(-2,-2,-2); //back left leg drawPost(0.5,0.5,5); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); //draw lamp glPushMatrix(); glTranslatef(0,1.8,0); //moves lamp up to level of table drawLamp(); glPopMatrix(); } //draws a bed centered in the x,z directions; draws from lowest y up void drawBed() { glBindTexture(GL_TEXTURE_2D, textureIDs[3]); twTriple lightGray = {0.7, 0.7, 0.7}; twColor( lightGray, 0.8, 100); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S,GL_OBJECT_PLANE,sgenparams1); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T,GL_OBJECT_PLANE,sgenparams2); glPushMatrix(); glScalef(2,2,2); //back left glPushMatrix(); glTranslatef(-1.5,2.5,-2.5); drawPost(0.4,0.4,5); glPopMatrix(); //back right glPushMatrix(); glTranslatef(1.5,2.5,-2.5); drawPost(0.4,0.4,5); glPopMatrix(); //front right glPushMatrix(); glTranslatef(1.5,1.5,2.5); drawPost(0.4,0.4,3); glPopMatrix(); //front left glPushMatrix(); glTranslatef(-1.5,1.5,2.5); drawPost(0.4,0.4,3); glPopMatrix(); //back beam glPushMatrix(); glTranslatef(0,1.5,-2.5); glRotatef(90,0,0,1); drawPost(0.3,0.3,3); glPopMatrix(); //front beam glPushMatrix(); glTranslatef(0,1.5,2.5); glRotatef(90,0,0,1); drawPost(0.3,0.3,3); glPopMatrix(); //left beam glPushMatrix(); glTranslatef(-1.5,1.5,0); glRotatef(90,0,1,0); glRotatef(90,0,0,1); drawPost(0.3,0.3,5); glPopMatrix(); //right beam glPushMatrix(); glTranslatef(1.5,1.5,0); glRotatef(90,0,1,0); glRotatef(90,0,0,1); drawPost(0.3,0.3,5); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); //mattress twTriple periwinkle = {0.8, 0.8, 1.0}; twColor(periwinkle, 0.2, 30); glBindTexture(GL_TEXTURE_2D, textureIDs[2]); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S,GL_OBJECT_PLANE,sgenparams1); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T,GL_OBJECT_PLANE,sgenparams2); glPushMatrix(); glTranslatef(0,2,0); glScalef(3,1,5); glutSolidCube(1); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); //draw bear on bed glPushMatrix(); glTranslatef(0,3.6,-2); glRotatef(-40,1,0,0); glScalef(3,3,3); twTeddyBear(); glPopMatrix(); glPopMatrix(); } void drawFrame(GLfloat openAngle) { glPushMatrix(); glRotatef(openAngle,0,1,0); glPushMatrix(); glRotatef(90,1,0,0); drawPost(0.5,15,0.5); //left glPushMatrix(); glTranslatef(6,0,0); drawPost(0.5,15,0.5); //middle glTranslatef(6,0,0); drawPost(0.5,15,0.5); //right glPopMatrix(); glPopMatrix(); glPushMatrix(); glRotatef(90,0,1,0); glTranslatef(0,-7.5,6); drawPost(0.5,13,0.5); glTranslatef(0,7.5,0); drawPost(0.5,13,0.5); glTranslatef(0,7.5,0); drawPost(0.5,13,0.5); glPopMatrix(); glPopMatrix(); } void drawWindow() { //sky twTriple white = {1, 1, 1}; twColor(white,1,100); glBindTexture(GL_TEXTURE_2D, textureIDs[4]); glEnable(GL_TEXTURE_2D); glBegin(GL_POLYGON); glTexCoord2f(1,1); glVertex3f(-4,9,-6.5); glTexCoord2f(0,1); glVertex3f(35,9,-6.5); glTexCoord2f(0,0); glVertex3f(35,32,-6.5); glTexCoord2f(1,0); glVertex3f(-4,32,-6.5); glEnd(); glDisable(GL_TEXTURE_2D); twTriple gray = {0.7, 0.7, 0.7}; twColor(gray, 0.8, 100); glBindTexture(GL_TEXTURE_2D, textureIDs[6]); glEnable(GL_TEXTURE_2D); //window frames glPushMatrix(); glTranslatef(3,17.5,0); drawFrame(30); glTranslatef(24,0,0); glRotatef(180,0,1,0); drawFrame(-20); glPopMatrix(); //sill twTriple lightGray = {0.8, 0.8, 0.8}; twColor(lightGray,0.8, 100); glPushMatrix(); glTranslatef(15,10,0); glRotatef(90,0,1,0); drawPost(0.8,25,0.8); glTranslatef(0,15,0); drawPost(0.8,25,0.8); glPopMatrix(); glDisable(GL_TEXTURE_2D); } void drawSides() { //ground glBindTexture(GL_TEXTURE_2D, textureIDs[0]); twTriple darkGray = {0.5, 0.5, 0.5}; twColor(darkGray,0.5, 128); glEnable(GL_TEXTURE_2D); glPushMatrix(); glScalef(30,30,30); // glNormal3f(0,1,0); twDrawUnitSquare(15,15); glPopMatrix(); glDisable(GL_TEXTURE_2D); //carpet twTriple terraCotta = {0.9, 0.6, 0.6}; twColor(terraCotta, 0, 10); glBindTexture(GL_TEXTURE_2D, textureIDs[7]); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(8,0.2,5); glScalef(10,1.2,10); twDrawUnitSquare(15,15); glPopMatrix(); glDisable(GL_TEXTURE_2D); twTriple lightGray = { 0.8, 0.8, 0.8 }; twColor(lightGray,0.8,50); glBindTexture(GL_TEXTURE_2D, textureIDs[5]); glEnable(GL_TEXTURE_2D); //left wall glPushMatrix(); //to get the normals right it's important to have the pos. y axis //pointing inside the room. glRotatef(270,0,0,1); glTranslatef(-30,0,0); //glNormal3f(0,-1,0); //NORMAL glScalef(30,30,30); twDrawUnitSquare(10,10); glPopMatrix(); //right wall glPushMatrix(); glTranslatef(30,0,0); glRotatef(90,0,0,1); glScalef(30,30,30); twDrawUnitSquare(10,10); glPopMatrix(); //back wall glPushMatrix(); glRotatef(90,1,0,0); glPushMatrix(); glTranslatef(0,0,-30); glScalef(3,30,30); twDrawUnitSquare(1,6); //left strip glPopMatrix(); glPushMatrix(); glTranslatef(27,0,-30); glScalef(3,30,30); twDrawUnitSquare(1,6); //right strip glPopMatrix(); glPushMatrix(); glTranslatef(3,0,-10); glScalef(24,1,10); //lower strip twDrawUnitSquare(8,2); glPopMatrix(); glPushMatrix(); glTranslatef(3,0,-30); glScalef(24,1,5); twDrawUnitSquare(8,1); //top strip glPopMatrix(); glPopMatrix(); glDisable(GL_TEXTURE_2D); //draw poster on left wall twTriple white = {1, 1, 1}; twColor(white, 0.2, 30); glBindTexture(GL_TEXTURE_2D, textureIDs[8]); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(0.2,18,12); glRotatef(90,0,0,1); glRotatef(180,0,1,0); glScalef(7,7,5); twDrawUnitSquare(1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); //draw vent on right wall twColor(white,0,0); glBindTexture(GL_TEXTURE_2D, textureIDs[9]); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(15,3,0.2); glRotatef(90,1,0,0); glScalef(3,3,2); twDrawUnitSquare(1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); //ceiling twTriple dark = {0.3, 0.3, 0.3}; twColor(dark, 0.4, 50); glPushMatrix(); glTranslatef(0,30,30); glRotatef(180,1,0,0); glScalef(30,30,30); twDrawUnitSquare(10,5); glPopMatrix(); } void drawToy() { glPushMatrix(); glScalef(1.7,0.3,1.7); twTriple purple = { 0.5, 0, 0.5 }; twColor(purple,0.8,100); glutSolidCube(1); //base glPopMatrix(); glPushMatrix(); glTranslatef(0,2,0); twTriple lightGray = {0.8, 0.8, 0.8}; twColor(lightGray,0.4,50); twSolidCylinder(0.2,0.3,2,20,20); //center shaft glPopMatrix(); glPushMatrix(); glRotatef(-90,1,0,0); //so toruses are facing right direction glScalef(1,1,0.7); glPushMatrix(); glTranslatef(0,0,0.5); twTriple blue = {0, 0, 0.8}; twColor(blue, 0.8, 100); glutSolidTorus(0.35,0.50,20,20); twTriple darkGreen = {0, 0.5, 0}; twColor(darkGreen, 0.8, 100); glTranslatef(0,0,0.6); glutSolidTorus(0.30,0.45,20,20); twTriple yellow = {0.8, 0.8, 0}; twColor(yellow, 0.8, 100); glTranslatef(0,0,0.5); glutSolidTorus(0.25,0.40,20,20); glPopMatrix(); glPushMatrix(); twTriple orange = {1, 0.3, 0}; twColor(orange,0.8,100); glTranslatef(1.8,1,0.1); glutSolidTorus(0.20,0.35,20,20); twTriple red = {0.8, 0, 0}; twColor(red, 0.8, 100); //red glTranslatef(1,-2,0); glutSolidTorus(0.15,0.30,20,20); glPopMatrix(); glPopMatrix(); } void drawBlock(int color) { glPushMatrix(); twColorName(color); glutSolidCube(0.5); glPopMatrix(); } void drawBlocks() { glPushMatrix(); glTranslatef(-1,0.3,1); drawBlock(TW_DARK_BLUE); glRotatef(30,0,1,0); glTranslatef(0.1,0.5,0); drawBlock(TW_TEAL); glTranslatef(2,-0.5,2); drawBlock(TW_YELLOW); glPopMatrix(); glPushMatrix(); glTranslatef(-3,0.3,1.5); glRotatef(40,0,1,0); drawBlock(TW_MAROON); glTranslatef(0.5,0,-1.5); glRotatef(-45,0,1,0); drawBlock(TW_PURPLE); glPopMatrix(); } /*---------------------------------------------------- MOBILE */ //bar lengths GLfloat bLength1=35; // length of first bar from top GLfloat bLength2=20; // length of second bar GLfloat bLength3=15; // length of third bar GLfloat bLength4=8; // length of fourth bar //string lengths GLfloat sLength1=10; // length of first string from top GLfloat sLength2=7; // length of second string GLfloat sLength3=15; // length of third string GLfloat sLength4=15; // length of fourth string //draws a "bar" of uniform height and width; takes length as a parameter void drawBar(GLfloat length) { glPushMatrix(); twColor(0.5,0.5,0.5,0); //set color of bar glScalef(length,1,1); glutSolidCube(1); glPopMatrix(); } //draws a red string; takes length as parameter void drawString(GLfloat length) { glPushMatrix(); twColor(1,0,0,0); //glLineWidth(2); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,-length,0); glEnd(); glPopMatrix(); } //resizes twDrawBarn to appropriate dimension void drawBarn() { glPushMatrix(); glRotatef(75,0,1,0); glTranslatef(-2,-6,3); //translate so barn is centered at end of string glScalef(4,6,6); twTriple pink = {1, 0.7, 0.7}; twTriple red = {1, 0, 0}; twTriple black = {0, 0, 0}; twSolidBarn(pink,red,black); glPopMatrix(); } void drawRightSide() { glPushMatrix(); glTranslatef((bLength1)/2,0,0); //translate to right end of first bar drawString(sLength1); //draw top right string glTranslatef(0,-sLength1,0); //translate to bottom of first string glRotatef(10,0,1,0); drawBar(bLength2); glPushMatrix(); //stores location after second bar is drawn glTranslatef((bLength2)/2,0,0); //translate to right end of second bar drawString(sLength2); glTranslatef(0,-sLength2,0); //translate to bottom of second string glRotatef(-30,0,1,0); drawBar(bLength3); glPushMatrix(); //stores location after third bar is drawn glTranslatef((bLength3)/2,0,0); //translate to right end of third bar drawString(sLength3); glTranslatef(0,-sLength3,0); //translate to bottom of third string glRotatef(86,0,1,0); drawBar(bLength4); glPushMatrix(); //stores location after fourth bar is drawn glTranslatef((bLength4)/2,0,0); //translate to right end of fourth bar drawString(sLength4); glTranslatef(0,-sLength4,0); //translate to bottom of fourth string twColor(0.2,0.2,1,100); //set color for teapot glRotatef(15,0,1,0); glutSolidTeapot(1.5); /* TEAPOT */ glPopMatrix(); //return to middle of fourth bar glTranslatef((-bLength4)/2,0,0); drawString(sLength4); glTranslatef(0,-sLength4,0); twColor(0,1,1,0); //set color for octahedron glScalef(2,2,2); glRotatef(5,0,1,0); glutSolidOctahedron(); /* OCTADRON */ glPopMatrix(); //return to middle of third bar glTranslatef((-bLength3)/2,0,0); drawString(sLength3); glTranslatef(0,-sLength3,0); twColor(0.5,0.1,0.1,100); glScalef(10,10,10); glRotatef(-4,0,1,0); twTeddyBear(); /* BEAR */ glPopMatrix(); // return to middle of second bar glTranslatef((-bLength2)/2,0,0); drawString(sLength2); glTranslatef(0,-sLength2,0); twColor(0.8,0.8,0,0); glTranslatef(0,-3,0); //translate down the size of the torus's outer radius glRotatef(55,0,1,0); glutSolidTorus(1,3,10,10); /* TORUS */ glPopMatrix(); } void drawLeftSide() { glPushMatrix(); glTranslatef((-bLength1)/2,0,0); //translate to left end of first bar drawString(sLength1); //draw top left string glTranslatef(0,-sLength1,0); //translate to bottom of first string glRotatef(-15,0,1,0); drawBar(bLength2); glPushMatrix(); //stores location after second bar is drawn glTranslatef((-bLength2)/2,0,0); //translate to left end of second bar drawString(sLength2); glTranslatef(0,-sLength2,0); //translate to bottom of second string glRotatef(13,0,1,0); drawBar(bLength3); glPushMatrix(); //stores location after third bar is drawn glTranslatef((-bLength3)/2,0,0); //translate to left end of third bar drawString(sLength3); glTranslatef(0,-sLength3,0); //translate to bottom of third string drawBar(bLength4); glPushMatrix(); //stores location after fourth bar is drawn glTranslatef((-bLength4)/2,0,0); //translate to left end of fourth bar drawString(sLength4); glTranslatef(0,-sLength4,0); //translate to bottom of fourth string twColor(0.2,0.8,0.2,100); //set color for icosahedron glScalef(2,2,2); glRotatef(-4,0,1,0); glutSolidIcosahedron(); /* ICOSAHEDRON */ glPopMatrix(); //return to middle of fourth bar glTranslatef((bLength4)/2,0,0); //translate to right end of fourth bar drawString(sLength4); glTranslatef(0,-sLength4,0); twColor(0.5,0,0.5,100); //set color for tetrahedron glScalef(2,2,2); glRotatef(85,0,1,0); glutSolidTetrahedron(); /* TETRAHEDRON */ glPopMatrix(); //return to middle of third bar glTranslatef((bLength3)/2,0,0); //translate to right end of third bar drawString(sLength3); glTranslatef(0,-sLength3,0); twColor(0,0.5,0.5,0); glTranslatef(0,-2,0); //translate down the size of the radius of the sphere glRotatef(-55,0,1,0); glutSolidSphere(3,20,20); /* SPHERE */ glPopMatrix(); // return to middle of second bar glTranslatef((bLength2)/2,0,0); //translate to right end of second bar drawString(sLength2); glTranslatef(0,-sLength2,0); glRotatef(-30,0,1,0); drawBarn(); /* BARN */ glPopMatrix(); } void drawMobile(void) { glPushMatrix(); glScalef(0.2,0.2,0.2); drawString(10); //top middle string glTranslatef(0,-10,0); drawBar(bLength1); //draw top bar drawRightSide(); drawLeftSide(); glPopMatrix(); } void display(void) { glClearColor(1,1,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); twCamera(); lamp(); //draw table and objects on table before everything //else so we do not get spotlight on tiled floor glPushMatrix(); glTranslatef(22,5.5,10); drawTable(); glPopMatrix(); //draw ceiling, ground, and walls drawSides(); //draw window and sky drawWindow(); //draw bed and teddy bear glPushMatrix(); glTranslatef(5,0.2,10); drawBed(); glPopMatrix(); //draw bedside table glPushMatrix(); glTranslatef(12,4.5,5); drawBedsideTable(); glPopMatrix(); //draw mobile glPushMatrix(); glTranslatef(10,30,6); drawMobile(); glPopMatrix(); //draw ring toy glPushMatrix(); glTranslatef(20,0.2,15); drawToy(); glPopMatrix(); //draw blocks glPushMatrix(); glTranslatef(7,0,15); drawBlocks(); glPopMatrix(); glFlush(); glutSwapBuffers(); } /* Loads the textures */ void loadTextures() { glGenTextures(10,textureIDs); /* make sure you generate as many textures as you load! */ twLoadTexture(textureIDs[0], "woodTile2.ppm"); /* for ground */ //loadTexture(textureIDs[1], "redWood.ppm"); /* for bed */ twLoadTexture(textureIDs[2], "blueCloth.ppm"); /* for bed */ twLoadTexture(textureIDs[3], "redWood.ppm"); /* for table */ twLoadTexture(textureIDs[4], "twilightSky.ppm"); /* for window */ twLoadTexture(textureIDs[5], "grayFlowerWallpaper.ppm"); /* for walls */ twLoadTexture(textureIDs[6], "wood.ppm"); /* for window frame */ twLoadTexture(textureIDs[7], "pinkCarpet.ppm"); /* for carpet */ twLoadTexture(textureIDs[8], "nemoPoster.ppm"); /* for left wall */ twLoadTexture(textureIDs[9], "vent.ppm"); /* for right wall */ } int main(int argc, char **argv) { /* need both double buffering and z buffer */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(650, 650); twBoundingBox(0,30,0,20,0,8); glutCreateWindow("room scene"); glutDisplayFunc(display); loadTextures(); glEnable(GL_NORMALIZE); twMainInit(); //twLighting(); glutMainLoop(); return 0; } /*-------------------------------------------------------- SHADOW STUFF */ /*void drawBedAndShadow() { glBindTexture(GL_TEXTURE_2D, textureIDs[3]); twColor(0.7,0.7,0.7,100); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S,GL_OBJECT_PLANE,sgenparams); GLfloat m[16]; int i; for(i=0;i<16;i++) m[i]=0.0; m[0]=m[5]=m[10]=1.0; //m[7]=1.0/light[1]; m[7] = -1; //draw real bed //drawBed(); glPushMatrix(); glTranslatef(0,10,0); glutSolidSphere(1,30,30); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(1,2,0); glMultMatrixf(m); // flattens out the shadow glTranslatef(-1,-2,0); glDisable(GL_LIGHTING); glColor3f(0.8,0.8,0.8); //color of shadow //drawBed(); glutSolidSphere(1,30,30); glEnable(GL_LIGHTING); glPopMatrix(); glPopMatrix(); }*/ /* void drawLampAndShadow() { GLfloat m[16]; int i,j; for(i=0;i<16;i++) m[i]=0.0; m[0]=m[5]=m[10]=1.0; m[7]=-1.0/light[1]; drawLamp(); glPushMatrix(); //glTranslatef(10,light[1]-5,light[2]); glTranslatef(0,1.5,0); /*LIGHT POSITION*/ /* twColor(1,1,0,70); glPushMatrix(); glutSolidSphere(0.5,20,20); glPopMatrix(); glMultMatrixf(m); // flattens out the shadow //glTranslatef(-light[0]+5,light[1]+5,-light[2]); glTranslatef(0,-1.5,0); //glTranslatef(0,8,0); glDisable(GL_LIGHTING); glColor3f(0.8,0.8,0.8); //color of shadow glTranslatef(0,-5,0); drawLamp(); glEnable(GL_LIGHTING); glPopMatrix(); } */