In 2009 I took an intro course to openGL. For some time I had been wanting to get working with graphics using C/C++ but never had a library to work with. My former experience with graphics was using Java in high school (which reminds me, I MUST find some of those projects, they were awesome). [Update 3/3/2012. You can now download and see this project first-hand! See details at end of post As of 2013, these files have expired due to lack of interest]
Anyways, I digress. For my final project, I had to choose a subject to render in 3D. Some students choose to render little boxcars, others did some really cool things with lights and spheres. I chose to pay homage to the man who gave us The Simpson’s – Matt Groening – by rendering the iconic living room and couch we see every episode.
Some notes about the project:
Every object is rendered using openGL primitives minus the lampshade on the right. I built that by hand.
The project took nearly 40 hours to complete.
The user can change a couple settings about the scene:
1. The ‘r’ key makes the telephone start ringing. ‘r’ again makes it stop
2. You can change the ball material from red rubber to silver to emerald
3. You can change the painting between the iconic sailboat, a picture of Kramer from Seinfeld, or a cool picture of an asteroid impacting a planet.
4. You can modify the ball to bounce lower or higher than normal, causing a faster or slower movement.
5. You can freely rotate the scene in all axes, and using the wasd keys moves the entire scene left, right, towards the camera, and away from the camera.
——
Now, I realize there’s no bouncing ball in the actual Simpson’s living room. A requirement for the project was to do something with shadow rendering (may sound easy to you openGL vets, but this is tough for newbies).
Overall, I’m very proud with how this turned out. Of course, my artist friend later informed me he could draw something like this using his digital art tools in about 30 minutes or less. Easy for him to say. He gets instant feedback while he’s working on the scene. For me, it looked something like this:
Here’s a few more pics of the rendered scene:
Downloading and running the project:
- Download the files from here (Update: Link is dead — the file expired due to lack of interest).
- Unzip the folder, and there should be another folder named ‘debug’
- Inside of ‘debug’ is a file named ‘CPS 460 3D Project’, double-click this to run the file
- To Interact with the scene (case-insensitive):
- Right-Click to set properties like painting, ball material, and ball bounce height
- Left-Click and drag to rotate the scene
- Press ‘W’ to zoom in
- Press ‘S’ to zoom out
- Press ‘A’ to rotate clockwise about Z-axis
- Press ‘D’ to rotate counter-clockwise about Z-axis
- Press ‘R’ to start/stop the telephone ringing
Enjoy!
[…] you’ve read any of my older posts, you may have stumbled across my rendition of the Simpson’s living room in 3D. Building this scene took at least as long as that one. […]
hey can you like help me figure out drawing the sofa…i am doing stuff in OpenGL, where i drew a castle and when I go inside the building , i want to add a sofa like shown in picture…thx
Hey Sam,
The couch is made up of a few OpenGL primitives that are cleverly sized and placed:
To get the “stencil” effect, I drew the couch cushions twice, but the second time I drew them I scaled them up slightly and drew them in wireframe (I did the same thing with the phone buttons).
That said, here’s a snippet of the code used to draw the couch:
void couchArmFront()
{
//Caps to the front arms
glPushMatrix();
glScalef(1.0,1.0,0.001);
glutSolidSphere(0.077,15,15);
glPopMatrix();
}//end of couchArmFront function
void couchArm()
{
//Base
glPushMatrix();
glScalef(.5,1.0,1.0);
glutSolidCube(0.3);
glPopMatrix();
//Arm Rest
glPushMatrix();
glTranslatef(0.0,0.15,-0.15);
gluCylinder(quadric,.077,.077,.3,15,15);
glPopMatrix();
//Cap of Arm Rest front
glPushMatrix();
glTranslatef(0.0,0.15,0.15);
couchArmFront();
glPopMatrix();
//Cap of Arm rest back
glPushMatrix();
glTranslatef(0.0,0.15,-0.15);
couchArmFront();
glPopMatrix();
}//end of couchArm function
void couchCushion()
{
GLfloat couchCush_ambient [] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat couchCush_diffuse [] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat couchCush_specular [] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat couchCush_shininess [] = {50.0f};
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glScalef(1.399,0.3,1.4);
glutSolidCube(.2);
glMaterialfv(GL_FRONT, GL_AMBIENT, couchCush_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, couchCush_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, couchCush_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, couchCush_shininess);
glutWireCube(.201);
glPopAttrib();
glPopMatrix();
}//end of couchCushion function
void couchButton(int num)
{
// The center button has to be rendered slightly less far back so that
// it does not clip into the back of the couch
double transZ = 0.0;
if (num == 2)
transZ = -0.115;
else
transZ = -0.125;
glPushMatrix();
glTranslatef(0.0,0.20,transZ);
glScalef(1.0,1.0,0.35);
glutSolidSphere(0.02,10,10);
glPopMatrix();
}//end of couchButton function
void couch()
{
//couch arms
glTranslatef(0.0,0.15,0.3);
couchArm();
glTranslatef(1.0,0.0,0.0);
couchArm();
glTranslatef(-0.5,0.0,0.0);
glPushMatrix();
//couch base
glTranslatef(0.0,-0.04,0.0);
glScalef(3.33,0.50,0.9);
glutSolidCube(0.3);
glPopMatrix();
//couch back base
glPushMatrix();
glTranslatef(0.0,0.0,-0.2);
glScalef(3.80,1.0,0.35);
glutSolidCube(0.3);
glPopMatrix();
glPushMatrix();
//couch back top
glTranslatef(0.0,.175,-0.2);
glScalef(1.9,0.9,0.3);
glutSolidSphere(.3,30,30);
glPopMatrix();
//couch cushions
glTranslatef(-0.28,.08,0.0);
couchCushion();
couchButton(1);
glTranslatef(0.28,0.0,0.0);
couchCushion();
couchButton(2);
glTranslatef(0.28,0.0,0.0);
couchCushion();
couchButton(3);
}//end of couch function
thanks a ton.
The link seems to be broken. Can you provide me the code please?
Hi Lancia, I’ll see if I can dig it up! The link died because nobody was interested.
-Andy
hi, the link is broken, can you provide me the new link please ? thanks before 😀
Hi!
Iam doing an opengl project and so it would be of great help if i could the this code.
Pls provide the link??