View difference between Paste ID: RTrNKGek and JkwgSrBF
SHOW: | | - or go back to the newest paste.
1
2
/*  curbe_Bezier.c
3
 *  
4
 Programul utilizeaza evaluatorii pentru determinarea
5
 punctelor de pe curba Bezier
6
 */
7
#include "glos.h"
8
9
#include <GL/gl.h>
10
#include <glu.h>
11
#include <glaux.h>
12
13
void myinit(void);
14
void CALLBACK myReshape(GLsizei w, GLsizei h);
15
void CALLBACK display(void);
16
#define nr_puncte 4
17
18
GLfloat ctrlpoints[nr_puncte][3] = {			
19
	//sunt date coordonatele celor 4 puncte de control
20
    { -4.0, 0.0, 0.0}, { -3.0, 2.0, 0.0}, 
21
	{-1.0, 2.0, 0.0}, {0.0,0.0,0}  };
22
23
GLfloat ctrlpoints2[nr_puncte][3] = {			
24
	//sunt date coordonatele celor 4 puncte de control
25
    { 0.0, 0.0, 0.0}, { 1.0, -2.0, 0.0}, 
26
	{3.0, -2.0, 0.0}, {4.0,0.0,0}  };
27
28
29
30
void myinit(void)
31
{
32
    glClearColor(1.0, 1.0, 1.0, 1.0); //culoarea background-ului
33
    
34
/*functia defineste caracteristicile curbei:
35
-tipul punctelor de control date in vectorul ctrlpoints, si al
36
datelor de iesire generate de functia de evaluare glEvalCoord1f
37
-valorile extreme luate de parametrul u (0 si 1 in acst caz)
38
-numarul coordonatelor date pentru fiecare punct de control, in tabloul
39
ctrlpoints
40
-numarul punctelor de control pe baza carora se va determina ordinul curbei
41
(numar puncte-1)
42
-vectorul punctelor de control
43
   */
44
	
45
    glEnable(GL_MAP1_VERTEX_3);	//se valideaza un anumit tip de evaluare
46
    glShadeModel(GL_FLAT); 	//umbrire constanta pe poligoane
47
	glLineStipple (1, 0x0F0F);
48
}
49
50
void CALLBACK display(void)
51
{
52
    int i;
53
54
    glClear(GL_COLOR_BUFFER_BIT);
55
    glColor3f(0.0, 0.0, 0.0);
56
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);	//culoarea curenta de desenare
57
    glBegin(GL_LINE_STRIP);		//se deseneaza curba prin segmente de dreapta
58
    for (i = 0; i <= 30; i++) 
59
        glEvalCoord1f((GLfloat) i/30.0); //pentru cele 30 varfuri determinate de 
60
								// functia glEvalCoord1f
61
    glEnd();
62
63
	glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints2[0][0]);	//culoarea curenta de desenare
64
    glBegin(GL_LINE_STRIP);		//se deseneaza curba prin segmente de dreapta
65
    for (i = 0; i <= 30; i++) 
66
        glEvalCoord1f((GLfloat) i/30.0); //pentru cele 30 varfuri determinate de 
67
								// functia glEvalCoord1f
68
    glEnd();
69
    
70
	/* Se afiseaza punctele de control. */
71
    glPointSize(5.0);	// de dimensiune 5
72
    glColor3f(1.0, 0.0, 0.0);	// culoare rosie
73
    glBegin(GL_POINTS);
74
    for (i = 0; i < nr_puncte; i++) 
75
        glVertex3fv(&ctrlpoints[i][0]);
76
    glEnd();
77
78
		
79
	
80
	//poligonul caracteristic ?
81
82
83
	glEnable(GL_LINE_STIPPLE);
84
	glColor3f(1.0, 0.0, 1.0);
85
	glBegin (GL_LINE_STRIP);
86
	for (i=0; i<nr_puncte; i++)
87
		glVertex3fv(&ctrlpoints2[i][0]);
88
	glEnd(); 
89
	 glPointSize(5.0);	// de dimensiune 5
90
    glColor3f(1.0, 0.0, 0.0);	// culoare rosie
91
    glBegin(GL_POINTS);
92
    for (i = 0; i < nr_puncte; i++) 
93
        glVertex3fv(&ctrlpoints2[i][0]);
94
    glEnd();
95
96
		
97
	
98
	//poligonul caracteristic ?
99
	glEnable(GL_LINE_STIPPLE);
100
	glColor3f(1.0, 0.0, 1.0);
101
	glBegin (GL_LINE_STRIP);
102
	for (i=0; i<nr_puncte; i++)
103
		glVertex3fv(&ctrlpoints2[i][0]);
104
	glEnd(); 
105
106
    glFlush();
107
}
108
109
void CALLBACK myReshape(GLsizei w, GLsizei h)
110
{
111
    if (!h) return;
112
    glViewport(0, 0, w, h);
113
    glMatrixMode(GL_PROJECTION);
114
    glLoadIdentity();
115
    if (w <= h)
116
    glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
117
        5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
118
    else
119
    glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
120
        5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
121
    glMatrixMode(GL_MODELVIEW);
122
    glLoadIdentity();
123
}
124
125
int main(int argc, char** argv)
126
{
127
    auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
128
    auxInitPosition (0, 0, 500, 500);
129
    auxInitWindow ("Curbe Bezier");
130
    myinit();
131
    auxReshapeFunc (myReshape);
132
    auxMainLoop(display);
133
    return(0);
134
}