0% found this document useful (0 votes)
39 views47 pages

CG Mini-Project Report Format

Uploaded by

shk7676246389
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views47 pages

CG Mini-Project Report Format

Uploaded by

shk7676246389
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELGAVI, KARNATAKA -590 018

A Minor Project Report on

“3d room environment ”


Submitted in partial fulfillment for the Computer Graphics and Image
Processing Laboratory [21CSL66] Course of Sixth Semester of Bachelor of
Engineering in Computer Science & Engineering during the academic
year 2023-24.
By
DARSHAN GOWDA N 4MN21CS014
SUHAS H K 4MN21CS051
T RAM GOPAL REDDY 4MN21CS052
Under the Guidance of

Prof. Bharath Bharadwaj B S


Assistant Professor
Dept. of CS&E
MIT Thandavapura

2023 – 24

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


MAHARAJA INSTITUTE OF TECHNOLOGY THANDAVAPURA
NH 766, NANJANGUD TALUK, MYSURU – 571302
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
MAHARAJA INSTITUTE OF TECHNOLOGY THANDAVAPURA

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

Prof. Bharath Bharadwaj B S Dr. Ranjit K N


Assistant Professor Associate Professor & Head
Dept. of CS&E Dept. of CS&E
MIT Thandavapura MIT Thandavapura

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]

T RAM GOPAL REDDY


[4MN21CS052]

I
ABSTRACT

This project presents the development of a 3D room environment


using computer graphics techniques. The primary objective is to create an
interactive and realistic virtual space that can be navigated and explored by
users. The 3D room environment is constructed using a combination of
modeling, texturing, lighting, and rendering techniques to achieve a high
level of visual fidelity.
The virtual room is designed with detailed 3D models representing
various elements such as furniture, windows, doors, and decorative items.
The layout is crafted to resemble a typical living space, providing users with
an immersive experience. Realistic textures and materials are applied to the
3D models to enhance the visual appeal and authenticity of the environment.
Techniques such as bump mapping, normal mapping, and specular mapping
are utilized to simulate different surface properties.

II
CONTENTS

SL. No. Index Page No.


1 INTRODUCTION 1-3
1.1 Aim of the Project 2
1.2 Overview of the Project 2
1.3 Outcome of the Project 3
2 DESIGN AND IMPLEMENTATION 4
2.1 Algorithm 5
2.2 Flowchart 6
2.3 OpenGL API’s Used with Description
3 RESULT ANALYSIS
3.1 Snapshots
3.2 Discussion
CONCLUSION AND FUTURE ENHANCEMENT
REFERENCES
APPENDIX A – Source Code

III
LIST OF FIGURES

SL. No. Index Page No.


1.1 OpenGL Architecture 2
2.1 OpenGL API’s Used with Description
3.1
3.2

IV
3D Room Environment Computer Graphics Laboratory with Mini Project

CHAPTER – 1
INTRODUCTION

Open GL is a hardware- and system dependent interface. An Open GL-application


will work on every platform, as long as there is an installed implementation, because it is
system independent, there are no functions to create windows etc., but there are helper
functions for each platform. A very useful thing is GLUT.
A broad classification of major subfields in Computer Graphics might be:

1. Geometry: Studies ways to represent and process surfaces.

2. Animation: Studies ways to represent and manipulate motion.

3. Rendering: Studies algorithms to reproduce light transport.

4. Imaging: Studies image acquisition or image editing.

• Computer graphics: Computer graphics is concerned with all aspects of producing


pictures and images using a computer.
• Translation: Translation is an operation that displaces points by a fixed size in a
given direction.
• Rotation: Three features of transformation extended to other rotations

1. There is one point in the origin that is unchanged by the rotation called fixed point.

2. Two-dimensional plane is a part of three-dimensional space, we can reinterpret this


rotation in three dimensions.
3. Rotation in the two-dimensional plane z=0 is equivalent to a three-dimensional rota-
tion about the z-axis.

Department of CS&E, MITT 2023-24 Page 1


3D Room Environment Computer Graphics Laboratory with Mini Project

OpenGL Architecture

Fig. 1.1: 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.

Department of CS&E, MITT 2023-24 Page 2


3D Room Environment Computer Graphics Laboratory with Mini Project

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.

Department of CS&E, MITT 2023-24 Page 3


3D Room Environment Computer Graphics Laboratory with Mini Project

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.

Department of CS&E, MITT 2023-24 Page 4


3D Room Environment Computer Graphics Laboratory with Mini Project

• 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

Design of the project.

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.

Department of CS&E, MITT 2023-24 Page 5


3D Room Environment Computer Graphics Laboratory with Mini Project

2.2 Flow Chart

2.3 OpenGL API’s Used with Description

Department of CS&E, MITT 2023-24 Page 6


3D Room Environment Computer Graphics Laboratory with Mini Project

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.

Function Name Description

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.

glutInitDisplaymode Set the initial window size.


Declaration:
Void glutInitWindowSize(int width,int height); width:
Width in pixels
Height: Height in pixels.
glutCreateWindow Set the title to graphics window.
Declaration:
Int glutCreateWindow(char *title);
Remarks:
This function creates a window on the display. The
string title can be used to label the window. The integer
value returned can be used to set the current window.
glutDisplayFunc Declaration.
Void glutDispalyFunc(void(*func)void));
Remarks:
This function registers the display function that is
executed when the window needs to be redrawn.
glEnd Declaration:
void glEnd();
Remarks:
This function is used in conjunction with glBegin to
Delimit the vertices of an opengl primitive.

Department of CS&E, MITT 2023-24 Page 7


3D Room Environment Computer Graphics Laboratory with Mini Project

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.

Table 2.1: OpenGL API’s Used with Description

Department of CS&E, MITT 2023-24 Page 8


3D Room Environment Computer Graphics Laboratory with Mini Project

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

Department of CS&E, MITT 2023-24 Page 9


3D Room Environment Computer Graphics Laboratory with Mini Project

Department of CS&E, MITT 2023-24 Page 10


3D Room Environment Computer Graphics Laboratory with Mini Project

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.

Department of CS&E, MITT 2023-24 Page 11


3D Room Environment Computer Graphics Laboratory with Mini Project

CONCLUSION AND FUTURE ENHANCEMENT

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

Department of CS&E, MITT 2023-24 Page 12


3D Room Environment Computer Graphics Laboratory with Mini Project

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.

Department of CS&E, MITT 2023-24 Page 13


REFERENCES
[l] Interactive computer graphics atop down approach with openGL-Edward Angel,5th
Edition.
[2] Computer graphics using open GL- F Hill, Jr.2ndEdition, Pearson Education,2001.
[31 OpenGL(R) Super Bible: Comprehensive Tutorial and Reference (4th Edition)
[4] Fundamentals of Computer Graphics by Steve Marschner, Peter Shirley [5] An
[5]Archaeology of Computer Graphics.
[6]Vector Analysis for Computer Graphics by Jhon Vince.
[7]A Programmer's Introduction to 3D Rendering.
[8]An Atlas & Exploration of Video Game Cities.
[9] Concepts, Algorithms and Implementation using C and OpenGL.
APPENDIX A: SOURCE CODE

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>

GLboolean redFlag = true, switchOne = false, switchTwo=false,


switchLamp=false, amb1=true, diff1=true, spec1=true, amb2=true,
diff2=true, spec2=true, amb3=true, diff3=true, spec3=true, fanSwitch =
false;
double windowHeight=800, windowWidth=600;
double eyeX=7.0, eyeY=2.0, eyeZ=15.0, refX = 0, refY=0,refZ=0;
double theta = 180.0, y = 1.36, z = 7.97888,a=2;

static GLfloat v_cube[8][3] =


{
{0.0, 0.0, 0.0}, //0
{0.0, 0.0, 3.0}, //1
{3.0, 0.0, 3.0}, //2
{3.0, 0.0, 0.0}, //3
{0.0, 3.0, 0.0}, //4
{0.0, 3.0, 3.0}, //5
{3.0, 3.0, 3.0}, //6
{3.0, 3.0, 0.0} //7
};

static GLubyte quadIndices[6][4] =


{
{0, 1, 2, 3}, //bottom
{4, 5, 6, 7}, //top
{5, 1, 2, 6}, //front
{0, 4, 7, 3}, // back is clockwise
{2, 3, 7, 6}, //right
{1, 5, 4, 0} //left is clockwise
};

static void getNormal3p


(GLfloat x1, GLfloat y1,GLfloat z1, GLfloat x2, GLfloat y2,GLfloat z2,
GLfloat x3, GLfloat y3,GLfloat z3)
{
GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz;

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();
}

void drawCube1(GLfloat difX, GLfloat difY, GLfloat difZ, GLfloat ambX=0,


GLfloat ambY=0, GLfloat ambZ=0, GLfloat shine=50)
{
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};

glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);

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();
}

static GLfloat v_trapezoid[8][3] =


{
{0.0, 0.0, 0.0}, //0
{0.0, 0.0, 3.0}, //1
{3.0, 0.0, 3.0}, //2

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
};

static GLubyte TquadIndices[6][4] =


{
{0, 1, 2, 3}, //bottom
{4, 5, 6, 7}, //top
{5, 1, 2, 6}, //front
{0, 4, 7, 3}, // back is clockwise
{2, 3, 7, 6}, //right
{1, 5, 4, 0} //left is clockwise
};

void drawTrapezoid(GLfloat difX, GLfloat difY, GLfloat difZ, GLfloat


ambX, GLfloat ambY, GLfloat ambZ, GLfloat shine=50)
{
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_emission[] = {difX, difY, difZ, 0.0};
GLfloat mat_shininess[] = {shine};

glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);

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();
}

//Drawing pyramid *************************


static GLfloat v_pyramid[5][3] =
{
{0.0, 0.0, 0.0},
{0.0, 0.0, 2.0},
{2.0, 0.0, 2.0},
{2.0, 0.0, 0.0},

A-3
APPENDIX A: SOURCE CODE
{1.0, 4.0, 1.0}
};

static GLubyte p_Indices[4][3] =


{
{4, 1, 2},
{4, 2, 3},
{4, 3, 0},
{4, 0, 1}
};

static GLubyte PquadIndices[1][4] =


{
{0, 3, 2, 1}
};

void drawpyramid(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};

glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);

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};

glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);

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();
}

void polygonLine(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};

glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);
glBegin(GL_LINE_STRIP);
//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();
}

void drawSphere(GLfloat difX, GLfloat difY, GLfloat difZ, GLfloat ambX,


GLfloat ambY, GLfloat ambZ, GLfloat shine=90)
{

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};

glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);

glutSolidSphere (3.0, 20, 16);


}

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();

//cupboard's 1st vertical stripline


glPushMatrix();
glTranslatef(4,1,5.9);
glScalef(0.5, 0.01, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's 2nd vertical stripline


glPushMatrix();
glTranslatef(4,0.5,5.9);
glScalef(0.5, 0.01, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's last stripline


glPushMatrix();
glTranslatef(4,0,5.9);
glScalef(0.5, 0.01, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's lst horizontal stripline


glPushMatrix();
glTranslatef(5.5,0,5.9);
glScalef(0.01, 1, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's right side horizontal stripline


glPushMatrix();
glTranslatef(4.75,1,5.9);
glScalef(0.01, 0.67, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's left side horizontal stripline


glPushMatrix();
glTranslatef(4,0,5.9);

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();

//cupboard's handle right


glPushMatrix();
glTranslatef(5,1.4,5.9);
glScalef(0.02, 0.18, 0.01);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's handle right sphere


glPushMatrix();
glTranslatef(5.02,1.9,5.91);
glScalef(0.02, 0.02, 0.01);
drawSphere(0.2,0.1,0.1, 0.1, 0.05, 0.05, 10);
glPopMatrix();

//cupboard's handle left


glPushMatrix();
glTranslatef(4.5,1.4,5.9);
glScalef(0.02, 0.18, 0.01);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's handle left sphere


glPushMatrix();
glTranslatef(4.52,1.9,5.91);
glScalef(0.02, 0.02, 0.01);
drawSphere(0.2,0.1,0.1, 0.1, 0.05, 0.05, 10);
glPopMatrix();

//cupboard's drawer's 1st handle


glPushMatrix();
glTranslatef(4.5,0.7,5.9);
glScalef(0.16, 0.02, 0.01);
drawCube1(0.2,0.1,0.1, 0.1, 0.05, 0.05);
glPopMatrix();

//cupboard's drawer's 2nd handle


glPushMatrix();
glTranslatef(4.5,0.25,5.9);
glScalef(0.16, 0.02, 0.01);
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();

// wall besides the right wall


//glColor3f(1, 0.8, 0.7);
glPushMatrix();
glTranslatef(8,-1,0);
glScalef(0.2, 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();

//pillow right far


//glColor3f(0.627, 0.322, 0.176);
glPushMatrix();
glTranslatef(0.5,0.5,6);
glRotatef(20, 0,0,1);
glScalef(0.1, 0.15, 0.28);
drawCube1(0.627, 0.322, 0.176, 0.3135,0.161,0.088);
glPopMatrix();

//pillow left near


//glColor3f(0.627, 0.322, 0.176);
glPushMatrix();

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();

//blanket side left part


//glColor3f(0.627, 0.322, 0.176);
glPushMatrix();
glTranslatef(1.4,-0.3,8.16);
//glRotatef(22, 0,0,1);
glScalef(0.5, 0.25, 0.05);
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();

//side drawer's drawer


glPushMatrix();
glTranslatef(0.88,0,8.8);
glScalef(0.0001, 0.11, 0.18);
drawCube1(0.3,0.2,0.2, 0.15,0.1,0.1);
glPopMatrix();

//side drawer's knob


glPushMatrix();
glTranslatef(0.9,0.15,9.05);
glScalef(0.01, 0.02, 0.02);
drawSphere(0.3, 0.1, 0.0, 0.15,0.05,0.0);
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();

//Linkin Park logo


glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(-0.9,2.1,5.5);
//glRotatef(22, 0,0,1);
glScalef(0.0001, .02, .25);
drawCube1(1.0,1.0,1.0, 1.0,1.0,1.0, 10);
glPopMatrix();

//Linkin Park logo


glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(-0.9,2.1,6.2);
glRotatef(-14, 1,0,0);
glScalef(0.0001, .28, .02);
drawCube1(1.0,1.0,1.0, 1.0,1.0,1.0, 10);
glPopMatrix();

//Linkin Park logo


glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(-0.9,1.8,6);
glRotatef(-14, 1,0,0);
glScalef(0.0001, .29, .02);
drawCube1(1.0,1.0,1.0, 1.0,1.0,1.0, 10);
glPopMatrix();

//Linkin Park logo


glColor3f(1.0,1.0,1.0);
glPushMatrix();
glTranslatef(-0.9,2.1,5.5);
glRotatef(23, 1,0,0);
glScalef(0.0001, .25, .02);
drawCube1(1.0,1.0,1.0, 1.0,1.0,1.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();

//wardrobe's 1st drawer


glPushMatrix();
glTranslatef(0.36,1.4,4.05);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.11, 0.38);
drawCube1(0.5,0.2,0.2, 0.25,0.1,0.1);
glPopMatrix();

//wardrobe's 2nd drawer


glPushMatrix();
glTranslatef(0.36,1,4.05);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.11, 0.38);
drawCube1(0.5,0.2,0.2, 0.25,0.1,0.1);
glPopMatrix();

//wardrobe's 3rd drawer


glPushMatrix();
glTranslatef(0.36,0.6,4.05);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.11, 0.38);
drawCube1(0.5,0.2,0.2, 0.25,0.1,0.1);
glPopMatrix();

//wardrobe's 4th drawer


glPushMatrix();
glTranslatef(0.36,0.2,4.05);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.11, 0.38);
drawCube1(0.5,0.2,0.2, 0.25,0.1,0.1);
glPopMatrix();

//wardrobe's 1st drawer handle


glColor3f(0.3,0.1,0);
glPushMatrix();
glTranslatef(0.37,1.5,4.3);
//glRotatef(22, 0,0,1);
glScalef(0.01, 0.03, 0.2);
drawCube1(0.3,0.1,0, 0.15,0.05,0.0);
glPopMatrix();

//wardrobe's 2nd drawer handle


glColor3f(0.3,0.1,0);
glPushMatrix();
glTranslatef(0.37,1.1,4.3);
//glRotatef(22, 0,0,1);
glScalef(0.01, 0.03, 0.2);
drawCube1(0.3,0.1,0, 0.15,0.05,0.0);
glPopMatrix();

//wardrobe's 3rd drawer handle


glColor3f(0.3,0.1,0);
glPushMatrix();
glTranslatef(0.37,0.7,4.3);
//glRotatef(22, 0,0,1);
glScalef(0.01, 0.03, 0.2);

A-11
APPENDIX A: SOURCE CODE
drawCube1(0.3,0.1,0, 0.15,0.05,0.0);
glPopMatrix();

//wardrobe's 4th drawer handle


glColor3f(0.3,0.1,0);
glPushMatrix();
glTranslatef(0.37,0.3,4.3);
//glRotatef(22, 0,0,1);
glScalef(0.01, 0.03, 0.2);
drawCube1(0.3,0.1,0, 0.15,0.05,0.0);
glPopMatrix();

void dressingTable()
{
//Dressing table ************************************************

//dressing table left body


glPushMatrix();
glTranslatef(5.9,0,4.6);
glScalef(0.2, 0.2, 0.2);
drawCube1(0.545, 0.271, 0.075, 0.2725,0.1355,0.0375);
glPopMatrix();

//dressing table right body


glPushMatrix();
glTranslatef(7,0,4.6);
glScalef(0.2, 0.2, 0.2);
drawCube1(0.545, 0.271, 0.075, 0.2725,0.1355,0.0375);
glPopMatrix();

//dressing table upper body


glPushMatrix();
glTranslatef(5.9,0.6,4.6);
glScalef(0.57, 0.1, 0.2);
drawCube1(0.545, 0.271, 0.075, 0.2725,0.1355,0.0375);
glPopMatrix();

//dressing table upper body bottom stripe


glPushMatrix();
glTranslatef(5.9,0.6,5.2);
//glRotatef(22, 0,0,1);
glScalef(0.57, 0.01, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table upper body upper stripe


glPushMatrix();
glTranslatef(5.9,0.9,5.2);
//glRotatef(22, 0,0,1);
glScalef(0.57, 0.01, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table upper body handle


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(6.5,0.75,5.2);
//glRotatef(22, 0,0,1);
glScalef(0.16, 0.02, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

A-12
APPENDIX A: SOURCE CODE

//dressing table left body handle


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(6.4,0.1,5.2);
//glRotatef(22, 0,0,1);
glScalef(0.02, 0.13, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table right body handle


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(7.1,0.1,5.2);
//glRotatef(22, 0,0,1);
glScalef(0.02, 0.13, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table main mirror


glPushMatrix();
glTranslatef(6.2,0.9,4.7);
//glRotatef(22, 0,0,1);
glScalef(0.36, 0.5, 0.0001);
drawCube1(0.690, 0.878, 0.902, 0.345,0.439,0.451, 10);
glPopMatrix();

//dressing table left mirror


glPushMatrix();
glTranslatef(5.92,0.9,4.7);
//glRotatef(0, 0,1,0);
glScalef(0.1, 0.48, 0.0001);
drawCube1(0.690, 0.878, 0.902, 0.345,0.439,0.451, 10);
glPopMatrix();

//dressing table left mirror left stripe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(5.92,0.9,4.71);
//glRotatef(22, 0,0,1);
glScalef(0.019, 0.48, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table left mirror left stripe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(6.17,0.9,4.71);
//glRotatef(22, 0,0,1);
glScalef(0.019, 0.48, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table mirror stripe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(5.92,0.9,4.71);
//glRotatef(22, 0,0,1);
glScalef(0.55, 0.019, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table left mirror upper stripe


glColor3f(0.2,0.1,0.1);

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();

//dressing table right mirror


glPushMatrix();
glTranslatef(7.25,0.9,4.7);
//glRotatef(-40, 0,1,0);
glScalef(0.1, 0.48, 0.0001);
drawCube1(0.690, 0.878, 0.902, 0.345,0.439,0.451, 10);
glPopMatrix();

//dressing table left mirror upper stripe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(7.25,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();

//dressing table right mirror left stripe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(7.25,0.9,4.71);
//glRotatef(22, 0,0,1);
glScalef(0.019, 0.48, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table right mirror right stripe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(7.5,0.9,4.71);
//glRotatef(22, 0,0,1);
glScalef(0.019, 0.48, 0.0001);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//dressing table main mirror polygon part


glColor3f(0.690, 0.878, 0.902);
glPushMatrix();
glTranslatef(6.2,2.4,4.7);
//glRotatef(22, 0,0,1);
glScalef(0.18, 0.18, 2);
polygon(0.690, 0.878, 0.902, 0.345,0.439,0.451, 10);
glPopMatrix();

//dressing table upper round srtipe


glColor3f(0.2,0.1,0.1);
glPushMatrix();
glTranslatef(6.2,2.4,4.71);
glScalef(.18, .18, 1);
polygonLine(0.2,0.1,0.1, 0.1,0.05,0.05, 50);
glPopMatrix();

void wallshelf()
{
//Wall Shelf **********************************************

A-14
APPENDIX A: SOURCE CODE

//wall shelf one


glPushMatrix();
glTranslatef(1.5,2.7,3);
glScalef(0.4, 0.03, 0.2);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//wall shelf two


glPushMatrix();
glTranslatef(1,2.3,3);
glScalef(0.4, 0.03, 0.2);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//wall shelf three


glPushMatrix();
glTranslatef(0.5,1.9,3);
glScalef(0.4, 0.03, 0.2);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//wall shelf four


glPushMatrix();
glTranslatef(1,1.5,3);
glScalef(0.4, 0.03, 0.2);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//wall shelf five


glPushMatrix();
glTranslatef(1.5,1.1,3);
glScalef(0.4, 0.03, 0.2);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//showpiece on the bottom shelf from left 1


glPushMatrix();
glTranslatef(1.5,1.2,3);
glScalef(0.04, 0.06, 0.2);
drawCube1(0.698,0.133,0.133, 0.349,0.0665,0.0665);
glPopMatrix();

//showpiece on the bottom shelf from left 2


glPushMatrix();
glTranslatef(2,1.2,3);
glScalef(0.04, 0.06, 0.2);
drawCube1(0.729,0.333,0.827, 0.3645,0.1665,0.4135);
glPopMatrix();

//showpiece on the bottom shelf from left 3 lower portion


glPushMatrix();
glTranslatef(2.5,1.2,3);
glScalef(0.04, 0.06, 0.2);
drawCube1(0.098,0.098,0.439, 0.049,0.049,0.2195);
glPopMatrix();

//showpiece on the bottom shelf from left 3 upper portion


glPushMatrix();
glTranslatef(2.51,1.35,3);
glScalef(0.01, 0.05, 0.2);
drawCube1(0.529,0.808,0.980, 0.2645,0.404,0.490);
glPopMatrix();

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();

//showpiece on the top shelf left 1


glPushMatrix();
glTranslatef(1.8,2.71,3);
glScalef(0.16, 0.1, 0.01);
drawCube1(0,0,0.9, 0,0,0.45);
glPopMatrix();

//showpiece on 2nd shelf


glColor3f(.416, 0.353, 0.804);
glPushMatrix();
glTranslatef(1.3,2.4,3);
glScalef(0.16, 0.08, 0.01);
drawCube1(.416,0.353,0.804, 0.208,0.1765,0.402);
glPopMatrix();

//showpiece on 3rd shelf left 1


glPushMatrix();
glTranslatef(0.4,1.9,3);
glScalef(0.05, 0.16, 0.01);
drawCube1(0.863,0.078,0.235, 0.4315,0.039,0.1175);
glPopMatrix();

//showpiece on 3rd shelf left 2


glPushMatrix();
glTranslatef(0.7,1.9,3);
glScalef(0.05, 0.12, 0.01);
drawCube1(0.780,0.082,0.522, 0.39,0.041,0.261);
glPopMatrix();

//showpiece on 3rd shelf left 3


glColor3f(0.600, 0.196, 0.800);
glPushMatrix();
glTranslatef(1,1.9,3);
glScalef(0.05, 0.09, 0.01);
drawCube1(0.6,0.196,0.8, 0.3,0.098,0.4);
glPopMatrix();

//showpiece on 4th shelf


glPushMatrix();
glTranslatef(1.8,1.5,3);
glScalef(0.2, 0.1, 0.2);
drawpyramid(0.282,0.239,0.545, 0.141,0.1195,0.2725, 50);
glPopMatrix();

//showpiece on 4th shelf


glPushMatrix();
glTranslatef(1.4,1.5,3);
glScalef(0.15, 0.1, 0.2);
drawpyramid(0.251,0.878,0.816, 0.1255,0.439,0.408, 50);
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();

//clock body white


glPushMatrix();
glTranslatef(-0.83,1.9,7.9);
//glRotatef(22, 0,0,1);
glScalef(0.06, 0.2, 0.08);
drawCube1(1.000,0.894,0.710, 1.000,0.894,0.710);
glPopMatrix();

//clock hour handle


glPushMatrix();
glTranslatef(-0.65,2.18,8.01);
glRotatef(45, 1,0,0);
glScalef(0.0001, 0.01, 0.04);
drawCube1(0,0,0, 0,0,0);
glPopMatrix();

//clock minute handle


glPushMatrix();
glTranslatef(-0.65,2.18,8.01);
glRotatef(90, 1,0,0);
glScalef(0.0001, 0.012, 0.08);
drawCube1(0,0,0, 0,0,0);
glPopMatrix();

//clock pendulum stick


glColor3f(0.2,0.1,0.1); //0.2,0.1,0.1
glPushMatrix();
glTranslatef(-0.7,2,8.1);
glRotatef(theta, 1,0,0);
glScalef(0.0001, 0.2, 0.03);
drawCube1(0.2,0.1,0.1, 0.1,0.05,0.05);
glPopMatrix();

//clock pendulum ball


glColor3f(0.2,0.1,0.1); //0.2,0.1,0.1
glPushMatrix();
glTranslatef(-0.72,1.42,z);
//glRotatef(x, 1,0,0);
glScalef(0.035, 0.035, 0.035);
//drawCube();
drawSphere(0.2,0.1,0.1, 0.1,0.05,0.05, 10);
glPopMatrix();

//clock top pyramid


glPushMatrix();
glTranslatef(-0.9,2.5,7.81);
//glRotatef(x, 1,0,0);
glScalef(0.16, 0.1, 0.2);
drawpyramid(0.5,0.2,0, 0.25,0.1,0, 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();

//window right side corner


glPushMatrix();
glTranslatef(-0.9,1,8.9);
glScalef(0.04, 0.6, 0.0001);
drawCube1(0.8,0.6,0.4, 0.4,0.3,0.2);
glPopMatrix();

//window left side corner


glPushMatrix();
glTranslatef(-0.9,1,9.8);
glScalef(0.04, 0.6, 0.0001);
drawCube1(0.8,0.6,0.4, 0.4,0.3,0.2);
glPopMatrix();

//window upper side corner


glPushMatrix();
glTranslatef(-0.7,2.7,8.9);
glScalef(0.0001, 0.05, 0.4);
drawCube1(0.7,0.6,0.5, 0.35,0.3,0.25);
glPopMatrix();

//window lower side corner


glPushMatrix();
glTranslatef(-0.8,1.02,8.9);
glScalef(0.0001, 0.02, 0.34);
drawCube1(0.7,0.6,0.5, 0.35,0.3,0.25);
glPopMatrix();

//window vertical bar 1


glPushMatrix();
glTranslatef(-0.87,2.1,8.9);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.02, 0.3);
drawCube1(0.0,0.0,0.0, 0.0,0.0,0.0, 5);
glPopMatrix();

//window vertical bar 2


glPushMatrix();
glTranslatef(-0.87,1.6,8.9);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.02, 0.3);
drawCube1(0.0,0.0,0.0, 0.0,0.0,0.0, 5);
glPopMatrix();

//window horizontal bar


glPushMatrix();
glTranslatef(-0.87,1,9.3);
//glRotatef(22, 0,0,1);
glScalef(0.0001, 0.6, 0.02);
drawCube1(0.0,0.0,0.0, 0.0,0.0,0.0, 5);
glPopMatrix();
}
void fan()

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);
}

glutSolidSphere(1.0, 16, 16);


glPopMatrix();
}

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);

if(amb1 == true){glLightfv( GL_LIGHT0, GL_AMBIENT, light_ambient);}


else{glLightfv( GL_LIGHT0, GL_AMBIENT, no_light);}

if(diff1 == true){glLightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse);}


else{glLightfv( GL_LIGHT0, GL_DIFFUSE, no_light);}

if(spec1 == true){glLightfv( GL_LIGHT0, GL_SPECULAR,


light_specular);}
else{glLightfv( GL_LIGHT0, GL_SPECULAR, no_light);}

glLightfv( GL_LIGHT0, GL_POSITION, light_position);


glPopMatrix();
}

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);

if(amb2 == true){glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient);}


else{glLightfv( GL_LIGHT1, GL_AMBIENT, no_light);}

if(diff2 == true){glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse);}


else{glLightfv( GL_LIGHT1, GL_DIFFUSE, no_light);}

A-21
APPENDIX A: SOURCE CODE

if(spec2 == true){glLightfv( GL_LIGHT1, GL_SPECULAR,


light_specular);}
else{glLightfv( GL_LIGHT1, GL_SPECULAR, no_light);}

glLightfv( GL_LIGHT1, GL_POSITION, light_position);


glPopMatrix();
}

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);

if(amb3 == true){glLightfv( GL_LIGHT2, GL_AMBIENT, light_ambient);}


else{glLightfv( GL_LIGHT2, GL_AMBIENT, no_light);}

if(diff3 == true){glLightfv( GL_LIGHT2, GL_DIFFUSE, light_diffuse);}


else{glLightfv( GL_LIGHT2, GL_DIFFUSE, no_light);}

if(spec3 == true){glLightfv( GL_LIGHT2, GL_SPECULAR,


light_specular);}
else{glLightfv( GL_LIGHT2, GL_SPECULAR, no_light);}

glLightfv( GL_LIGHT2, GL_POSITION, light_position);


GLfloat spot_direction[] = { 0.3, -1, -0.8 };
glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spot_direction);
glLightf( GL_LIGHT2, GL_SPOT_CUTOFF, 35.0);
glPopMatrix();
}

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();
}

void myKeyboardFunc( unsigned char key, int x, int y )


{
switch ( key )
{
case 'w': // move eye point upwards along Y axis
eyeY+=1.0;
break;
case 's': // move eye point downwards along Y axis
eyeY-=1.0;
break;
case 'a': // move eye point left along X axis
eyeX-=1.0;
break;
case 'd': // move eye point right along X axis
eyeX+=1.0;
break;
case 'o': //zoom out
eyeZ+=1;
break;
case 'i': //zoom in
eyeZ-=1;
break;
case 'q': //back to default eye point and ref point
eyeX=7.0; eyeY=2.0; eyeZ=15.0;
refX=0.0; refY=0.0; refZ=0.0;
break;
case 'j': // move ref point upwards along Y axis
refY+=1.0;
break;
case 'n': // move ref point downwards along Y axis
refY-=1.0;
break;
case 'b': // move ref point left along X axis
refX-=1.0;
break;
case 'm': // move eye point right along X axis
refX+=1.0;
break;
case 'k': //move ref point away from screen/ along z axis
refZ+=1;
break;
case 'l': //move ref point towards screen/ along z axis
refZ-=1;
break;
case '1': //to turn on and off light one
if(switchOne == false)
{
switchOne = true; amb1=true; diff1=true; spec1=true;
glEnable( GL_LIGHT0); break;
}

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

if(theta >= 196 && theta <= 210)


{
y = 1.44;
}
else if(theta >= 180 && theta <= 194)
{
y = 1.42;
}
else if(theta >= 180 && theta <= 194)
{
y = 1.4;
}
else if(theta >= 164 && theta <= 178)
{
y = 1.42;
}

if(theta >= 210)


{
redFlag = false;
}
}
else if(redFlag == false)
{
theta -= thetaIncrement;
z += zIncrement; // Decreased the rate of change for z

if(theta >= 196 && theta <= 210)


{
y = 1.44;
}
else if(theta >= 180 && theta <= 194)
{
y = 1.42;
}
else if(theta >= 180 && theta <= 194)
{
y = 1.4;
}
else if(theta >= 164 && theta <= 178)
{
y = 1.42;
}

if(theta <= 150)


{
redFlag = true;

A-25
APPENDIX A: SOURCE CODE
}
}
if(fanSwitch == true){
a+= 5;
if(a > 360)
a -= 360;
}
else{
a = a;
}

glutPostRedisplay();
}

void fullScreen(int w, int h)


{
//Prevent a divide by zero, when window is too short;you cant make a
window of zero width.
if (h == 0)
h = 1;
float ratio = (GLfloat)w / (GLfloat)h; //Calculate aspect
ratio of the window

//Set the perspective coordinate system


glMatrixMode(GL_PROJECTION); //Use the Projection
Matrix
glLoadIdentity(); //Reset Matrix

glViewport(0, 0, w, h); //Set the viewport to


be the entire window
gluPerspective(60, ratio, 1, 500); //Set the correct
perspective.
//glFrustum(-2.5,2.5,-2.5,2.5, ratio, 200);
glMatrixMode(GL_MODELVIEW); //Get Back to the
Modelview
}

int main (int argc, char **argv)


{
glutInit(&argc, argv);

std::cout<<"To move Eye point:"<< std::endl;


std::cout<<"w: up"<<std::endl;
std::cout<<"s: down"<<std::endl;
std::cout<<"a: left"<<std::endl;
std::cout<<"d: right"<<std::endl;
std::cout<<"i: zoom in"<<std::endl;
std::cout<<"o: zoom out"<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<"To move Camera point:"<< std::endl;
std::cout<<"j: up"<<std::endl;
std::cout<<"n: down"<<std::endl;
std::cout<<"b: left"<<std::endl;
std::cout<<"m: right"<<std::endl;
std::cout<<"l: move nearer"<<std::endl;
std::cout<<"k: move far"<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<"Press q to move to default position"<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<"For lighting: "<<std::endl;

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;

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

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

You might also like