This is a report for 3D modeling project using freeglut.
1. Introduction
This is a 3D scene describing Central building (CB) and Science buildings (SBs) in north campus of Xi’an Jiaotong-Liverpool University (XJTLU) in real life. This scene contains techniques such as lighting, fog, texture mapping and viewing transformation, moving animation. There are ten objects in this scene in total, which are respectively Central building, four science buildings (SA, SB, SC, SD), road, trees, moving cars and buses
and skybox. In addition, keyboard interactions and mouse control are implemented in the program, which provide zoom function and viewing transformation along with switches of texture, lighting, and fog effects. This report will discuss the graphic features in detail and provide instructions to run the program interactively by posting screen shots of each stage and image materials used in the program.
2. Graphic Features
All the graphic techniques are drawn in a world coordinate system, and they are placed in a large virtual
box. Objects in the scene are drawn by hierarchical modelling with their own coordinate systems. For the
viewing and window reshaping, perspective projection matrix is utilized. In the texture mapping technique,
there are totally 12 pictures used in this program. After transferring the bmp picture to pixel data and
binding, their IDs are stored in an integer list GLuint texture[12] whose length is 12.
2.1 Central Building
This central Building is drawn through hierarchical modelling. Cubes composing of the main body of the building are bound with strips in black and white which are generated by texture mapping through “strip.bmp”
which is shown below. Similarly, the logos of XJTLU on the top of the building are generated through “XJTLU.bmp”. To fuse the colour of textures and materials GL_MODULATE
is used in glTexParameterf()
. Edges
of each fragment are decorated with brown cubes stretched by scaling and they are translated to the right
position. Coordinates of each fragment of CB are computed elaborately and translated to the position.
2.2 Science Buildings
Science buildings are also drawn through hierarchical modelling. The green grids on the front and back are generated by texture mapping through “greenGrid.bmp” and the brown grids on the left and right are generated through “brownGrid.bmp”. Also, the strips on the intermediate layer are produced through “strip1.bmp”. The three textures are demonstrated below. After modelling SA, the other three buildings SB, SC, SD are drawn by translating and rotating the original SA, thus reducing the redundant codes.
2.3 Skybox
Skybox is generated through sticking six separated sky pictures to a large cube surrounding the whole scene and it ranges from (-6000, -6000, -60000) to (6000, 6000 ,6000). The six consecutive images “front.bmp”, ”back.bmp”, ”left.bmp” ,”right.bm”, ”top.bmp”, ”bottom.bmp” are mapped to the top, bottom, front, back, left and right of the surrounding cubic respectively and they are connected to each other, so that if observing inside the large box, the sky is the same as a whole picture taken in the real world. To make the
textures not interfered with materials, GL_REPLACE
is used in glTexParameterf()
.
The consecutive images are presented below:
2.4 Road and Trees
The road is drawn by stretching the cubes. Zebra lines on it and trees consisting of Icosahedrons and cubes beside it are drawn through translations embedded in a for loop, so that they are placed consecutively. In addition, the road on the back of CB is generated through translating and rotating the original front road. The ground where all the objects stand is drawn by a huge cube with grass texture “greenGrass.bmp” bound to
it which is shown below:
2.5 Moving Cars
There are moving cars on each of the two roads. The cars are drawn by a body consisting of cubes and four tyres consisting of cylinders. Two different kinds of cars are all generated by copying the original car. The motion of each car is enabled by glutIdleFunc()
, so that they can appear moving in the opposite direction on the different lanes. Each round of function call, a global variable named carD
will increase by one. In the
drawing function drawCars()
where this global variable is used, translate function is applied to move the cars by the value of carD
.
2.6 Viewing
Perspective transformation is implemented through gluLookAt()
. The detailed parameters inside are
demonstrated below:
gluLookAt(fltX0 * fltZoom, fltY0 * fltZoom, fltZ0 * fltZoom, fltXRef * fltZoom, fltYRef * fltZoom, fltZRef * fltZoom, fltXUp, fltYUp, fltZUp);
Where fltX0
, fltY0
,fltZ0
are the camera position of X, Y, Z coordinate, fltXRef
, fltYRef
, fltZRef
are the coordinates of lookat position, and fltZoom
is the zoom value of viewing, fltXUp
, fltYUp
, fltZUp
are the direction of camera up vector which are not changeable.
When moving the viewing position, parameters of look at positions and camera positions are changed simultaneously. Parallelly, when changing look-at position, only parameters of look at position are changed. So that the viewing transformation is implemented. In addition, viewing is triggered by keyboard interaction.
2.7 Fog and Lighting
To make the scene real, fog and lighting are implemented in the program. Also, they can be trigger by pressing left key of mouse and pressing “z” on the keyboard. To make the fog effects real, the colour of fog is set to
light blue which is the same as the sky. Besides, colour materials are enabled to allow different colour displaying on the transferred objects by calling glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
,
glEnable(GL_COLOR_MATERIAL) and glEnable(GL_NORMALIZE)
.
3. Instructions
3.1 Keyboard Interactions
To change viewing in the virtual world, there are fourteen operations:
-
To change viewing direction up or down, please press ‘n’ or ‘m’.
-
To change viewing position left or right, press ‘,’ or ‘.’.
-
To change viewing direction front or back, press ‘]’ or ‘[‘.
-
To move viewing position left or right, press ‘a’ or ‘d’.
-
To move viewing position up or down, press ‘w’ or ‘s’.
-
To move viewing position forward or back, press ‘e’ or ‘q’.
-
To zoom in or zoom out, press ‘I’ or ‘o’. To enable effects, there are three operations:
-
To enable or disable lighting, press ‘z’.
-
To enable or disable skybox, press ‘t’.
-
To enable or disable fog, press left mouse.
Entering the program, the scene is presented as image12, also, the scene without any effects is presented as image13:
Turn on the light effect and fog effect, the scene is demonstrated below:
To move around in the virtual world, anywhere in the skybox can be reached, the scene between SC and SD
is demonstrated below:
The Scene beside the central building is presented as stage3:
The resources can be accessed below:
https://download.csdn.net/download/Hhhhhaohao/14944522?spm=1001.2014.3001.5503