Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1125 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  OpenGL avec C++ stack pour transformation

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

OpenGL avec C++ stack pour transformation

n°988901
nimo
New.Internet.Master.Operator
Posté le 21-02-2005 à 18:26:47  profilanswer
 

Salut a tous,
 
Je travail avec OpenGL et Glut avec C++ (VC)
je voudrai faire un program qui montre mes 2 intials on 3D mais aussi la possibliter de faire les transformation avec les intials
 
 
Pour etre plus clair voila mon code:
je suis sur londres, desoler pour l'anglai  :p  
Ce code montre mes deux initial avec la possibliter de les faire tourner sur le click de la sourie
 
Mais je voudrai avec une scene qui fera les transformations et si un bouton et pressed de faire la transformation de retour pour avec la position d'origne. peu etre qu'un stack peu etre utiliser ?
 
 

Code :
  1. #include <stdlib.h>
  2. #include <GL/glut.h>
  3. // Definned but not used so far ...
  4. #define RED 1
  5. #define GREEN 2
  6. #define BLUE 3
  7. #define WHITE 4
  8. // Double array of undefined first and defined second
  9. GLfloat vertices[][3] =
  10. {
  11. /********************************************************* A LETTER **************************************************/
  12. /* first face
  13. /*0*/ {-1.0,-0.60,/**/-1.0},
  14. /*1*/ {-0.80,-0.60,/**/-1.0},
  15. /*2*/ {-0.80,0.60,/**/-1.0},
  16. /*3*/ {-1.0,0.60,/**/-1.0},
  17. /*4*/ {-0.80,-0.20,/**/-1.0},
  18. /*5*/ {-0.40,-0.20,/**/-1.0},
  19. /*6*/ {-0.40,0.00,/**/-1.0},
  20. /*7*/ {-0.80,0.00,/**/-1.0},
  21. /*8*/ {-0.80,0.40,/**/-1.0},
  22. /*9*/ {-0.40,0.40,/**/-1.0},
  23. /*10*/ {-0.40,0.60,/**/-1.0},
  24. /*11*/ {-0.80,0.60,/**/-1.0},
  25.  
  26. /*12*/ {-0.40,-0.60,/**/-1.0},
  27. /*13*/ {-0.20,-0.60,/**/-1.0},
  28. /*14*/ {-0.20,0.60,/**/-1.0},
  29. /*15*/ {-0.40,0.60,/**/-1.0},
  30. /* second face
  31. /*16*/ {-1.0,-0.60,/**/-0.50},
  32. /*17*/ {-0.80,-0.60,/**/-0.50},
  33. /*18*/ {-0.80,0.60,/**/-0.50},
  34. /*19*/ {-1.0,0.60,/**/-0.50},
  35.  
  36. /*20*/ {-0.80,-0.20,/**/-0.50},
  37. /*21*/ {-0.40,-0.20,/**/-0.50},
  38. /*22*/ {-0.40,0.00,/**/-0.50},
  39. /*23*/ {-0.80,0.00,/**/-0.50},
  40.  
  41. /*24*/ {-0.80,0.40,/**/-0.50},
  42. /*25*/ {-0.40,0.40,/**/-0.50},
  43. /*26*/ {-0.40,0.60,/**/-0.50},
  44. /*27*/ {-0.80,0.60,/**/-0.50},
  45. /*28*/ {-0.40,-0.60,/**/-0.50},
  46. /*29*/ {-0.20,-0.60,/**/-0.50},
  47. /*30*/ {-0.20,0.60,/**/-0.50},
  48. /*31*/ {-0.40,0.60,/**/-0.50},
  49. /********************************************************* N LETTER **************************************************/
  50.  
  51. /* first face
  52. /*32*/ {0.20,-0.60,/**/-1.0},
  53. /*33*/ {0.40,-0.60,/**/-1.0},
  54. /*34*/ {0.40,0.60,/**/-1.0},
  55. /*35*/ {0.20,0.60,/**/-1.0},
  56. /*36*/ {0.40,0.20,/**/-1.0},
  57. /*37*/ {0.80,-0.60,/**/-1.0},
  58. /*38*/ {0.80,-0.20,/**/-1.0},
  59. /*39*/ {0.40,0.60,/**/-1.0},
  60. /*40*/ {0.80,-0.60,/**/-1.0},
  61. /*41*/ {1.0,-0.60,/**/-1.0},
  62. /*42*/ {1.0,0.60,/**/-1.0},
  63. /*43*/ {0.80,0.60,/**/-1.0},
  64.  
  65. /* second face
  66. /*44*/ {0.20,-0.60,/**/-0.50},
  67. /*45*/ {0.40,-0.60,/**/-0.50},
  68. /*46*/ {0.40,0.60,/**/-0.50},
  69. /*47*/ {0.20,0.60,/**/-0.50},
  70.  
  71. /*48*/ {0.40,0.20,/**/-0.50},
  72. /*49*/ {0.80,-0.60,/**/-0.50},
  73. /*50*/ {0.80,-0.20,/**/-0.50},
  74. /*51*/ {0.40,0.60,/**/-0.50},
  75.  
  76. /*52*/ {0.80,-0.60,/**/-0.50},
  77. /*53*/ {1.0,-0.60,/**/-0.50},
  78. /*54*/ {1.0,0.60,/**/-0.50},
  79. /*55*/ {0.80,0.60,/**/-0.50}
  80. };
  81. /************************************************* Color settings *****************************************************/
  82. GLfloat colors[][3] =  
  83. {
  84. /*0*/ {0.0, 0.0, 0.0},
  85. /*1*/ {1.0, 0.0, 0.0},
  86. /*2*/ {1.0, 1.0, 0.0},
  87. /*3*/ {0.0, 1.0, 0.0},
  88. /*4*/ {0.0, 0.0, 1.0},
  89. /*5*/ {1.0, 0.0, 1.0},
  90. /*6*/ {1.0, 1.0, 1.0},
  91. /*7*/ {0.0, 1.0, 1.0},
  92. /*8*/ {0.0, 0.0, 0.25},
  93. /*9*/ {1.0, 0.50, 0.0},
  94. /*10*/ {1.0, 1.0, 0.25},
  95. /*11*/ {0.25, 1.0, 0.0},
  96. /*12*/ {0.0, 0.50, 1.0},
  97. /*13*/ {1.0, 0.75, 1.0},
  98. /*14*/ {1.0, 1.0, 1.0},
  99. /*15*/ {0.75, 1.0, 1.0},
  100. /*16*/ {0.0, 0.75, 0.0},
  101. /*17*/ {1.0, 0.25, 0.0},
  102. /*18*/ {1.0, 1.0, 0.0},
  103. /*19*/ {0.25, 1.0, 0.0},
  104. /*20*/ {0.0, 0.50, 1.0},
  105. /*21*/ {1.0, 0.25, 1.0},
  106. /*22*/ {1.0, 1.0, 1.0},
  107. /*23*/ {0.25, 1.0, 1.0},
  108. /*24*/ {0.0, 0.0, 0.75},
  109. /*25*/ {1.0, 0.75, 0.0},
  110. /*26*/ {1.0, 1.0, 0.0},
  111. /*27*/ {0.50, 1.0, 0.0},
  112. /*28*/ {0.0, 0.25, 1.0},
  113. /*29*/ {1.0, 0.50, 1.0},
  114. /*30*/ {1.0, 1.0, 1.0},
  115. /*31*/ {0.50, 1.0, 1.0},
  116. /*32*/ {0.0, 0.0, 0.75},
  117. /*33*/ {1.0, 0.75, 0.0},
  118. /*34*/ {1.0, 1.0, 0.0},
  119. /*35*/ {0.50, 1.0, 0.0},
  120. /*36*/ {0.0, 0.25, 1.0},
  121. /*37*/ {1.0, 0.50, 1.0},
  122. /*38*/ {1.0, 1.0, 1.0},
  123. /*39*/ {0.50, 1.0, 1.0},
  124. /*40*/ {0.0, 0.75, 0.0},
  125. /*41*/ {1.0, 0.25, 0.0},
  126. /*42*/ {1.0, 1.0, 0.0},
  127. /*43*/ {0.25, 1.0, 0.0},
  128. /*44*/ {0.0, 0.50, 1.0},
  129. /*45*/ {1.0, 0.25, 1.0},
  130. /*46*/ {1.0, 1.0, 1.0},
  131. /*47*/ {0.25, 1.0, 1.0},
  132. /*48*/ {0.0, 0.75, 0.0},
  133. /*49*/ {1.0, 0.25, 0.0},
  134. /*50*/ {1.0, 1.0, 0.0},
  135. /*51*/ {0.25, 1.0, 0.0},
  136. /*52*/ {0.0, 0.50, 1.0},
  137. /*53*/ {1.0, 0.25, 1.0},
  138. /*54*/ {1.0, 1.0, 1.0},
  139. /*55*/ {0.25, 1.0, 1.0}
  140. };
  141. void polygon(int a, int b, int c , int d)
  142. {
  143. /* draw a polygon via list of vertices */
  144. //  glShadeModel(GL_SMOOTH);
  145.  glBegin(GL_POLYGON);
  146.  glColor3fv(colors[a]);
  147.  glVertex3fv(vertices[a]);
  148.  glColor3fv(colors[b]);
  149.  glVertex3fv(vertices[b]);
  150.  glColor3fv(colors[c]);
  151.  glVertex3fv(vertices[c]);
  152.  glColor3fv(colors[d]);
  153.  glVertex3fv(vertices[d]);
  154. glEnd();
  155. }
  156. void colorcube(void)
  157. {
  158. /* map vertices to faces */
  159. /************************************************* POLYGONES FOR A ********************************************************/
  160. /*1*/ polygon(0,1,2,3);
  161.  polygon(1,17,18,2);
  162.  polygon(3,19,16,0);
  163.  polygon(16,17,18,19);
  164.  polygon(0,1,17,16);
  165.  polygon(3,2,18,19);
  166. /*2*/ polygon(4,5,6,7);
  167.  polygon(7,6,22,23);
  168.  polygon(5,21,22,6);
  169.  polygon(4,20,23,7);
  170.  polygon(20,21,22,23);
  171.  polygon(4,5,21,20);
  172. /*3*/ polygon(8,9,10,11);
  173.  polygon(24,25,26,27);
  174.  polygon(8,24,27,11);
  175.  polygon(9,25,26,10);
  176.  polygon(8,9,25,24);
  177.  polygon(11,10,26,27);
  178. /*4*/ polygon(12,13,14,15);
  179.  polygon(28,29,30,31);
  180.  polygon(12,13,29,28);
  181.  polygon(15,14,30,31);
  182.  polygon(12,28,31,15);
  183.  polygon(13,29,30,14);
  184. /************************************************* POLYGONES FOR N ********************************************************/
  185. /*1*/ polygon(32,33,34,35);
  186.  polygon(44,45,46,47);
  187.  polygon(32,34,45,44);
  188.  polygon(35,34,46,47);
  189.  polygon(34,46,45,33);
  190.  polygon(44,32,35,47);
  191. /*2*/ polygon(36,37,38,39);
  192.  polygon(48,49,50,51);
  193.  polygon(36,37,49,48);
  194.  polygon(51,50,38,39);
  195.  polygon(36,39,51,48);
  196.  polygon(37,49,50,38);
  197. /*3*/ polygon(40,41,42,43);
  198.  polygon(52,53,54,55);
  199.  polygon(40,41,53,52);
  200.  polygon(43,42,54,55);
  201.  polygon(41,53,54,42);
  202.  polygon(52,40,43,55);
  203. }
  204. static GLfloat theta[] = {0.0,0.0,0.0};
  205. static GLint axis = 2;
  206. void display(void)
  207. {
  208. /* display callback, clear frame buffer and z buffer,
  209.    rotate cube and draw, swap buffers */
  210. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  211. glLoadIdentity();
  212. glRotatef(theta[0], 1.0, 0.0, 0.0);
  213. glRotatef(theta[1], 0.0, 1.0, 0.0);
  214. glRotatef(theta[2], 0.0, 0.0, 1.0);
  215. colorcube();
  216. glFlush();
  217. glutSwapBuffers();
  218. }
  219. void spinCube()
  220. {
  221. /* Idle callback, spin cube 2 degrees about selected axis */
  222. theta[axis] += 2.0;
  223. if( theta[axis] > 360.0 ) theta[axis] -= 360.0;
  224. /* display(); */
  225. glutPostRedisplay();
  226. }
  227. void mouse(int btn, int state, int x, int y)
  228. {
  229. /* mouse callback, selects an axis about which to rotate */
  230. if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis = 0;
  231. if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) axis = 1;
  232. if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN) axis = 2;
  233. }
  234. void myReshape(int w, int h)
  235. {
  236.     glViewport(0, 0, w, h);
  237.     glMatrixMode(GL_PROJECTION);
  238.     glLoadIdentity();
  239.     if (w <= h)
  240.         glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
  241.             2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
  242.     else
  243.         glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
  244.             2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
  245.     glMatrixMode(GL_MODELVIEW);
  246. }
  247. void
  248. main(int argc, char **argv)
  249. {
  250.     glutInit(&argc, argv);
  251. /* need both double buffering and z buffer */
  252.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  253.     glutInitWindowSize(500, 500);
  254.     glutCreateWindow("colorcube" );
  255.     glutReshapeFunc(myReshape);
  256.     glutDisplayFunc(display);
  257. glutIdleFunc(spinCube);
  258. glutMouseFunc(mouse);
  259. glEnable(GL_DEPTH_TEST); /* Enable hidden--surface--removal */
  260.     glutMainLoop();
  261. }
  262. // END OF PROGRAM


 
 
