Documente Academic
Documente Profesional
Documente Cultură
->
N - normala la planul de vizualizare
--->
VUP - vectorul sus la planul de vizualizare
-->
VV
--->
UP
->
N
-->
---> ->
VU = UP x N
-->
VU
plan de vizualizare
Translatie
Sistem de
coordonate de
vizualizare
Alinierea axelor
VU x VU y
VVx VVy
Nx Ny
0
0
VU z 0
VVz 0
T(-PRVx , - PRVy , - PRVz )
Nz 0
0 1
3
v
fereastra
plan de vizualizare
fereastra
Volum de
vizualizare
(umax, vmax)
PRP
(umin, vmin)
fereastra
Volum de
vizualizare
CF (umax, vmax)
(umin, vmin)
PRP
CF - centrul ferestrei
PRP-CF - directia de proiectie
plan de vizualizare
plan spate
plan fata
PRP
n
planul fata
n
F
Planele delimitatoare:
plan spate
zmin
-1
-z
x=z, x=-z
y=z, y=-z
z=zmin, z=-1, zmin < 0
plan fata
Planele delimitatoare:
plan spate
0
plan fata
-1
-z
x=1, x=-1
y=1, y=-1
z=0, z=-1
-1
10
x sau y
1
plan spate
planul fata
-1
-z
plan fata
-1
n
F
11
Plan de
vizualizare
Plan fata
Directia de
proiectie
Plan
spate
Directia de
proiectie
Plan de
vizualizare
Plan fata
12
Proiectia paralela
13
PRP
plan spate
zmin
-1
-z
plan fata
14
PRP
Plan
spate
N
Plan de
vizualizare
N
Plan
fata
PRP
15
Proiectia pespectiva
16
Transformarea in viewport 3D
0<=x<=1
0<=y<=1
0<=z<=1
(xvmin<=x<=xvmax
yvmin<=y<=yvmax
zvmin<=z<=zvmax)
17
Proiectia paralela
x sau y
1
plan spate
0
-1
-z
plan fata
-1
Proiectia perspectiva
x sau y
plan spate
zmin
-1
-z
plan fata
Transformarea perspectiva
x sau y
x sau y
plan spate
plan spate
0
zmin
-1
-z
-1
-z
plan fata
-1
plan fata
0
P
=
perspectiva 0
0
0 0 0
1 0 0
0 1 0
1
0
0
d
Transformarea perspectiva
Variatia coordonatei z in intervalul [0, 1]
1
0
T
=
perspectiva 0
a=
1
1 + zmin
Tperspectiva
1
0
=
0
b= -
0
1
0
0
0
0
a
-1
zmin
1 + zmin
1
1 + zmin
0
-1
0
0
0
b
zmin
1 + zmin
0
21
OpenGL
Caracteristici OpenGL
Desenare obiecte
Transformarea de vizualizare
Culori, iluminare
Eliminarea partilor nevizibile
Maparea texturilor
Lucrul cu imagini
22
OpenGL
Biblioteca OpenGL
gl*() - gl.h
Biblioteci suplimentare
23
glNume_Functie2f(x, y)
Numar componente/
Dimensiuni
2 (x,y)
3 (x,y,z)
4 (x,y,z,w) sau
(r,g,b,a)
B
ub
s
us
i
ui
f
d
byte
unsigned byte
short
unsigned short
int
unsigned int
float
double
Se adauga v
pentru forma
vectoriala
glVertex2fv(v)
24
glVertex
glVertex3f (x,y,z);
Numele
Functie din
biblioteca
de baza al 3 argumente
functiei
Argumente
numere reale
OpenGL
25
Descrierea Primitivelor
Puncte
Linii
Poligoane
26
Tipuri de primitive
GL_POINTS
GL_LINE
{S | _LOOP | _STRIP }
GL_POLYGON
27
Tipuri de primitive
GL_TRIANGLE
{S | _STRIP | _FAN}
GL_QUAD
{S | _STRIP}
28
glBegin(GL_POLYGON)
glVertex2f( 0.0,
glVertex2f( 0.0,
glVertex2f( 3.0,
glVertex2f( 4.0,
glVertex2f( 2.0,
glEnd();
0.0
3.0
3.0
1.5
0.0
);
);
);
);
);
GL_POLYGON
29
Transformarea de modelare
Transformarea de vizualizare
Transformarea de proiectie (inclusiv
decupare)
Impartire perspectiva
Transformarea in poarta de afisare
Transformarile sunt pastrate sub forma
matricilor 4x4, in reprezentarea coloana
30
Coordonate de
vizualizare
Coordonate de
decupare
Coordonate dispozitiv
normalizate
Transformarea de
modelare - vizualizare
Transformarea de
proiectie
Impartirea
perspectiva
Transformarea in
poarta de afisare
31
Ttransformarea de modelare
Obiecte definite in
sisteme de
coordonate proprii
(sisteme de
coordonate locale)
Transformarea de
modelare
Sistem obiect
Sistem real
glRotate{fd}(u, 1, 0,0);
glRotate{fd}(u, 0, 1,0);
glRotate{fd}(u, 0, 0,1);
32
glLoadIdentity();
A desen();
A
B
glLoadIdentity();
B glTranslatef(-20.0, 0.0, 0.0);
desen();
33
Stive de matrici
34
Exemplu
A
glPushMatrix();
desen();
glPopMatrix();
glPushMatrix();
glTranslatef(10,0,10);
desen();
glPopMatrix();
glPushMatrix();
glTranslatef(40,0,0);
glRotatef(45.0,0,1,0);
desen();
glPopMatrix();
20
10
0
A
0
10
20
30
40
50
60
35
Transformarea de vizualizare
gluLookAt(ox,oy,oz,cx,cy,cz,upx,upy,upz)
Obs(ox,oy,oz)-pozitia observatorului
C(cx,cy,cz)-punctul catre care se priveste
upx,upy,upz-componentele vectorului sus
Vector up
(upx, upy, upz)
(ox, oy, oz)
Sistem
real
36
Transformarea de vizualizare
v
y
n
Obs
C
Sistem
real
x
z
Sistem de coordonate
de vizualizare
Implicit:
37
Transformarea de proiectie
Proiectie paralela
glOrtho(l, r, b, t, n, f);
Proiectie perspectiva
glFrustum(l, r, b, t, n, f);
38
Proiectie perspectiva
glFrustum(l, r, b, t, n, f)
y
z
x
b
n
39
Proiectie perspectiva
gluPerspective(fovy, aspect, n, f)
y
z
y
fovy
z
obs
aspect = w / h
w
h
x
n
40
Proiectie paralela
glOrtho(l, r, b, t, n, f)
t
l
y
z
x
b
n
41
Proiectie
Volum de vizualizare
Proiectie paralela
Proiectie perspectiva
-w<=x<=w
-w<=y<=w
-w<=z<=w
42
Impartirea perspectiva
-1<=x<=1
-1<=y<=1
-1<=z<=1
43
glViewport(px,py,w,h)
w
poarta de
afisare
(px,py)
44
Matrici de transformare
glMatrixMode(mod)
GL_MODELVIEW
GL_PROJECTION
GL_TEXTURE
void glLoadIdentity();
void glLoadMatrix{fd}(const TYPE *m);
void glMultMatrix{fd}(const TYPE *m);
45
Atribute de afisare
void glPointSize(GLfloat dim);
void glLineWidth(GLfloat w);
void glLineStipple(GLint factor, GLushort sablon);
glEnable(GL_LINE_STIPPLE)
glDisable(GL_LINE_STIPPLE)
46
Afisarea poligoanelor
void glPolygonMode( GLenum fata, GLenum mod );
fata: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
mod: GL_POINT, GL_LINE, or GL_FILL
glEnable(GL_CULL_FACE);
glDisable(GL_CULL_FACE);
47
Culori
glColor3f(R, G, B);
glColor4f(R, G, B, A);
(x2,y2,z2)
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(x0,y0,z0);
glColor3f(0,0,1);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glEnd();
(x0,y0,z0)
(x1,y1,z1)
48
Terminarea desenarii
Terminarea desenarii
glFlush()
glFinish()
49
50
Ferestre
evenimente de la mouse, tastatura,
reafisarea ferestrelor
Meniuri
51
Initializare
53
Stergerea ferestrei
Stergerea bufferului de culoare
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
sau
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(0.0 );
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
54
55
Tipuri de evenimente
Modificarea ferestrei
Apasare buton mouse
Deplasare mouse
Apasare/eliberare tasta
Idle
56
Coada de mesaje
Coada de mesaje
Tastatura
.
Mouse
MainLoop()
Fereastra
Mouse_callback()
{
.
{
Keypress_callback()
{
.
{
window_callback()
{
.
{
57
glutMainLoop
repeta
if eveniment tastatura then
apeleaza functia inregistrata pentru tastatura
else if eveniment mouse then
apeleaza functia inregistrata pentru mouse
else if fereastra trebuie redesenata then
apeleaza functia inregistrata pentru afisare
...
else if nu este nimic de tratat then
apeleaza functia idle inregistrata
58
Afisare
void glutDisplayFunc(void (*func)(void));
Redimensionare fereastra
void glutReshapeFunc(void (*func)(int w, int h));
Eveimente de la tastatura
void glutKeyboardFunc(void (*func)(unsigned char key,
int x, int y)) ;
59
Evenimente de la mouse
apasarea/eliberearea unui buton al mouse-ului
void glutMouseFunc(void (*func)(int buton, int stare,
int x, int y)) ;
deplasarea mouse-ului avand unul sau mai multe
butoane apasate / fara a avea butoanele apasate
void glutMotionFunc(void (*func)(int x, int y)) ;
void glutPassiveMotionFunc(void (*func)(int x, int y)) ;
60
61
Fereastra aplicatiei
h
O
x
w
63
Exemplu
void display(void) {
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex3f (-0.25, -0.25, 0.0);
glVertex3f (0.25, -0.25, 0.0);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (-0.25, 0.25, 0.0);
glEnd();
glFlush ();
}
void init (void) {
glClearColor (0.0, 0.0, 0.0, 0.0);
}
64
Exemplu
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Primul Program");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
65