Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdlib.h>
- #if defined(__APPLE__)
- #include <OpenGL/gl.h>
- #include <OpenGL/glu.h>
- #include <GLUT/glut.h>
- #else
- #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
- #include <windows.h>
- #endif
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #endif
- struct Vector {
- float x, y;
- Vector(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
- };
- Vector trans(0, 0), scale(1, 1);
- float angle;
- void onInitialization() {
- glMatrixMode(GL_PROJECTION);
- gluOrtho2D(-5, 5, -5, 5);
- }
- void onDisplay() {
- glClear(GL_COLOR_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- // Eltolás a megadott vektorral
- glTranslatef(trans.x, trans.y, 0);
- // Z tengely azaz (0, 0, 1) vektor körüli forgatás
- // A szöget fokban várja nem radiánban.
- glRotatef(angle, 0, 0, 1);
- // Skálázás (nagyítás), koordinátánként.
- glScalef(scale.x, scale.y, 1);
- glLineWidth(1);
- glBegin(GL_LINES); {
- // Négyzetrács
- for(int i = -100; i <= 100; i++) {
- glColor3f(1.0f, 1.0f, 1.0f);
- glVertex2f(i, -100);
- glVertex2f(i, +100);
- glVertex2f(-100, i);
- glVertex2f(+100, i);
- }
- } glEnd();
- glLineWidth(4);
- glBegin(GL_LINES); {
- // X tengely
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex2f(-5.0f, 0.0f);
- glVertex2f(5.0f, 0.0f);
- glVertex2f(4.5f, 0.5f);
- glVertex2f(5.0f, 0.0f);
- glVertex2f(4.5f, -0.5f);
- glVertex2f(5.0f, 0.0f);
- // Y tengely
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex2f(0.0f, -5.0f);
- glVertex2f(0.0f, 5.0f);
- glVertex2f(0.5f, 4.5f);
- glVertex2f(0.0f, 5.0f);
- glVertex2f(-0.5f, 4.5f);
- glVertex2f(0.0f, 5.0f);
- } glEnd();
- glutSwapBuffers();
- }
- void onIdle() {
- float time = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
- if(2.0f < time && time < 4.0f) {
- scale.x = (time-2)/2 + 1;
- scale.y = (time-2)/2 * 1.5 + 1;
- } else if(4.0f < time && time < 6.0f) {
- angle = (time-4)/2 * 67;
- } else if(6.0f < time && time < 8.0f) {
- trans.x = (time-6)/2 * 2.7;
- trans.y = (time-6)/2 * -3.1;
- }
- glutPostRedisplay();
- }
- void onMouse(int, int, int, int) {}
- void onMouseMotion(int, int) {}
- void onKeyboard(unsigned char, int, int) {}
- void onKeyboardUp(unsigned char, int, int) {}
- int main(int argc, char **argv) {
- glutInit(&argc, argv);
- glutInitWindowSize(600, 600);
- glutInitWindowPosition(100, 100);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("Grafika pelda program");
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- onInitialization();
- glutDisplayFunc(onDisplay);
- glutMouseFunc(onMouse);
- glutIdleFunc(onIdle);
- glutKeyboardFunc(onKeyboard);
- glutKeyboardUpFunc(onKeyboardUp);
- glutMotionFunc(onMouseMotion);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement