Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <math.h>
- #include <stdlib.h>
- #include <GL/freeglut.h>
- const double TWO_PI = 6.2831853;
- GLsizei winWidth = 700, winHeight = 700;
- GLuint regHex;
- static GLfloat rotTheta = 0.0;
- double i = 0.0;
- double j = 0.0;
- double alpha = 0.5;
- class scrPt
- {
- public:
- GLint x, y;
- };
- static 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);
- // axa de rostogolire in afara transformarii
- scrPt hexVertex;
- GLdouble hexTheta;
- GLint k;
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0, 0, 0);
- glBegin(GL_LINES);
- glVertex2i(-30, 100);
- glVertex2i(780, 100);
- glEnd();
- glPushMatrix();
- glTranslated(i, 100.0, 0.0);
- glPushMatrix();
- glRotated(i, 0, 0, 1);
- glTranslated(-i, -100.0, 0.0);
- glColor3f(1.0, 0.0, 0.0);
- glBegin(GL_POLYGON);
- for (k = 0; k < 6; k++)
- {
- hexTheta = TWO_PI * k / 6;
- hexVertex.x = i + 50 * cos(hexTheta);
- hexVertex.y = 100 + 50 * sin(hexTheta);
- glVertex2i(hexVertex.x, hexVertex.y);
- }
- glEnd();
- glPopMatrix();
- 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 + 1.0;
- glutPostRedisplay();
- }
- void miscas(void)
- {
- i = i + alpha;
- if (i < 0.0)
- alpha = 0.5;
- else if (i > 750.0)
- alpha = -0.5;
- j = j + 1.0;
- glutPostRedisplay();
- }
- void mouse(int button, int state, int x, int y)
- {
- switch (button) {
- case GLUT_LEFT_BUTTON:
- if (state == GLUT_DOWN)
- alpha = -1.0; glutIdleFunc(miscas);
- break;
- case GLUT_RIGHT_BUTTON:
- if (state == GLUT_DOWN)
- alpha = 1.0; 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("Patrat care se rostogoleste");
- init();
- glutDisplayFunc(deseneazaScena);
- glutReshapeFunc(reshape);
- glutMouseFunc(mouse);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment