1. Thesis Writing - United International College

Virtual Campus Tour System
by
Wan Wei, Lycoris
(0730800068)
A Final Year Project Thesis (COMP4222; 6 Credits)
submitted in partial fulfillment of the requirements
for the degree of
Bachelor of Science (Honours)
in
Computer Science and Technology
at
BNU-HKBU
UNITED INTERNATIONAL COLLEGE
February, 2009
I
DECLARATION
I hereby declare that all the work done in this Project is of my independent
effort. I also certify that I have never submitted the idea and product of this
Project for academic or employment credits.
______________________
Wan Wei, Lycoris
(073080068)
Date: ___________________
II
BNU-HKBU
United International College
Computer Science and Technology Program
We hereby recommend that the Project submitted by Wan Wei, Lycoris
entitled "Virtual Campus tour" be accepted in partial fulfillment of the
requirements for the degree of Bachelor (Honours) of Science in Computer
Science and Technology Program.
_________________________
Date: __________________
_________________________
Date: ___________________
III
ACKNOWLEDGEMENT
I would like to express my great gratitude towards my supervisor, Dr. Hui
Zhang, Amy who had given me invaluable advice to this project.
IV
TABLE OF CONTENTS
ABSTRACT ........................................................................................................................................................ 1
Introduction ....................................................................................................................................................... 2
1. Thesis Writing ................................................................................................................................................ 4
1.1 Thesis Title Page ................................................................................................................................... 4
1.2 Declaration Page.................................................................................................................................... 4
1.3 Acceptance Page .................................................................................................................................... 4
1.4 Acknowledgement ................................................................................................................................. 4
1.5 Table of Contents .................................................................................................................................. 4
1.6 Abstract ................................................................................................................................................ 4
1.7 Introduction ........................................................................................................................................... 5
2 Main Text ........................................................................................................................................................ 5
2.1 Flow chat ...................................................................................................................................... 5
2.2 Modeling ....................................................................................................................................... 5
2.3 Rendering ...................................................................................................................................... 6
2.4 Event ............................................................................................................................................. 7
2.5 planned result ................................................................................................................................ 8
3. Conclusion ....................................................................................................................................................... 9
References ........................................................................................................................................................ 10
Appendices (optional) ....................................................................................................................................... 11
V
Virtual campus tool system
by
Wan Wei, Lycoris
Computer Science and Technology Program
BNU-HKBU
United International College
ABSTRACT
This paper addresses the problem of how to develop a virtual campus use
OpenGL. With the development of computer science technology,
nowadays people seek for 3D world/virtual reality to represent our world
and our fantasy into computer. By studying the relationship between
computer graphic and the real world, many algorithms has been used for
representing the real world into computer. However the real world is too
difficult for computer to display all things in the real world. In order to
offer better effect of the simulate world in computer, many render
technology has been proposed, where use sound, light, texture, physical
engine, particle system. This allows the system to use less time to develop
a better computer world.
1
Introduction
Virtual tour, which is a simulation of an existing location, has been widely
used for school, company, government. Let people to visit and find information
about a place without actually being there. It usually composes sequence of
video image, sound effects, music, narration, text. Traditional virtual tour use
panorama to show scenario, requiring assembling multiple images of a view in
to a single wide image. One popular method to develop the virtual tour
panorama is to stitch photographs taken from the same point in space but of
varying pitch and yaw in order to create a panoramic image which, when
rendered using appropriate software, allows the end user to pan and zoom at
will. The benefit of this method is that it doesn’t requires specialized equipment
to capture the images, although using such can greatly speed up the process and
render a higher quality result. However, The other method will be used for
develop the system, using OpenGL to create a 3D graphic world, which people
can walk-through the world and can pan, rotate and zoom.
In this paper, a different virtual tour method is used with OpenGL. The
method use polygons to create individual object and to assemble them into a
single map. And then take photos form the location to texture the polygon to
simulate the building and object in the computer world. In order to make the
simulate world become more realistic, using lighting and shading to render the
environment. Other system such as physical engine is used for detecting the
object’s border and test collision in the map. And to simulate the water, use a
particle system to express the product water wave of the lake, rain, and fork.
2
This paper is organized as follows. 2 reviews the fundamentals of computer
graphic. 3 proposed the method to model the object and to create the
environment base on OpenGL code. 4 presents many algorithm to render the
object and the environment. 5 presents the implementations. 6 shows the
experimental results and 7 gives the conclusions.
3
1.
Thesis Writing
All theses should be typed in black ink, paginated, and on A-4 white paper. The
page layout should use double-spacing, font size 12 and have 2.5 cm margins
on all sides. The thesis should not exceed 50 pages excluding the appendices.
1.1
Thesis Title Page
See the first page of this template.
1.2
Declaration Page
This declares the original and independent work by the author. See the second
page of this template.
1.3
Acceptance Page
This is to be signed by the Project Supervisor and the Observer if they find the
Project Report acceptable.
1.4
Acknowledgement
This should include the contributions made from supervisor(s), appreciation
extended to supervisor(s), and parties who should receive recognition for their
part in the project.
1.5
Table of Contents
Major headings and titles of all the tables and figures should be listed.
1.6
Abstract
An abstract should contain not more than 250 words on a separate page
summarizing the essentials of the research work including the objectives,
introduction, methodology, results, discussions and conclusions.
4
1.7
Introduction
The introduction should state clearly the objectives and significance of the
project with reference to the past or ongoing work.
2 Main Text
2.1 Flow chat
Start
3D modeling
Transform
TD
OpenGL
Texture
Rendering
Event
No
All the modeling done?
YES
Testing
End
5
2.2 Modeling
2.2.1 OpenGL concept
OpenGL (open graphics library) is an open-ended, high performance 3D graphics
library have hundreds instructions and functions, which provides a graphics hardware
interface for programmer. It is independent of hardware and operation system so it
has good cross-platform portability, which allows different operation system such as
Windows, Linux and Mac OS to use the same code only needs recompiled. But
OpenGL using basic points, lines, and polygons to build 3D model, is difficult and
complicated.
2.2.2 3Ds MAX
3Ds MAX (Autodesk 3D Studio MAX) is famous software developed by Autodesk
Media and Entertainment for modeling, animation and rendering package which
provides a strong tool for user to build 3D model, flexible plugin architecture and can
see models directly without programming. So first build model in 3Ds MAX and can
be easily transformed to OpenGL using converted tool and C++ code.
Figure 2.1 models built in 3Ds MAX
6
Figure 2.2 Load 3D models from .3Ds file into program using 3DS loader
2.2.3 Basic concept for modeling in OpenGL
1. OpenGL pipeline
When application call OpenGL API those command will push into a command
buffer. When buffer flush, data send to the next step, calculate the property of each
vertex, then send to rasterization. Rasterization use the vertex property to create
images then send it to frame buffer, which will post the image into screen.
Figure 2.3 a simple view of OpenGL pipeline
2. OpenGL primitive
Function glBegin(argument) and glEnd() tell the complier where the image start
and end. Different argument can draw different image like point, line, and polygon
etc. Every complicated graphics can divide into s single primitive so we can use those
primitive to build difficult model.
3. Defined viewpoint
Void glViewport(GLint x,GLint y,GLsizei width,GLsizei height)
Function defines the image only can be seeing in rectangle
7
{(x,y),(x+width,y),(x+width,y+height),(x,y+height)}
4. Projection
In OpenGL there are two different project methods: rectangular projection and
perspective projection. In order to express the realistic world we use perspective
rather than rectangular projection. Basic concept in perspective projection is project a
3D point into a 2D plane.
Figure 2.4 the position of Point P in the perspective projection
To calculate x1 and y1, use similar triangle. We can know that
x1
N

