Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include <gl/freeglut.h>
- double i = 0.0;
- double j = 0.0;
- double alpha = 0.5;
- double alpha2 = 1;
- void init(void)
- {
- glClearColor(1.0, 1.0, 1.0, 0.0);
- glMatrixMode(GL_PROJECTION);
- glOrtho(-20.0, 780.0, 0.0, 600.0, -1.0, 1.0);
- }
- void deseneazaScena(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glLineWidth(6.0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- // CENTRUL DE GREUTATE
- glColor3f(0, 0, 0);
- glPointSize(10);
- glEnable(GL_POINT_SMOOTH);
- glBegin(GL_POINTS);
- glVertex2f(300, 200);
- glEnd();
- // APLICAREA TRANSFORMARII ASUPRA TRIUNGHIULUI
- glPushMatrix();
- glTranslated(300, 200, 0);
- glScaled(j, j, j);
- glRotated(i, 0, 0, 1);
- glTranslated(-300, -200, 0);
- glBegin(GL_TRIANGLES);
- glColor3f(0, 0, 1);
- glVertex2f(100, 100);
- glColor3f(0, 1, 0);
- glVertex2f(500, 100);
- glColor3f(1, 0, 0);
- glVertex2f(300, 400);
- glEnd();
- glPopMatrix();
- glutSwapBuffers();
- glFlush();
- }
- void reshape(int w, int h)
- {
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-20.0, 780.0, 0.0, 600.0, -1.0, 1.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void miscad(void)
- {
- i = i + alpha;
- if (i > 750.0)
- alpha = -0.5;
- else if (i < 0.0)
- alpha = 0.5;
- j = j + alpha2;
- if (j > 1)
- alpha2 = -0.3;
- else if (j < 0.1)
- alpha2 = 0.3;
- glutPostRedisplay();
- }
- void miscas(void)
- {
- i = i + alpha;
- if (i < 0.0)
- alpha = 0.5;u
- else if (i > 750.0)
- alpha = -0.5;
- j = j + alpha2;
- if (j > 1)
- alpha2 = -0.3;
- else if (j < 0.1)
- alpha2 = 0.3;
- glutPostRedisplay();
- }
- void mouse(int button, int state, int x, int y)
- {
- switch (button) {
- case GLUT_LEFT_BUTTON:
- if (state == GLUT_DOWN)
- alpha = -0.5; glutIdleFunc(miscas);
- break;
- case GLUT_RIGHT_BUTTON:
- if (state == GLUT_DOWN)
- alpha = 0.5; glutIdleFunc(miscad);
- break;
- default:
- break;
- }
- }
- void main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(800, 600);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Triunghi rotitor scalat");
- init();
- glutDisplayFunc(deseneazaScena);
- glutReshapeFunc(reshape);
- glutMouseFunc(mouse);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment