Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GL/glut.h>
- #include <math.h>
- const theta = -30;
- const PI = 3.1415;
- void draw(){
- glBegin(GL_LINE_LOOP);
- glVertex2d(1,1);
- glVertex2d(2,2);
- glVertex2d(1,3);
- glVertex2d(0,2);
- glEnd();
- }
- void display(void){
- double c,s;
- c = cos(PI*theta/180.0);
- s = sin(PI*theta/180.0);
- // Vai para origem
- double matrix_origin[16]={1.0,0,0,0,
- 0,1.0,0,0,
- 0,0,1.0,0,
- -1.0,-1.0,0,1};
- // pos inicial
- double matrix_init[16]={1.0,0,0,0,
- 0,1.0,0,0,
- 0,0,1.0,0,
- 1.0,1.0,0,1};
- // rotaciona em z
- double matrixRZ[16]={c,s,0,0,
- -s,c,0,0,
- 0,0,1,0,
- 0,0,0,1};
- glClearColor (1.0, 1.0, 1.0, 0.0);
- glClear (GL_COLOR_BUFFER_BIT);
- glColor3f (0.0, 0.0, 0.0);
- glLoadIdentity ();
- draw();
- glPushMatrix();
- glMultMatrixd(matrix_init);
- glMultMatrixd(matrixRZ);
- glMultMatrixd(matrix_origin);
- draw();
- glPopMatrix();
- glFlush ();
- }
- void reshape(int w, int h){
- glViewport (0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
- gluOrtho2D (-10.0, 10.0, -10.0, 10.0);
- glMatrixMode (GL_MODELVIEW);
- }
- int main(int argc, char** argv){
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize (500,440);
- glutInitWindowPosition (10, 10);
- glutCreateWindow (argv[0]);
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement