Advertisement
Guest User

Untitled

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