J'esper que quequ'un peu m'aider svp ?
 
Merci


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
mood
Publicité
Posté le 21-02-2005 à 18:26:47  profilanswer
 

n°989010
nimo
New.Internet.Master.Operator
Posté le 21-02-2005 à 19:44:00  profilanswer
 

Person ? :(


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
n°989077
bjone
Insert booze to continue
Posté le 21-02-2005 à 20:30:19  profilanswer
 

bin heuuuuu.....
 
prends 3DSMax, Blender ou Maya
et exporte tes initiales dans un fichier texte, tu te feras moins chier.

n°989154
Zeross
Posté le 21-02-2005 à 20:58:51  profilanswer
 

bjone a écrit :

bin heuuuuu.....
 
prends 3DSMax, Blender ou Maya
et exporte tes initiales dans un fichier texte, tu te feras moins chier.


 
 
Encore plus simple : GlutStrokeCharacter  voire wglUseFontOutline.
 
Mais je ne crois pas que ce soit la question, ceci dit vu que je ne l'ai pas vraiment comprise non plus j'aurais du mal à proposer une solution au problème. Si tu veux revenir à la position initiale tu remets les 3 angles à 0 enfin j'ai vraiment pas du comprendre vu que je ne vois même pas le problème  :??:

n°991604
nimo
New.Internet.Master.Operator
Posté le 23-02-2005 à 17:37:46  profilanswer
 

Merci pour votre reponse,
 
mais mon problem n'est pas de cree les lettres, j'ai cree les 2 initials avec leur coordonees on 3D comme le code le montre, mon problem vien au stage des transformations:
 
je voudrai faire une sequence de scalling, rotation mais aussi de translation, apres que c'est transformation sont faite je voudrai avoir une sequance qui fasse ces exact transformation mais en sence inverse.
 
Es ce que c'est un peu plus clair?
 
Tout commentaire sont bienvenue
 
Merci


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
n°993618
nimo
New.Internet.Master.Operator
Posté le 25-02-2005 à 15:49:37  profilanswer
 

Salut,
 
J'ai mis en place les transformation, mais je voudrai que quequ'un me dise comment je peu faire pour que ma function sequence() fonctionne correctement ?  
 
SVP, merci :)
 

