Computer Graphic Final Project
Computer Graphic Final Project
Project
Li Yicheng
Leiden Institution of Computer Science
[email protected]
Abstract
This document illustrates several interested topics in computer graphic, including the movement of
an object using matrix transformation with the demonstration of a flying dragon, two different modes in
developing openGL programs: retained mode and immediate mode and the designing of particle system
with the demonstration of firework in which some fuzzy operations was introduced. SDL was used so that
the two different scenes - the dragon as the firework rocket and the explosion of firework can be arranged
in good time sequence.
I. Introduction
The initial goal of this final project is to simulate the dragon fireworks from Gandalf in the
movie, The Fellowship of the Ring(2001). The
basic idea is using the dragon as the rocket and
when the dragon flew far away and disappear
within our sight, a firework exploded at where
the dragon disappeared. The first problem to
solve is how to load a dragon model into our
program. The main problem I solve is that the
dragons self motion should correspond to the
path it follows. A simple path was designed
that the dragon flew towards the screen then
it turned around and flew far away from us.
Four different kinds of firework was designed,
there is the basic sphere mode, curtain shape
mode, which is from one point several particles
pouring down, laser mode, which is from one
point particles pop out in a fast speed like the
laser. All the modes are just transformation
of a basic particle system class. The difference
are just how to define the moving path, the
kinematics of each particle system. These will
be further illustrated in later section.
Object Loader
special thank to Mark Hoekveen for his help in having taught me how to use SDL in the program
v ...
...
# List of texture coordinates, in (u, v [,
w]) coordinates, these will vary
between 0 and 1, w is optional and
defaults to 0.
vt 0.500 1 [0]
vt ...
...
# List of vertex normals in (x,y,z) form;
normals might not be unit vectors.
vn 0.707 0.000 0.707
vn ...
...
# Parameter space vertices in ( u [, v] [, w
] ) form; free form geometry
statement ( see below )
vp 0.310000 3.210000 2.100000
vp ...
...
# Polygonal face element (see below)
f 123
f 3/1 4/2 5/3
f 6/4/1 3/5/3 7/6/5
f ...
...
In this project, a class called Loadobj is created and since only the vertices are needed
the implementation is very simple and informal. The only thing we need to do is to judge
whether the beginning of a new line is actually a single letter v, if it is, then the following
three float numbers would be stored in a vector
with 3 element, such data struct a vector with
3 elements is defined in the glm library. Then
we push the single vertex to the whole vertices
structure and here the structure is defined in
the <vector> library. The whole vertices is the
member of the class LoadObj.
1
2
3
4
5
6
7
8
9
10
II.
Dragon Movement
/
originally created by Yicheng in Leiden
/
#include <vector>
#include <stdio.h>
#include <string>
#include <cstring>
#include "glm/glm.hpp"
#include "loadobj.hpp"
The velocity direction marked as blue dotted line should provide two information. First,
it is the tangent line of every point on the path.
Second, it reflects how much degree should
the object be rotated. Here the example is
only given in a 2-Dimensional case. And the
1
equations are obvious:
2
3
4
5
dy
tan() = dx
dx = v x dt
dy = vy dt
y = f (x)
6
7
8
9
III.
4
5
6
7
8 }
Then if you would like to go back to the retained mode, just create your objects again.
However, the problem here is if you have programmed in the immediate mode, it is not possible to keep on declaring the shader program
because the shader program also have effect
on the vertices you created in the immediate
mode. I tried and the program could run but
some ugly cube and shadow appears flashing
in the window you created, it is a bit scary!!
To conclude, it is still better to build all the
project on the retained mode.
II.
Particle System
III. Firework
I.
void changeProgramState ( ) {
g l B i n d B u f f e r (GL_ARRAY_BUFFER, 0 ) ;
g l D e l e t e B u f f e r s (1 ,&VBO) ;
3
/ data /
4
vec3 p o s i t i o n ;
5
vec3 v e l o c i t y ;
6
vec3 a c c e l e r a t i o n ;
7
Color c o l o r ;
8
f l o a t age ;
9
float l i f e ;
10
float size ;
11 } P a r t i c l e ;
/ / i t e r i s j u s t one p a r t i c l e
f l o a t alpha = 1 ( i t e r > age ) /( i t e r >
life ) ;
IV.
When the particles age reach its life, it becomes transparent. Of course, the variables
velocity,position and acceleration are used to
modify how the particles would move and the
inner function between these variables is what
makes every particle system different.
The following is just a simple example of show- 1
ing how a round firework is created.
2
1
2
3
4
5
6
7
8
9
10
f l o a t posX , posY = 0 . 0 f ;
f l o a t dangle = 2 3 . 1 4 1 5 / ptlCount ;
f l o a t angle = 0 . 0 ;
for ( vector < P a r t i c l e > : : i t e r a t o r i t e r =
p a r t i c l e s . begin ( ) ;
i t e r ! = p a r t i c l e s . end ( ) ;
i t e r ++) {
i t e r > age += dt ;
/ / add t h e p a s s i n g
time ( d i f f e r i a n t i a l time )
angle += dangle ;
i t e r > v e l o c i t y = vec3 ( 2 0 cos ( angle ) ,
20 s i n ( angle ) , rand ( ) %30 1 5 . 0 f )
;
}
III.
Fuzzy Operation
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Using SDL
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
}
changeProgramState ( ) ;
while ( running )
{
handleEvent ( ) ;
ps . s i m u l a t e ( 0 . 0 1 ) ;
ps_n . s i m u l a t e ( 0 . 0 1 ) ;
ps_n1 . s i m u l a t e ( 0 . 0 1 ) ;
ps_s . s i m u l a t e ( 0 . 0 1 ) ;
ps_d . s i m u l a t e ( 0 . 0 1 ) ;
renderGL_dragon ( ) ;
renderGL_lazer ( ) ;
renderGL_normal ( ) ;
renderGL_normal1 ( ) ;
renderGL_scatter ( ) ;
}
V.
Conclusion
Conducting the project provides me with another way to build and simulate models, while
I ususlly use Matlab to build simulations. And
computer graphic now started to intrigue me,
there is huge possibility that I would move on
to more study in Computer Graphics.