so (x1,
Px  Pz
y1)’ coordinate is
Px
Py
,N
)
(Point P’s projection)
 Pz
 Pz
Use these formula we can know the point near to observer is big, far is small, which
similar to realistic world.
The perspective projection in OpenGL is gluPerspective (GLdouble fov,GLdouble
aspect,GLdouble near,GLdouble far).
( x1, y1)  ( N
2.3 Rendering
2.3.1 Illumination model
Light is a very important for building the virtual world. To simulate the light in
OpenGL should consider light sources, material properties, location of viewer, surface
orientation. Correct shading requires a global calculation involving all objects and
light sources. In OpenGL, commonly use three components: Diffuse, Specular, And
Ambient.
Figure 2.5 illumination model where r = 2 (l ・n) n – l
8
To enable the light:
void glEnable(GL_LIGHTING);
To enable the light source function:
void glEnable(GLenum cap);
To assign the light function:
void glLightfv(GLenum light,GLenum pname,const GLfloat* params);
Objects are made of different material. Object’s material in OpenGL is defined
with the values of material’s reflectivity with three primary colors. So observer sees
the color of an object after the mix of ambient light, diffuse, specular and material
reflects ambient light.
Material defined function:
void Materialfv (GLenum face,GLenum pname,const float*params);
2.3.2 Texture
1. Concept
It's very difficult to simulate all the existing location into polygon, so texture is a
good method to solve this problem. Use texture can ignore the unimportant details,
for example, to build a strawberry model using texture can ignore complicated
building little hole in strawberry. Within the virtual tool system, use photos of the
location to texture the modeling are a good way to build model.
2.
Texture using 3Ds max unwrap UVW
There are many good methods to texture a model in 3Ds MAX. UVW unwrap is a
modifier that can unfold a complicated model into 2D picture. Thus it’s easy to
mapping the photos into the model by loading BMP file.
Figure 2.6 UVW unwrap in 3Ds MAX
Figure 2.7 mapping using Photoshop
9
Figure 2.8 model with texture
3.
Code in OpenGL for texture:
Except the texture using 3Ds MAX, OpenGL also offer some method to texture.
To load picture from file:
AUX_RGBImageRec *LoadBMP(char *Filename)()
AUX_RGBImageRec *TextureImage[1];
Bind Texture:
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[0]->data);
To bind picutre with model:
glBindTexture(GL_TEXTURE_2D, texture[0]);
Figure 2.9 Load SkyBox’s picture using OpenGL functions
10
2.3.3 Blending
Some material like grass is different from other material. When light encounter
the glass objects the light will reflection and transmission. So user can see the back
side of the object.
Figure 2.4 the schematic diagram of light transmission
Many special efficacies depend on Blend. To mix pixels and color existed in
screen, is depend on the value Alpha, the forth component of color to express the
transparency of object. Alpha = 0 means it is a crystal object Alpha = 1 otherwise.
Blend formula:
(Rs Sr + Rd Dr, Gs Sg + Gd Dg, Bs Sb + Bd Db, As Sa + Ad Da)
To implement the function in OpenGL using:
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2.4.5 Particle system
Many nature phenomena can be expressed by particle system such as blaze, fountain,
gas, and starry sky. A particle system can be consisting of objects with different
properties and particular rules.
1. One particle system should know where it's objects' location using 3D coordination.
2. Velocity (speed and direction) can describe the location after objects move.
Velocity is a vector to change objects' location.
3. Acceleration
Many force like gravitation will change the speed of objects' because of the acceleration.
4. Life
Every object has its life cycle, to express the disappearance of objects.
With those properties, Computer will express many phenomena by control each
particle with particular formula.
2.4 Event
2.4.1 Sound and Sound effects
11
Sound makes the world become more realistic like the real world and make people
feel comfortable when they travel in the simulated world. User can hear footfall when
their character walk or can hear the voice of rain hit the. Sounds in the simulated world
are part of the system that can let user interact with the system with hearing.
a. Background music
User can hear the background music when they first contact the system and they can
adjust the volume when they call-out the user menu.
Sound effects and Music event
User can hear different voice when they interact with the system, for example user
use the elevator then they will hear the “DingDong” and hear the voice of door opened.
Those voice usually actually existing in the realistic world and simulated in the
simulated world which can let user feel friendly because they are familiar with those
voice.
b. Development
Use DirectSound, support the windows platform, is one of an API of DirectX audio.
DirectSound are good at hardware utilizing and fine compatibility.
To use the DirectSound first it will create primary cache for the program that send
the MIXING to output device.
2.4.2 Animation
The simulated world is not a still world, but a vivid world. To let object become more
realistic, some animation will be added to the objects, such as flag fluttered in the breeze,
water flowing. Others, Character will walk to the appointed place with animation such as
in the real world. To add the animation to the character, draw key frame and computer
will calculate the interpolating between two key frames.
2.4.3 Transformation
The system allow character walk in the simulated world. To implement this function,
the 3D world can rotation, translates, and zooms.
Transform function:
Translation is to move a point to a new location.
Figure 2.5 object translate vector d from original position
The translation can be expressed using 4X4 matrix T in homogenous coordinate:
T = T (dx, dy, dz) =
1
0

0

0
0 0 dx 
1 0 d y 
0 1 dz 

0 0 1
In the system, user can walk in the map because of translation. When user click the
left mouse or special key “direction key” the character in the virtual world will react it and
translate from one point to another. And the scene will change with the character's
movement.
Rotation function:
User allows rotating the scene, with the right click of the mouse. To implement this
function using p’=Rz(q)p :
cos   sin 
 sin  cos 

 0
0

0
 0
0 0
0 0
1 0

0 1
Implementation in OpenGL
Load an identity matrix:
glLoadIdentity()
Multiply on right:
glRotatef(theta, vx, vy, vz)
theta in degrees, (vx, vy, vz) define axis of rotation
glTranslatef(dx, dy, dz)
glScalef( sx, sy, sz)
Each has a float (f) and double (d) format (glScaled)
2.4.4 Collision detection
There are some physical rules in the virtual world like realistic world such as gravity.
Characters can not cross the wall as people in the realistic world. So in order to prevent
form character against those laws of physics system will detect the collision.
Use light ray, the light can be expressed as:
PointOnRay = Raystart + t * Raydirection
t’s value from 0 to infinite. Then use this ray to represent and calculate the intersections
with plane or cylinders.
A plane is represented using its Vector representation as: Xn dot X = d
With the two functions reach conclusion that
t = (Xn dot (PointOnRay - Raystart)) / (Xn dot Raydirection)
2.4.5 Navigation
Navigation is an important function in the virtual tool system. People can travel in the
internet and feel the virtual world or they can know the place before they go there. Some
novices want the system help them to travel in the virtual tool, so that system should
calculate the shortest path for navigation.
2.5 accelerative algorithms
2.5.1 Display List
2.5.2 Frustum Culling
2.5.3 LOD (Level of detail)
2.5.4 Occlusion Culling
2.6.4 Backface Culling
2.6 planned result
Testing environment
Platform: Windows Vista
3D API: OpenGL
Develop tool: VS 2008 .NET
The result of the system should become a desktop application, which user can easy open it
by download the application from website. The application will automatically install and
can be open with double click the exe file. System will show a short welcome message to
user and open the main page, where user can control their characters to visit place.
3 Conclusion
In this paper, we have presented a practical and efficient method to develop a 3D
virtual tour system using OpenGL and VC++. The system is simulated a computer
world to represent the real location. User can walk in it and feel the beautiful
computer world which gives them an interesting tour at home.
References
[1] S.H Francis, M.K Stephen, “Computer graphics using OpenGL” Transmation,
chapter.5 , pp. 174-189.
[2] S.H Francis, M.K Stephen, “Computer graphics using OpenGL” Transmation,
chapter.4, pp. 121-149.
[3] Particle Engine Using OpenGL. [Online]. Available:
http://hi.baidu.com/xun1573/blog/item/2295fa2580c41f6735a80f0c.html
[4]
Particle Engine [Online] Available:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30
[5] Nehe Collision Detection: Acailable: http://blog.sina.com.cn/s/blog_5f0cf7bd0100cf28.html
Appendices (optional)
Not all theses need to have appendices. However, when there are materials which
are too technical or too detailed to be included in the main text and would help
some readers to understand the topic more thoroughly, the author can accommodate
them in an appendix section. These could be system setup, auxiliary tables, figures,
computer programs, and sample calculations etc., which are related to the subject of
investigation. However, it must be stressed that the main text itself should be self
sufficient and readers should be able to follow the arguments without frequent use
of the appendices.