Document 1
Document 1
Stefan HUBER
Kamran SAFDAR
Andreas SCHRÖCKER
Fachbereich Computerwissenschaften
Universität Salzburg
3 Force Simulation
4 Viewing
5 Animation
6 Control
3 Force Simulation
4 Viewing
5 Animation
6 ControlS. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 3/34
The Ball
z
Geometrically stating, a sphere with
radius r centred at C (xc , yc , zc ) is
the locus of points
Pi (x , y , z ), (0 ≤ i ≤ n), such that P
t r
(x − xc )2 +(y − yc )2 +(z − zc )2 = r 2 C
s
For any point P (x , y , z ) on surface y
P0
of the sphere, let s be the angle
−−→
from +x-axis to CP 0 , and t be the x
−→
angle from +z-axis to CP, such
that (0 ≤ s ≤ 2π) and (0 ≤ t ≤ π).
z
The parametric representation can
be explained mathematically as:
x = xc + r · sin t · cos s P
y = yc + r · sin t · sin s t r
z = zc + r · cos t
C
s
with s ∈ [0, 2π] and t ∈ [0, π] y
P0
So, if we know the coordinates of a
x
point P (x , y , z ) on surface of the
sphere, then we can easily find out
the values of parameters s and t.
0 s 1
North pole
0
t 256
1
512 South pole
−z
t=0
North pole
−y
s = 0.5
Texture coordinates are assigned such
that: −x
s = 0.00 at y = +r
s = 0.25 at x = +r +x
t = 0.0 at z = −r
s = 0.50 at y = −r
t = 1.0 at z = +r
s = 0.75 at x = −r
s = 1.00 at y = +r s=1
+y s = 0
t=1
South pole
+z
1 void DrawBall ()
2 {
3 GLuint texture_map ;
4 GLUquadric * qobj = gluNewQuadric () ;
5
6 texture_map = LoadTextureRAW (" textures /2. raw " , true , 512 , 256) ;
7 glEnable ( GL_TEXTURE_2D );
8 glBindTexture ( GL_TEXTURE_2D , texture_map );
9 gluQuadricTexture ( qobj , GL_TRUE );
10 gluSphere ( qobj ,1 ,50 ,50) ;
11 gluDeleteQuadric ( qobj );
12 glDeleteTextures ( 1, & texture_map );
13 glDisable ( GL_TEXTURE_2D );
14 }
3 Force Simulation
4 Viewing
5 Animation
6 Control
rectangle rectangle
The Table is axis
aligned.
Rectangular planes
trapezoid
GL QUADS
Pockets
GL QUAD STRIPS
GL TRIANGLE FAN triangle
GL TRIANGLES
quad strip
triangle fan
trapezoid
triangle
S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 14/34
Drawing the Edge
A cylinder is drawn
void gluCylinder()
And closed with
void gluDisk()
We make use
of the
symmetry in
the table’s
geometry.
One quarter
of a table is
drawn 4 times
with
glScalef().
Two different raw files: Wooden texture and green cloth texture
The texture coordinates are specified with glTexCoord2d(u,v)
For GL QUADS: Set u,v to (0.0,0.0), (0.0,1.0), (1.0,0.0), (1.0,1.0)
For the rest: Calculate u,v so that it looks properly
3 Force Simulation
4 Viewing
5 Animation
6 Control
3 Force Simulation
4 Viewing
Camera Movement
5 Animation
6 Control
1 switch ( nCameraState )
2 {
3 case CAM_SHOOTING :
4 gluLookAt ( eye_x , eye_y , eye_z ,
5 arrBalls [0]. pos .x ,0.285 , arrBalls [0]. pos .z ,
6 0.0 , 1.0 , 0.0) ;
7 break;
8
9 case CAM_OVERVIEW :
10 gluLookAt (0 ,35 ,0 , 0 ,0 ,0 , 1.0 , 0.0 , 0.0) ;
11 break;
12
13 case CAM_CENTER :
14 gluLookAt ( eye_x , eye_y , eye_z , 0 ,0 ,0 , 0.0 , 1.0 , 0.0) ;
15 break;
16 }
3 Force Simulation
4 Viewing
5 Animation
Movement and Friction
Rotation of Balls
Collision with the Cushion
Collision of Balls
6 Control
S. Huber, K. Safdar, A. Schröcker: Pool Billiard, An OpenGL-based billiard simulation 27/34
Movement and Rotation of Balls
x 2 (1 − c ) + c xy (1 − c ) − zs xz (1 − c ) + ys
0
yx (1 − c ) + zs y 2 (1 − c ) + c yz (1 − c ) − xs 0
xz (1 − c ) − ys yz (1 − c ) + xs z 2 (1 − c ) + c
0
0 0 0 1
-(a-b)
A
a
(a-b)
3 Force Simulation
4 Viewing
5 Animation
6 Control