Code :
  1. #include <stdlib.h>
  2. #include <GL/glut.h>
  3. void init(void);
  4. void display(void);
  5. void keyboard(unsigned char, int, int);
  6. void resize(int, int);
  7. int is_depth; /* depth testing flag */
  8. int frame=0;
  9. // Double array of undefined first and defined second
  10. GLfloat vertices[][3] =
  11. {
  12. /********************************************************* A LETTER **************************************************/
  13. /* first face
  14. /*0*/ {-1.0,-0.60,/**/-1.0},
  15. /*1*/ {-0.80,-0.60,/**/-1.0},
  16. /*2*/ {-0.80,0.60,/**/-1.0},
  17. /*3*/ {-1.0,0.60,/**/-1.0},
  18. /*4*/ {-0.80,-0.20,/**/-1.0},
  19. /*5*/ {-0.40,-0.20,/**/-1.0},
  20. /*6*/ {-0.40,0.00,/**/-1.0},
  21. /*7*/ {-0.80,0.00,/**/-1.0},
  22. /*8*/ {-0.80,0.40,/**/-1.0},
  23. /*9*/ {-0.40,0.40,/**/-1.0},
  24. /*10*/ {-0.40,0.60,/**/-1.0},
  25. /*11*/ {-0.80,0.60,/**/-1.0},
  26.  
  27. /*12*/ {-0.40,-0.60,/**/-1.0},
  28. /*13*/ {-0.20,-0.60,/**/-1.0},
  29. /*14*/ {-0.20,0.60,/**/-1.0},
  30. /*15*/ {-0.40,0.60,/**/-1.0},
  31. /* second face
  32. /*16*/ {-1.0,-0.60,/**/-0.50},
  33. /*17*/ {-0.80,-0.60,/**/-0.50},
  34. /*18*/ {-0.80,0.60,/**/-0.50},
  35. /*19*/ {-1.0,0.60,/**/-0.50},
  36.  
  37. /*20*/ {-0.80,-0.20,/**/-0.50},
  38. /*21*/ {-0.40,-0.20,/**/-0.50},
  39. /*22*/ {-0.40,0.00,/**/-0.50},
  40. /*23*/ {-0.80,0.00,/**/-0.50},
  41.  
  42. /*24*/ {-0.80,0.40,/**/-0.50},
  43. /*25*/ {-0.40,0.40,/**/-0.50},
  44. /*26*/ {-0.40,0.60,/**/-0.50},
  45. /*27*/ {-0.80,0.60,/**/-0.50},
  46. /*28*/ {-0.40,-0.60,/**/-0.50},
  47. /*29*/ {-0.20,-0.60,/**/-0.50},
  48. /*30*/ {-0.20,0.60,/**/-0.50},
  49. /*31*/ {-0.40,0.60,/**/-0.50},
  50. /********************************************************* N LETTER **************************************************/
  51.  
  52. /* first face
  53. /*32*/ {0.20,-0.60,/**/-1.0},
  54. /*33*/ {0.40,-0.60,/**/-1.0},
  55. /*34*/ {0.40,0.60,/**/-1.0},
  56. /*35*/ {0.20,0.60,/**/-1.0},
  57. /*36*/ {0.40,0.20,/**/-1.0},
  58. /*37*/ {0.80,-0.60,/**/-1.0},
  59. /*38*/ {0.80,-0.20,/**/-1.0},
  60. /*39*/ {0.40,0.60,/**/-1.0},
  61. /*40*/ {0.80,-0.60,/**/-1.0},
  62. /*41*/ {1.0,-0.60,/**/-1.0},
  63. /*42*/ {1.0,0.60,/**/-1.0},
  64. /*43*/ {0.80,0.60,/**/-1.0},
  65.  
  66. /* second face
  67. /*44*/ {0.20,-0.60,/**/-0.50},
  68. /*45*/ {0.40,-0.60,/**/-0.50},
  69. /*46*/ {0.40,0.60,/**/-0.50},
  70. /*47*/ {0.20,0.60,/**/-0.50},
  71.  
  72. /*48*/ {0.40,0.20,/**/-0.50},
  73. /*49*/ {0.80,-0.60,/**/-0.50},
  74. /*50*/ {0.80,-0.20,/**/-0.50},
  75. /*51*/ {0.40,0.60,/**/-0.50},
  76.  
  77. /*52*/ {0.80,-0.60,/**/-0.50},
  78. /*53*/ {1.0,-0.60,/**/-0.50},
  79. /*54*/ {1.0,0.60,/**/-0.50},
  80. /*55*/ {0.80,0.60,/**/-0.50}
  81. };
  82. /************************************************* Color settings *****************************************************/
  83. GLfloat colors[][3] =  
  84. {
  85. // Color for A
  86. /*0*/ {0.0, 0.0, 1.0}, // Blue
  87. /*1*/ {0.0, 0.0, 1.0},
  88. /*2*/ {0.0, 0.0, 1.0},
  89. /*3*/ {0.0, 0.0, 1.0},
  90. /*4*/ {0.0, 0.0, 1.0},
  91. /*5*/ {0.0, 0.0, 1.0},
  92. /*6*/ {0.0, 0.0, 1.0},
  93. /*7*/ {0.0, 0.0, 1.0},
  94. /*8*/ {0.0, 0.0, 1.0},
  95. /*9*/ {0.0, 0.0, 1.0},
  96. /*10*/ {0.0, 0.0, 1.0},
  97. /*11*/ {0.0, 0.0, 1.0},
  98. /*12*/ {0.0, 0.0, 1.0},
  99. /*13*/ {0.0, 0.0, 1.0},
  100. /*14*/ {0.0, 0.0, 1.0},
  101. /*15*/ {0.0, 0.0, 1.0},
  102. /*16*/ {0.0, 1.0, 0.0}, // Green
  103. /*17*/ {0.0, 1.0, 0.0},
  104. /*18*/ {0.0, 1.0, 0.0},
  105. /*19*/ {0.0, 1.0, 0.0},
  106. /*20*/ {0.0, 1.0, 0.0},
  107. /*21*/ {0.0, 1.0, 0.0},
  108. /*22*/ {0.0, 1.0, 0.0},
  109. /*23*/ {0.0, 1.0, 0.0},
  110. /*24*/ {0.0, 1.0, 0.0},
  111. /*25*/ {0.0, 1.0, 0.0},
  112. /*26*/ {0.0, 1.0, 0.0},
  113. /*27*/ {0.0, 1.0, 0.0},
  114. /*28*/ {0.0, 1.0, 0.0},
  115. /*29*/ {0.0, 1.0, 0.0},
  116. /*30*/ {0.0, 1.0, 0.0},
  117. /*31*/ {0.0, 1.0, 0.0},
  118. // Color for N
  119. /*32*/ {1.0, 1.0, 0.0}, // Yellow
  120. /*33*/ {1.0, 1.0, 0.0},
  121. /*34*/ {1.0, 1.0, 0.0},
  122. /*35*/ {1.0, 1.0, 0.0},
  123. /*36*/ {1.0, 1.0, 0.0},
  124. /*37*/ {1.0, 1.0, 0.0},
  125. /*38*/ {1.0, 1.0, 0.0},
  126. /*39*/ {1.0, 1.0, 0.0},
  127. /*40*/ {1.0, 1.0, 0.0},
  128. /*41*/ {1.0, 1.0, 0.0},
  129. /*42*/ {1.0, 1.0, 0.0},
  130. /*43*/ {1.0, 1.0, 0.0},
  131. /*44*/ {1.0, 0.0, 0.0}, // Red
  132. /*45*/ {1.0, 0.0, 0.0},
  133. /*46*/ {1.0, 0.0, 0.0},
  134. /*47*/ {1.0, 0.0, 0.0},
  135. /*48*/ {1.0, 0.0, 0.0},
  136. /*49*/ {1.0, 0.0, 0.0},
  137. /*50*/ {1.0, 0.0, 0.0},
  138. /*51*/ {1.0, 0.0, 0.0},
  139. /*52*/ {1.0, 0.0, 0.0},
  140. /*53*/ {1.0, 0.0, 0.0},
  141. /*54*/ {1.0, 0.0, 0.0},
  142. /*55*/ {1.0, 0.0, 0.0}
  143. };
  144. void polygon(int a, int b, int c , int d)
  145. {
  146. /* draw a polygon via list of vertices */
  147.     glShadeModel(GL_SMOOTH);
  148.  glBegin(GL_POLYGON);
  149.  glColor3fv(colors[a]);
  150.  glVertex3fv(vertices[a]);
  151.  glColor3fv(colors[b]);
  152.  glVertex3fv(vertices[b]);
  153.  glColor3fv(colors[c]);
  154.  glVertex3fv(vertices[c]);
  155.  glColor3fv(colors[d]);
  156.  glVertex3fv(vertices[d]);
  157. glEnd();
  158. }
  159. void nimo(void)
  160. {
  161. /* map vertices to faces */
  162. /************************************************* POLYGONES FOR A ********************************************************/
  163. /*1*/ polygon(0,1,2,3);
  164.  polygon(1,17,18,2);
  165.  polygon(3,19,16,0);
  166.  polygon(16,17,18,19);
  167.  polygon(0,1,17,16);
  168.  polygon(3,2,18,19);
  169. /*2*/ polygon(4,5,6,7);
  170.  polygon(7,6,22,23);
  171.  polygon(5,21,22,6);
  172.  polygon(4,20,23,7);
  173.  polygon(20,21,22,23);
  174.  polygon(4,5,21,20);
  175. /*3*/ polygon(8,9,10,11);
  176.  polygon(24,25,26,27);
  177.  polygon(8,24,27,11);
  178.  polygon(9,25,26,10);
  179.  polygon(8,9,25,24);
  180.  polygon(11,10,26,27);
  181. /*4*/ polygon(12,13,14,15);
  182.  polygon(28,29,30,31);
  183.  polygon(12,13,29,28);
  184.  polygon(15,14,30,31);
  185.  polygon(12,28,31,15);
  186.  polygon(13,29,30,14);
  187. /************************************************* POLYGONES FOR N ********************************************************/
  188. /*1*/ polygon(32,33,34,35);
  189.  polygon(44,45,46,47);
  190.  polygon(32,33,45,44);
  191.  polygon(35,34,46,47);
  192.  polygon(34,46,45,33);
  193.  polygon(44,32,35,47);
  194. /*2*/ polygon(36,37,38,39);
  195.  polygon(48,49,50,51);
  196.  polygon(36,37,49,48);
  197.  polygon(51,50,38,39);
  198.  polygon(36,39,51,48);
  199.  polygon(37,49,50,38);
  200. /*3*/ polygon(40,41,42,43);
  201.  polygon(52,53,54,55);
  202.  polygon(40,41,53,52);
  203.  polygon(43,42,54,55);
  204.  polygon(41,53,54,42);
  205.  polygon(52,40,43,55);
  206. }
  207. // Keyboard input from user for transformation
  208. void keyboard(unsigned char key, int x, int y)
  209. {
  210. switch (key)
  211. {
  212. /******************************************** Translate ***************************************************/
  213. case 'd': //"d": move right
  214. case 'D':
  215.  glTranslatef(0.10, 0.0, 0.0);
  216.  break;
  217. case 'a': //"a": move left
  218. case 'A':
  219.  glTranslatef(-0.10, 0.0, 0.0);
  220.  break;
  221. case 'w': //"w": move up
  222. case 'W':
  223.  glTranslatef(0.0, 0.10, 0.0);
  224.  break;
  225. case 's': //"s": move down
  226. case 'S':
  227.  glTranslatef(0.0, -0.10, 0.0);
  228.  break;
  229. /************************************************** Rotate ********************************************************/
  230. case 'u':
  231. case 'U':
  232.  glRotatef(3.0, 1.0, 0.0, 0.0); /* rotate up */
  233.  break;
  234. case 'j':
  235. case 'J':
  236.  glRotatef(-3.0, 1.0, 0.0, 0.0); /* rotate down */
  237.  break;
  238. case 'i':
  239. case 'I':
  240.  glRotatef(3.0, 0.0, 1.0, 0.0); /* rotate left */
  241.  break;
  242. case 'k':
  243. case 'K':
  244.  glRotatef(-3.0, 0.0, 1.0, 0.0); /* rotate right */
  245.  break;
  246. case 'o':
  247. case 'O':
  248.  glRotatef(3.0, 0.0, 0.0, 1.0); /* rotate left */
  249.  break;
  250. case 'l':
  251. case 'L':
  252.  glRotatef(-3.0, 0.0, 0.0, 1.0); /* rotate right */
  253.  break;
  254. /********************************************** Scale *************************************************/
  255. case 'g':
  256. case 'G':
  257.  glScalef(1.10, 1.10, 1.10);
  258.  break;
  259. case 'b':
  260. case 'B':
  261.  glScalef(0.90, 0.90, 0.90);
  262.  break;
  263. /***************************************** Depth on or off **********************************************/
  264. case 't':
  265. case 'T':
  266.  if (is_depth)
  267.  {
  268.   is_depth = 0;
  269.   glDisable(GL_DEPTH_TEST);
  270.  }
  271.  else
  272.  {
  273.   is_depth = 1;
  274.   glEnable(GL_DEPTH_TEST);
  275.  }
  276. }
  277. display();
  278. }
  279. void sequence(void)
  280. {
  281. if ((frame >=0 ) && (frame <10))
  282. {
  283. glTranslatef(0.10, 0.0, 0.0);
  284. }
  285. else if ((frame >=10 ) && (frame <20))
  286. {
  287. glRotatef(-3.0, 0.0, 0.0, 1.0);
  288. }
  289. // glRotatef(-3.5, 0.0, 0.0, 1.0);
  290. // glTranslatef(0.50, 0.0, 0.0);
  291. frame ++;
  292. display();
  293. }
  294. void resize(int width, int height)
  295. {
  296. if (height == 0) height = 1;
  297.  
  298. glMatrixMode(GL_PROJECTION);
  299. glLoadIdentity();
  300. /* note we divide our width by our height to get the aspect ratio */
  301. gluPerspective(45.0, width / height, 1.0, 400.0);
  302. /* set initial position */
  303. glTranslatef(0.0, 1.0, -10.0);
  304. glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  305. glMatrixMode(GL_MODELVIEW);
  306. }
  307. void display(void)
  308. {
  309. /* display callback, clear frame buffer and z buffer,
  310.    rotate cube and draw, swap buffers */
  311. if (is_depth)
  312.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  313. else
  314.  glClear(GL_COLOR_BUFFER_BIT);
  315. nimo();
  316. glFlush();
  317. glutSwapBuffers();
  318. }
  319. int main (int argc, char **argv)
  320. {
  321. glutInit(&argc, argv);
  322. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  323. glutInitWindowSize(800, 600);
  324. glutInitWindowPosition(40, 40);
  325. glutCreateWindow("2219191: ALEXANDRE NALIN" );
  326. init();
  327. sequence();
  328. glutDisplayFunc(display);
  329. glutKeyboardFunc(keyboard);
  330. /* this time we're going to keep the aspect ratio
  331. constant by trapping the window resizes */
  332. glutReshapeFunc(resize); 
  333. glutMainLoop();
  334. return 0;
  335. }
  336. void init(void)
  337. {
  338. glClearColor(0.0, 0.0, 0.0, 0.0);
  339. glEnable(GL_DEPTH_TEST);
  340. is_depth = 1;
  341. glMatrixMode(GL_MODELVIEW);
  342. }
  343. // END OF PROGRAM


---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  OpenGL avec C++ stack pour transformation

 

Sujets relatifs
[OPENGL/C++] Rendu de pluiefenetre openGL qui se ferme pas ...
[openGl] threads[C-OpenGL] Qu'est ce que MESA ???
[C OpenGL] Ou trouver les sources de Quake 2 ?[MFC/OPENGL] Problème de chargement de texture
[openGL] problème de conpilation[OpenGL] Afficher une texture en mosaique
[OpenGL] Probleme avec le rouge ... [resolu]blender + opengl @ glut
Plus de sujets relatifs à : OpenGL avec C++ stack pour transformation


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR