CG Mini-Project Report Format
CG Mini-Project Report Format
2023 – 24
CERTIFICATE
Certified that the minor project work entitled “3D ROOM
ENVIRONMENT” is a bonafide work carried out by DARSHAN GOWDA N
(4MN21CS014), SUHAS H K (4MN21CS051) & T RAM GOPAL REDDY
(4MN21CS052) for the course Computer Graphics and Image Processing
Laboratory with course code 21CSL66 of Sixth Semester in Computer Science
& Engineering under Visvesvaraya Technological University, Belagavi during
academic year 2023-24.
It is certified that all corrections/suggestions indicated for Internal
Assignment have been incorporated in the report. The report has been approved
as it satisfies the course requirements.
_________________ _________________
Signature of Lab Staff In-Charge Signature of the HoD
External viva
Name of the Examiners Signature with date
1)…………………………………………………………………………………….
2)…………………………………………………………………………………….
ACKNOWLEDGEMENT
It is the time to acknowledge all those who have extended their guidance,
inspiration and their whole hearted co-operation all along our project work.
We are grateful to Dr.Y T Krishne Gowda, Principal, MIT
Thandavapura, Dr.H K Chethan, Professor and Mentor, CS&E, MIT
Thandavapura and Dr.Ranjit K N, Associate Professor and Head, CS&E, MIT
Thandavapura for having provided us academic environment which nurtured our
practical skills contributing to the success of our project.
We would like to sincerely thank our project guide
Prof. Bharath Bharadwaj B S, Assistant Professor, CS&E, MIT Thandavapura
for providing relevant information, valuable guidance and encouragement to
complete this project.
We wish to place a deep sense of gratitude to all Teaching and
Non-Teaching staffs of Computer Science and Engineering Department for
whole-hearted guidance and constant support without which this endeavor would
not have been possible.
Our gratitude will not be complete without thanking our parents and also
our friends, who have been a constant source of support and aspirations.
DARSHAN GOWDA
[4MN21CS014]
SUHAS GOWDA
[4MN21CS051]
I
ABSTRACT
II
CONTENTS
III
LIST OF FIGURES
IV
3D Room Environment Computer Graphics Laboratory with Mini Project
CHAPTER – 1
INTRODUCTION
1. There is one point in the origin that is unchanged by the rotation called fixed point.
OpenGL Architecture
1.1 Aim
The aim of this project is to demonstrate the 3D Room Environment and visualization
in the observer view point and working showing using computer graphic concepts
using OpenGL and glut.
1.2 Overview
This project involves the creation of a 3D room environment, leveraging a range of
computer graphics techniques to achieve a realistic and interactive virtual space. The
development process is divided into several key stages.
The first stage involves designing the layout of the room and creating detailed 3D models
for various elements such as furniture, windows, doors, and decorative items. The models
are crafted to reflect real-world objects, enhancing the realism of the virtual environment.
To add authenticity and visual appeal, realistic textures and materials are applied to the
3D models. Techniques such as bump mapping, normal mapping, and specular mapping
are used to simulate different surface properties, making the objects look more lifelike.
1.3 Outcome
We can successfully demonstrate the 3D Room Environment and its components
using OpenGL and Glut libraries with C/C++.
Creating a 3D room environment using OpenGL involves several key steps. Start
by setting up a basic room with walls, a floor, and a ceiling, adding basic lighting for
realism. Enhance the environment with textures, materials, and shaders. Implement
camera controls for navigation and add interactive elements like doors and windows.
Populate the room with textured furniture and objects. Use advanced lighting techniques
and shadows to improve realism. Develop a user interface (UI) for environment control
and optimize performance with level of detail (LOD) techniques. Add save and load
functionality for room setups. For an immersive experience, consider adding virtual
reality (VR) support and VR controls.
CHAPTER – 2
DESIGN AND IMPLEMENTATION
This project aims to enhance the user's knowledge of computer graphics and OpenGL by
demonstrating the creation of a three-dimensional room environment. The project focuses
on using key OpenGL functions such as translation and rotation to manipulate objects
within the room. Users can interact with the environment through input devices like a
keyboard, observing how different transformations affect the objects in the room.
This project will demonstrate the use of three-dimensional Room environment in
OpenGL. Our project has detail information about 3D room in different forms as well as
regaining its original shape.
The project is mainly divided into two functions. They are as follows:
• Translation
• Rotation
Translation
Translation is an operation that displaces points by fixed distance in a given
direction. A translation takes a point and maps that point into another point. We use
translation in order to shift from one position to other.
In our project glTranslate produces a translation by x, y, z. The current matrix is
multiplied by this translation matrix, with the product replacing the current matrix. If the
matrix mode is either GL_MODELVIEW or GL_PROJECTION, all objects are drawn
after a call to glTranslate or glTranslated. Use glPushMatrix and glPopMatrix to save and
restore the untranslated coordinate system. To perform translation, we can use following
function call.
Void glTranslatef (Glfloat x, Glfloat y, Glfloat z);
Again, we can translate the object in following direction:
• X-axis
• Y-axis
• Z-axis
Rotation
Rotation is an operation that rotates the object about fixed point in any given
direction. A rotated function takes four parameters first is to accept the angle according to
which it has to perform rotation and remaining three parameters for direction of rotation.
In our project we use rotation to rotate the propeller along with the cone about origin in
the desired direction. Following are the direction in which we rotate cone and propeller.
• Left direction
• Right direction
• Up direction
• Down direction
To perform the rotation, we use the following function glRotatef (Glfloat angle, Glfloat x,
Glfloat y, Glfloat z); where angle specifies how many degrees we want to rotate around
an axis and x, y, z specifies the axis to rotate respectively and below figure shows us the
2.1 Algorithm
Step 1: Define Room Geometry
Specify the shape and dimensions of the room.
Define the vertices and indices for the walls, floor, and ceiling.
Step 2: Set Up the Scene
Create a 3D scene with the room model and other relevant objects (e.g., furniture).
Define the camera and lighting setup.
Step 3: Animation Loop
Initialize any required variables for the scene (e.g., camera position, light
intensity).
Step 4: Handle User Input
Allow the user to move the camera, adjust lighting, or interact with objects.
Step 5: Update Scene Parameters
Update camera position and orientation based on user input.
Update lighting and other scene parameters as needed.
Step 6: Render the Scene
Render the room and all objects within it.
Output the rendered frame to the screen.
Repeat the animation loop to create a smooth, interactive environment.
OpenGL has become a widely accepted standard for developing graphics applica-
tion. Most Of our applications will be designed to access OpenGL directly through func-
tions in three libraries. Functions in main GL library have names that begin with the let-
ters gl and are stored in a library usually referred to as GL.
glutInitDisplayMode
Sets the initial display mode. Declaration:
void glutlnitDisplayMode (unsigned int mode);
Remarks:
The initial display mode is used when creating top-level
windows, sub windows, and overlays to determine the
OpenGL display mode for the to-be- created window or
overlay.
glMatrixMode Declaration:
VoidglMatrixMode(GLenummode);
Remarks:
This function specifies which matrix will be affected by
subsequent transformations mode can be GL
MODELVIEW, GLPROJECTION or GL TEXTURE.
glOrtho Declaration:
void glOrtho(GLdouble left, GLdouble right, GLdouble
bottom,GLdouble top,GLdouble near,GLdouble far);
Remarks:
It defines an orthographic viewing volume with all
parameters measured from the center of the projection
plane.
glIint Declaration:
Void glutInit(int *argc, char **argv).
Remarks:
To start through graphics system, we must first call glutInit
(),glutInit will initialize the GLUT library and negotiate a
session with the window system. During this process,
glutInit may cause the termination of the GLUT program
with an error message to the user if GLUT cannot be
properly initialized.
glutAddMenuEntry Declaration:
Void glutAddMenuEntry(char *name,int value); Remarks:
Adds a menu entry to the bottom of the current menu The
String name will be displayed for the newly added menu
entry.
CHAPTER – 3
RESULT ANALYSIS
3D room environment OpenGL project involves assessing visual quality (lighting,
shadows, textures), performance (frame rate, memory usage), and interactivity (user input
response, collision detection). Ensure all features work as intended, and use profiling
tools to identify and document any issues, supported by visual evidence and improvement
suggestions.
3.1 Snapshots
3.2 Discussion
3D room environments are vital for architecture and interior design, providing realistic vi-
sualizations early in the design process. They enable exploration of layouts and aesthetics
before construction. In virtual reality, these environments are crucial for immersive train-
ing and educational simulations, enhancing learning through realistic experiences. In
gaming, they create immersive worlds for interactive gameplay. They also support practi-
cal training in fields like healthcare, offering safe environments for skill development.
Developing high-quality 3D rooms involves optimizing performance and achieving real-
istic visuals. Future advancements may include AI integration for dynamic interactions
and advanced rendering techniques for enhanced realism, expanding applications across
industries.
Conclusion
The development of the 3D room environment has demonstrated the effective use of com-
puter graphics techniques to create a realistic and interactive virtual space. The project
successfully integrated various elements such as detailed 3D modeling, realistic texturing
and materials, dynamic lighting and shadows, and intuitive user interaction. The outcome
is a cohesive and immersive environment that provides a hands-on experience for users,
showcasing the potential of computer graphics in virtual reality, interior design visualiza-
tion, and game development.
Throughout the project, the application of efficient rendering techniques and optimization
strategies ensured smooth performance and real-time interaction, balancing visual quality
with computational load. The project serves as a foundational example for future develop-
ments in related fields, highlighting the importance of combining different graphics tech-
niques to achieve a high level of realism and interactivity.
Future Enhancement
Future enhancements for 3D room environments can significantly elevate their realism
and interactivity. Implementing physics-based interactions will allow objects to behave
according to real-world physics, enhancing immersion through realistic simulations of
gravity, collisions, and other dynamics. Expanding the environment to include multiple
rooms or diverse spaces can provide a more comprehensive and varied experience, allow-
ing users to navigate and explore different settings. Enabling multi-user collaboration will
allow multiple users to interact within the same virtual space simultaneously, facilitating
collaborative tasks, virtual meetings, and multiplayer gaming. Enhanced interactivity,
such as functional appliances, movable furniture, and dynamic environmental changes
like lighting adjustments or weather effects, can further engage users. Adapting the envi-
ronment for virtual reality (VR) platforms will provide an even more immersive experi-
ence, requiring optimization of controls and rendering for VR headsets to ensure a com-
fortable and intuitive user experience. Incorporating artificial intelligence (AI) elements,
such as virtual assistants or intelligent non-player characters (NPCs), can add a layer of
interactivity and personalization, making the environment more dynamic and responsive
to user actions. Continuously improving graphics and effects through advanced tech-
niques like ray tracing, global illumination, and real-time reflections can push the bound-
aries of visual realism, creating more stunning and lifelike environments. These enhance-
ments will transform 3D room environments into more complex and versatile virtual spa-
ces, opening up new possibilities for applications in virtual reality, interior design, gam-
ing, education, and beyond.
APPENDIX – A
SOURCE CODE
#define GL_SILENCE_DEPRECATION
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
Ux = x2-x1;
Uy = y2-y1;
Uz = z2-z1;
Vx = x3-x1;
Vy = y3-y1;
Vz = z3-z1;
Nx = Uy*Vz - Uz*Vy;
A-1
APPENDIX A: SOURCE CODE
Ny = Uz*Vx - Ux*Vz;
Nz = Ux*Vy - Uy*Vx;
glNormal3f(Nx,Ny,Nz);
}
void drawCube()
{
glBegin(GL_QUADS);
for (GLint i = 0; i <6; i++)
{
getNormal3p(v_cube[quadIndices[i][0]][0], v_cube[quadIndices[i]
[0]][1], v_cube[quadIndices[i][0]][2],
v_cube[quadIndices[i][1]][0], v_cube[quadIndices[i]
[1]][1], v_cube[quadIndices[i][1]][2],
v_cube[quadIndices[i][2]][0], v_cube[quadIndices[i]
[2]][1], v_cube[quadIndices[i][2]][2]);
glVertex3fv(&v_cube[quadIndices[i][0]][0]);
glVertex3fv(&v_cube[quadIndices[i][1]][0]);
glVertex3fv(&v_cube[quadIndices[i][2]][0]);
glVertex3fv(&v_cube[quadIndices[i][3]][0]);
}
glEnd();
}
glBegin(GL_QUADS);
A-2
APPENDIX A: SOURCE CODE
{3.0, 0.0, 0.0}, //3
{0.5, 3.0, 0.5}, //4
{0.5, 3.0, 2.5}, //5
{2.5, 3.0, 2.5}, //6
{2.5, 3.0, 0.5} //7
};
if(switchLamp==true){
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
} else {
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
}
glBegin(GL_QUADS);
for (GLint i = 0; i <6; i++)
{
getNormal3p(v_trapezoid[TquadIndices[i][0]][0],
v_trapezoid[TquadIndices[i][0]][1], v_trapezoid[TquadIndices[i][0]][2],
v_trapezoid[TquadIndices[i][1]][0], v_trapezoid[TquadIndices[i]
[1]][1], v_trapezoid[TquadIndices[i][1]][2],
v_trapezoid[TquadIndices[i][2]][0], v_trapezoid[TquadIndices[i]
[2]][1], v_trapezoid[TquadIndices[i][2]][2]);
glVertex3fv(&v_trapezoid[TquadIndices[i][0]][0]);
glVertex3fv(&v_trapezoid[TquadIndices[i][1]][0]);
glVertex3fv(&v_trapezoid[TquadIndices[i][2]][0]);
glVertex3fv(&v_trapezoid[TquadIndices[i][3]][0]);
}
glEnd();
}
A-3
APPENDIX A: SOURCE CODE
{1.0, 4.0, 1.0}
};
glBegin(GL_TRIANGLES);
for (GLint i = 0; i <4; i++)
{
getNormal3p(v_pyramid[p_Indices[i][0]][0],
v_pyramid[p_Indices[i][0]][1], v_pyramid[p_Indices[i][0]][2],
v_pyramid[p_Indices[i][1]][0],
v_pyramid[p_Indices[i][1]][1], v_pyramid[p_Indices[i][1]][2],
v_pyramid[p_Indices[i][2]][0],
v_pyramid[p_Indices[i][2]][1], v_pyramid[p_Indices[i][2]][2]);
glVertex3fv(&v_pyramid[p_Indices[i][0]][0]);
glVertex3fv(&v_pyramid[p_Indices[i][1]][0]);
glVertex3fv(&v_pyramid[p_Indices[i][2]][0]);
}
glEnd();
glBegin(GL_QUADS);
for (GLint i = 0; i <1; i++)
{
getNormal3p(v_pyramid[PquadIndices[i][0]][0],
v_pyramid[PquadIndices[i][0]][1], v_pyramid[PquadIndices[i][0]][2],
v_pyramid[PquadIndices[i][1]][0],
v_pyramid[PquadIndices[i][1]][1], v_pyramid[PquadIndices[i][1]][2],
v_pyramid[PquadIndices[i][2]][0],
v_pyramid[PquadIndices[i][2]][1], v_pyramid[PquadIndices[i][2]][2]);
glVertex3fv(&v_pyramid[PquadIndices[i][0]][0]);
glVertex3fv(&v_pyramid[PquadIndices[i][1]][0]);
glVertex3fv(&v_pyramid[PquadIndices[i][2]][0]);
glVertex3fv(&v_pyramid[PquadIndices[i][3]][0]);
}
glEnd();
A-4
APPENDIX A: SOURCE CODE
void polygon(GLfloat difX, GLfloat difY, GLfloat difZ, GLfloat ambX,
GLfloat ambY, GLfloat ambZ, GLfloat shine)
{
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_ambient[] = { ambX, ambY, ambZ, 1.0 };
GLfloat mat_diffuse[] = { difX, difY, difZ, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = {shine};
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(6,0);
glVertex2f(5.8,1);
glVertex2f(5.2,2);
glVertex2f(5, 2.2);
glVertex2f(4, 2.8);
glVertex2f(3,3);
glVertex2f(2, 2.8);
glVertex2f(1, 2.2);
glVertex2f(0.8, 2);
glVertex2f(0.2,1);
//glVertex2f(0,0);
glEnd();
}
glEnd();
}
A-5
APPENDIX A: SOURCE CODE
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_ambient[] = { ambX, ambY, ambZ, 1.0 };
GLfloat mat_diffuse[] = { difX, difY, difZ, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = {shine};
void cupboard()
{
//Cupboard/Almari
************************************************************
//cupboard
glPushMatrix();
glTranslatef(4,0,4.4);
glScalef(0.5, 1, 0.5);
drawCube1(0.5,0.2,0.2, 0.25, 0.1, 0.1 );
glPopMatrix();
A-6
APPENDIX A: SOURCE CODE
glScalef(0.01, 1, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();
void room()
{
// carpet
//glColor3f(0.4, 0.1, 0.0);
glPushMatrix();
//glScalef(5, 0.1, 7);
glTranslatef(3,-0.2,7);
glScalef(1.3, 0.01, 1.7);
drawCube1(0.4, 0.1, 0.0, 0.20, 0.05, 0.0);
glPopMatrix();
// right wall
//glColor3f(1, 0.8, 0.5);
glPushMatrix();
glTranslatef(-1.5,-1,.5);
glScalef(5, 2, 0.1);
//drawCube1(1, 0.8, 0.5, 0.5,0.4,0.25);
A-7
APPENDIX A: SOURCE CODE
drawCube1(1, 0.8, 0.7, 0.5, 0.4, 0.35);
glPopMatrix();
// left wall
//glColor3f(1, 0.8, 0.7);
glPushMatrix();
glTranslatef(-4.5,-1,0);
glScalef(1, 2, 5);
drawCube1(1, 0.8, 0.7, 0.5, 0.4, 0.35);
glPopMatrix();
//ceiling
//glColor3f(1.0, 0.9, 0.8);
glPushMatrix();
glTranslatef(-2,5.1,0);
glScalef(5, 0.1, 7);
drawCube1(1.0, 0.9, 0.8, 0.5,0.45,0.4);
glPopMatrix();
// floor
glPushMatrix();
glScalef(5, 0.1, 7);
glTranslatef(-1,-5,0); //-1,-5,.5
//glScalef(5, 0.1, 7);
drawCube1(0.5, 0.1, 0.0, 0.25,0.05,0);
glPopMatrix();
}
void bed()
{
//bed headboard
glPushMatrix();
glScalef(0.1, 0.5, 0.9);
glTranslatef(-2,-0.5,6.2);
drawCube1(0.5,0.2,0.2, 0.25,0.1,0.1);
glPopMatrix();
//bed body
glPushMatrix();
glScalef(1, 0.2, 0.9); //1, 0.2, 0.9
glTranslatef(0,-0.5,6.2);
drawCube1(0.824, 0.706, 0.549, 0.412,0.353,0.2745);
glPopMatrix();
A-8
APPENDIX A: SOURCE CODE
glTranslatef(0.5,0.5,7.2);
glRotatef(22, 0,0,1);
glScalef(0.1, 0.15, 0.28);
drawCube1(0.627, 0.322, 0.176, 0.3135,0.161,0.088);
glPopMatrix();
//blanket
//glColor3f(0.627, 0.322, 0.176);
glPushMatrix();
glTranslatef(1.4,0.45,5.5);
//glRotatef(22, 0,0,1);
glScalef(0.5, 0.05, 0.95);
drawCube1(0.627, 0.322, 0.176, 0.3135,0.161,0.088);
glPopMatrix();
void bedsideDrawer()
{
//bedside drawer *************************************
//side drawer
glPushMatrix();
glTranslatef(0.5,-0.1,8.7); //0.5,-0.1,9
glScalef(0.12, 0.2, 0.23);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();
void lamp()
{
//lamp base
glPushMatrix();
glTranslatef(.6,0.5,8.95);
glScalef(0.07, 0.02, 0.07);
drawCube1(0,0,1, 0,0,0.5);
glPopMatrix();
//lamp stand
glColor3f(1,0,0);
glPushMatrix();
glTranslatef(.7,0.35,9.05);
A-9
APPENDIX A: SOURCE CODE
glScalef(0.01, 0.2, 0.01);
drawCube1(1,0,0, 0.5,0.0,0.0);
glPopMatrix();
//lamp shade
glColor3f(0.000, 0.000, 0.545);
glPushMatrix();
glTranslatef(.6,0.9,8.9);
glScalef(0.08, 0.09, 0.08);
drawTrapezoid(0.000, 0.000, 0.545, 0,0,0.2725);
//drawCube1(0.000, 0.000, 0.545, 0,0,0.2725);
glPopMatrix();
}
void LinkinParkPoster()
{
//Linkin Park Poster *****************************************
//poster black
glColor3f(0.0,0.0,0.0);
glPushMatrix();
glTranslatef(-1,1.4,4.6);
glScalef(0.0001, .65, .8);
drawCube1(0,0,0, 0,0,0, 10);
glPopMatrix();
void wardrobe()
A-10
APPENDIX A: SOURCE CODE
{
//wardrobe
glPushMatrix();
glTranslatef(0,0,4);
glScalef(0.12, 0.6, 0.4);
drawCube1(0.3,0.1,0, 0.15,0.05,0);
glPopMatrix();
A-11
APPENDIX A: SOURCE CODE
drawCube1(0.3,0.1,0, 0.15,0.05,0.0);
glPopMatrix();
void dressingTable()
{
//Dressing table ************************************************
A-12
APPENDIX A: SOURCE CODE
A-13
APPENDIX A: SOURCE CODE
glPushMatrix();
glTranslatef(5.92,2.3,4.71);
//glRotatef(22, 0,0,1);
glScalef(0.1, 0.019, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();
void wallshelf()
{
//Wall Shelf **********************************************
A-14
APPENDIX A: SOURCE CODE
A-15
APPENDIX A: SOURCE CODE
//showpiece on the top shelf left 2
glColor3f(0.502, 0.502, 0.000);
glPushMatrix();
glTranslatef(2.5,2.71,3);
//glRotatef(22, 0,0,1);
glScalef(0.05, 0.16, 0.01);
drawCube1(0.502,0.502,0.000, 0.251,0.251,0);
glPopMatrix();
void Clock()
{
A-16
APPENDIX A: SOURCE CODE
//Clock ************************************************************
//clock body
glColor3f(0.545, 0.271, 0.075);
glPushMatrix();
glTranslatef(-0.9,1.8,7.87);
//glRotatef(22, 0,0,1);
glScalef(0.08, 0.25, 0.1);
drawCube1(0.545,0.271,0.075, 0.271,0.1335,0.0375, 50);
glPopMatrix();
A-17
APPENDIX A: SOURCE CODE
void window()
{
//Window ********************************************
//window white open
glPushMatrix();
glTranslatef(-0.9,1,8.9); //0.5,1,9.6
glScalef(0.0001, .6, .3);
drawCube1(1.0,1.0,1.0, 0.05,0.05,0.05);
glPopMatrix();
A-18
APPENDIX A: SOURCE CODE
{
glPushMatrix();
glTranslatef(3,4,8);
//stand
glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(0.1,0,0.09);
glScalef(0.01,0.4,0.01);
//glTranslatef(-1.5,-1.5,-1.5);
drawCube();
glPopMatrix();
//fan cube
glColor3f(0.5,0.2,0.2);
glPushMatrix();
glScalef(0.1,0.05,0.1);
glTranslatef(-1.5,-1.5,-1.5);
drawCube();
glPopMatrix();
glPushMatrix();
glRotatef(a, 0,1,0);
//blade 1 blue
glColor3f(0.8,0.6,0.4);
glPushMatrix();
//glRotatef(a, 0,1,0);
glScalef(0.5,0.01,0.1);
glTranslatef(-1.5,-1.5,-1.5);
drawCube();
glPopMatrix();
//blade 2 purple
glColor3f(0.8,0.6,0.4);
glPushMatrix();
//glRotatef(a, 0,1,0);
glScalef(0.1,0.01,0.5);
glTranslatef(-1.5,-1.5,-1.5);
drawCube();
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
void sphericalObject()
{
//table top part
glPushMatrix();
glTranslatef(5, 0.2, 10);
glScalef(0.1, 0.02, 0.1);
drawSphere(0.5,0.2,0, 0.25,0.1,0, 20);
glPopMatrix();
//table leg
glColor3f(0.2,0.1,0.1); //0.2,0.1,0.1
glPushMatrix();
glTranslatef(4.98,-0.1,10);
glScalef(0.02, 0.1, 0.02);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();
//base
A-19
APPENDIX A: SOURCE CODE
glPushMatrix();
glTranslatef(5, -0.1, 10);
glScalef(0.05, 0.01, 0.05);
drawSphere(0.5,0.2,0, 0.25,0.1,0, 20);
glPopMatrix();
}
void lightBulb1()
{
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 1.000, 0.843, 0.000, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat high_shininess[] = { 100.0 };
GLfloat mat_emission[] = {1.000, 1,1, 0.0};
glPushMatrix();
glTranslatef (5, 5, 8);
glScalef(0.2, 0.2, 0.2);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
if(switchOne == true){
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
}else{
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
}
void lightBulb2()
{
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 1.000, 0.843, 0.000, 1.0 };
GLfloat high_shininess[] = { 100.0 };
GLfloat mat_emission[] = {1,1,1, 1.0};
glPushMatrix();
glTranslatef (0,5,8);
glScalef(0.2, 0.2, 0.2);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
if(switchTwo == true){
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
}else{
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
}
glutSolidSphere(1.0, 16, 16);
glPopMatrix();
}
void lightBulb3()
{
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
A-20
APPENDIX A: SOURCE CODE
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 1.000, 0.843, 0.000, 1.0 };
GLfloat high_shininess[] = { 100.0 };
GLfloat mat_emission[] = {1,1,1, 1.0};
glPushMatrix();
glTranslatef (0.7, 1.5, 9.0);
glScalef(0.2, 0.2, 0.2);
glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
if(switchLamp == true){
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
}else{
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
}
glutSolidSphere(1.0, 16, 16);
glPopMatrix();
}
void lightOne()
{
glPushMatrix();
GLfloat no_light[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 5.0, 5.0, 8.0, 1.0 }; //5 5 10
//glEnable( GL_LIGHT0);
void lightTwo()
{
glPushMatrix();
GLfloat no_light[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat light_diffuse[] = { 1.0, 1.0, 0.9, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 0.0, 5.0, 8.0, 1.0 };
//glEnable( GL_LIGHT1);
A-21
APPENDIX A: SOURCE CODE
void lampLight()
{
glPushMatrix();
GLfloat no_light[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 0.7, 1.5, 9.0, 1.0 }; //0.7, 4.5, 9.0
//glEnable( GL_LIGHT2);
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective(60,1,1,100);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ, refX,refY,refZ, 0,1,0); //7,2,15, 0,0,0,
0,1,0
glEnable(GL_LIGHTING);
lightOne();
lightTwo();
lampLight();
room();
bed();
bedsideDrawer();
lamp();
LinkinParkPoster();
wallshelf();
wardrobe();
cupboard();
A-22
APPENDIX A: SOURCE CODE
dressingTable();
Clock();
window();
fan();
sphericalObject();
lightBulb1();
lightBulb2();
//lightBulb3();
glDisable(GL_LIGHTING);
glFlush();
glutSwapBuffers();
}
A-23
APPENDIX A: SOURCE CODE
else if(switchOne == true)
{
switchOne = false; amb1=false; diff1=false; spec1=false;
glDisable( GL_LIGHT0); break;
}
case '2': //to turn on and off light two
if(switchTwo == false)
{
switchTwo = true; amb2=true; diff2=true; spec2=true;
glEnable( GL_LIGHT1); break;
}
else if(switchTwo == true)
{
switchTwo = false; amb2=false; diff2=false; spec2=false;
glDisable( GL_LIGHT1); break;
}
case '3': //to turn on and off light one
if(switchLamp == false)
{
switchLamp = true; amb3=true; diff3=true; spec3=true;
glEnable( GL_LIGHT2); break;
}
else if(switchLamp == true)
{
switchLamp = false; amb3=false; diff3=false;
spec3=false;
glDisable( GL_LIGHT2); break;
}
case'4': //turn on/off ambient light 1
if(amb1 == false) {amb1=true; break;}
else{amb1=false; break;}
case'5':
if(diff1 == false) {diff1=true; break;}
else{diff1=false; break;}
case'6':
if(spec1 == false) {spec1=true; break;}
else{spec1=false; break;}
case'7': //turn on/off ambient light 2
if(amb2 == false) {amb2=true; break;}
else{amb2=false; break;}
case'8':
if(diff2 == false) {diff2=true; break;}
else{diff2=false; break;}
case'9':
if(spec2 == false) {spec2=true; break;}
else{spec2=false; break;}
case'e': //turn on/off ambient lamp light
if(amb3 == false) {amb3=true; break;}
else{amb3=false; break;}
case'r':
if(diff3 == false) {diff3=true; break;}
else{diff3=false; break;}
case't':
if(spec3 == false) {spec3=true; break;}
else{spec3=false; break;}
case 'f': //turn on/off fan
if(fanSwitch == false) {
fanSwitch = true; break;
}
else{
fanSwitch = false; break;
}
case 27: // Escape key
exit(1);
A-24
APPENDIX A: SOURCE CODE
}
glutPostRedisplay();
}
void animate()
{
// Change these values to make the animation slower
float thetaIncrement = 0.1; // Smaller increment for theta
float zIncrement = 0.001; // Smaller increment for z
if(redFlag == true)
{
theta += thetaIncrement;
z -= zIncrement; // Decreased the rate of change for z
A-25
APPENDIX A: SOURCE CODE
}
}
if(fanSwitch == true){
a+= 5;
if(a > 360)
a -= 360;
}
else{
a = a;
}
glutPostRedisplay();
}
A-26
APPENDIX A: SOURCE CODE
std::cout<<"Light source 1 [the light on the right on the screen
"<<std::endl;
std::cout<<"1: to turn on/off light one "<<std::endl;
std::cout<<"4: to turn on/off ambient light one "<<std::endl;
std::cout<<"5: to turn on/off diffusion light one "<<std::endl;
std::cout<<"6: to turn on/off specular light one "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<"Light source 2 [the light on the left on the screen
"<<std::endl;
std::cout<<"2: to turn on/off light two "<<std::endl;
std::cout<<"7: to turn on/off ambient light two "<<std::endl;
std::cout<<"8: to turn on/off diffusion light two "<<std::endl;
std::cout<<"9: to turn on/off specular light two "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<"Lamp light (spot light)" <<std::endl;
std::cout<<"3: to turn on/off lamp "<<std::endl;
std::cout<<"e: to turn on/off ambient lamp light "<<std::endl;
std::cout<<"r: to turn on/off diffusion lamp light
"<<std::endl;
std::cout<<"t: to turn on/off specular lamp light "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<"f: to turn on/off fan "<<std::endl;
std::cout<<"____________________"<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" "<<std::endl;
glutInitWindowPosition(100,100);
glutInitWindowSize(windowHeight, windowWidth);
glutCreateWindow("1607063 Bedroom");
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
glEnable(GL_NORMALIZE);
glutReshapeFunc(fullScreen);
glutDisplayFunc(display);
glutKeyboardFunc(myKeyboardFunc);
glutIdleFunc(animate);
glutMainLoop();
return 0;
}
A-27