Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <GL/glut.h>
  4. #include <math.h>
  5.  
  6. const theta = -30;
  7. const PI = 3.1415;
  8.  
  9. void draw(){
  10.  
  11. glBegin(GL_LINE_LOOP);
  12.  
  13. glVertex2d(1,1);
  14. glVertex2d(2,2);
  15. glVertex2d(1,3);
  16. glVertex2d(0,2);
  17.  
  18. glEnd();
  19.  
  20. }
  21.  
  22.  
  23. void display(void){
  24.  
  25. double c,s;
  26.  
  27. c = cos(PI*theta/180.0);
  28. s = sin(PI*theta/180.0);
  29.  
  30. // Vai para origem
  31. double matrix_origin[16]={1.0,0,0,0,
  32. 0,1.0,0,0,
  33. 0,0,1.0,0,
  34. -1.0,-1.0,0,1};
  35.  
  36. // pos inicial
  37. double matrix_init[16]={1.0,0,0,0,
  38. 0,1.0,0,0,
  39. 0,0,1.0,0,
  40. 1.0,1.0,0,1};
  41. // rotaciona em z
  42. double matrixRZ[16]={c,s,0,0,
  43. -s,c,0,0,
  44. 0,0,1,0,
  45. 0,0,0,1};
  46.  
  47.  
  48. glClearColor (1.0, 1.0, 1.0, 0.0);
  49. glClear (GL_COLOR_BUFFER_BIT);
  50. glColor3f (0.0, 0.0, 0.0);
  51.  
  52. glLoadIdentity ();
  53. draw();
  54.  
  55. glPushMatrix();
  56. glMultMatrixd(matrix_init);
  57. glMultMatrixd(matrixRZ);
  58. glMultMatrixd(matrix_origin);
  59. draw();
  60. glPopMatrix();
  61.  
  62. glFlush ();
  63. }
  64.  
  65. void reshape(int w, int h){
  66.  
  67. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  68. glMatrixMode (GL_PROJECTION);
  69. glLoadIdentity ();
  70. //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
  71. gluOrtho2D (-10.0, 10.0, -10.0, 10.0);
  72. glMatrixMode (GL_MODELVIEW);
  73. }
  74.  
  75. int main(int argc, char** argv){
  76.  
  77. glutInit(&argc, argv);
  78. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  79.  
  80. glutInitWindowSize (500,440);
  81. glutInitWindowPosition (10, 10);
  82. glutCreateWindow (argv[0]);
  83.  
  84. glutDisplayFunc(display);
  85. glutReshapeFunc(reshape);
  86.  
  87. glutMainLoop();
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement