Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.06 KB | None | 0 0
  1.  
  2. //=============================================================================================
  3. // Szamitogepes grafika hazi feladat keret. Ervenyes 2014-tol.          
  4. // A //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. // sorokon beluli reszben celszeru garazdalkodni, mert a tobbit ugyis toroljuk.
  6. // A beadott program csak ebben a fajlban lehet, a fajl 1 byte-os ASCII karaktereket tartalmazhat.
  7. // Tilos:
  8. // - mast "beincludolni", illetve mas konyvtarat hasznalni
  9. // - faljmuveleteket vegezni (printf is fajlmuvelet!)
  10. // - new operatort hivni az onInitialization fĂźggvĂŠnyt kivĂŠve, a lefoglalt adat korrekt felszabadĂ­tĂĄsa nĂŠlkĂźl
  11. // - felesleges programsorokat a beadott programban hagyni
  12. // - tovabbi kommenteket a beadott programba irni a forrasmegjelolest kommentjeit kiveve
  13. // ---------------------------------------------------------------------------------------------
  14. // A feladatot ANSI C++ nyelvu forditoprogrammal ellenorizzuk, a Visual Studio-hoz kepesti elteresekrol
  15. // es a leggyakoribb hibakrol (pl. ideiglenes objektumot nem lehet referencia tipusnak ertekul adni)
  16. // a hazibeado portal ad egy osszefoglalot.
  17. // ---------------------------------------------------------------------------------------------
  18. // A feladatmegoldasokban csak olyan gl/glu/glut fuggvenyek hasznalhatok, amelyek
  19. // 1. Az oran a feladatkiadasig elhangzottak ES (logikai AND muvelet)
  20. // 2. Az alabbi listaban szerepelnek:  
  21. // Rendering pass: glBegin, glVertex[2|3]f, glColor3f, glNormal3f, glTexCoord2f, glEnd, glDrawPixels
  22. // Transzformaciok: glViewport, glMatrixMode, glLoadIdentity, glMultMatrixf, gluOrtho2D,
  23. // glTranslatef, glRotatef, glScalef, gluLookAt, gluPerspective, glPushMatrix, glPopMatrix,
  24. // Illuminacio: glMaterialfv, glMaterialfv, glMaterialf, glLightfv
  25. // Texturazas: glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glTexEnvi,
  26. // Pipeline vezerles: glShadeModel, glEnable/Disable a kovetkezokre:
  27. // GL_LIGHTING, GL_NORMALIZE, GL_DEPTH_TEST, GL_CULL_FACE, GL_TEXTURE_2D, GL_BLEND, GL_LIGHT[0..7]
  28. //
  29. // NYILATKOZAT
  30. // ---------------------------------------------------------------------------------------------
  31. // Nev    : <RÉTI> <MARCELL>
  32. // Neptun : <SWESQ1>
  33. // ---------------------------------------------------------------------------------------------
  34. // ezennel kijelentem, hogy a feladatot magam keszitettem, es ha barmilyen segitseget igenybe vettem vagy
  35. // mas szellemi termeket felhasznaltam, akkor a forrast es az atvett reszt kommentekben egyertelmuen jeloltem.
  36. // A forrasmegjeloles kotelme vonatkozik az eloadas foliakat es a targy oktatoi, illetve a
  37. // grafhazi doktor tanacsait kiveve barmilyen csatornan (szoban, irasban, Interneten, stb.) erkezo minden egyeb
  38. // informaciora (keplet, program, algoritmus, stb.). Kijelentem, hogy a forrasmegjelolessel atvett reszeket is ertem,
  39. // azok helyessegere matematikai bizonyitast tudok adni. Tisztaban vagyok azzal, hogy az atvett reszek nem szamitanak
  40. // a sajat kontribucioba, igy a feladat elfogadasarol a tobbi resz mennyisege es minosege alapjan szuletik dontes.  
  41. // Tudomasul veszem, hogy a forrasmegjeloles kotelmenek megsertese eseten a hazifeladatra adhato pontokat
  42. // negativ elojellel szamoljak el es ezzel parhuzamosan eljaras is indul velem szemben.
  43. //=============================================================================================
  44.  
  45. #define _USE_MATH_DEFINES
  46. #include <math.h>
  47. #include <stdlib.h>
  48. #include <iostream> /////////szeddki!!!
  49. using namespace std; ////////////eztis!!
  50.  
  51. #if defined(__APPLE__)                                                                                                                                                                                                            
  52. #include <OpenGL/gl.h>                                                                                                                                                                                                            
  53. #include <OpenGL/glu.h>                                                                                                                                                                                                          
  54. #include <GLUT/glut.h>                                                                                                                                                                                                            
  55. #else                                                                                                                                                                                                                            
  56. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)                                                                                                                                                                      
  57. #include <windows.h>                                                                                                                                                                                                              
  58. #endif                                                                                                                                                                                                                            
  59. #include <GL/gl.h>                                                                                                                                                                                                                
  60. #include <GL/glu.h>                                                                                                                                                                                                              
  61. #include <GL/glut.h>                                                                                                                                                                                                              
  62. #endif          
  63.  
  64.  
  65. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. // Innentol modosithatod...
  67. //--------------------------------------------------------
  68. // 3D Vektor
  69. //--------------------------------------------------------
  70. struct Vector {
  71.     float x, y, z;
  72.  
  73.     Vector() {
  74.         x = y = z = 0;
  75.     }
  76.     Vector(float x0, float y0, float z0 = 0) {
  77.         x = x0; y = y0; z = z0;
  78.     }
  79.     Vector operator*(float a) {
  80.         return Vector(x * a, y * a, z * a);
  81.     }
  82.     Vector operator+(const Vector& v) {
  83.         return Vector(x + v.x, y + v.y, z + v.z);
  84.     }
  85.     Vector operator-(const Vector& v) {
  86.         return Vector(x - v.x, y - v.y, z - v.z);
  87.     }
  88.     float operator*(const Vector& v) {  // dot product
  89.         return (x * v.x + y * v.y + z * v.z);
  90.     }
  91.     Vector operator%(const Vector& v) {     // cross product
  92.         return Vector(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
  93.     }
  94.     float Length() { return sqrt(x * x + y * y + z * z); }
  95. };
  96.  
  97. const int screenWidth = 600;    // alkalmazĂĄs ablak felbontĂĄsa
  98. const int screenHeight = 600;
  99. bool bouncestart = false;
  100.  
  101. struct Vector2D {
  102.  
  103.     float x, y;
  104.  
  105.     Vector2D() {
  106.         x = y = 0;
  107.     }
  108.     Vector2D(float x0, float y0) {
  109.         x = x0; y = y0;
  110.     }
  111.     Vector2D operator*(float a) {
  112.         return Vector2D(x * a, y * a);
  113.     }
  114.     Vector2D operator/(float a) {
  115.         return Vector2D(x / a, y / a);
  116.     }
  117.     Vector2D operator+(const Vector2D& v) {
  118.         return Vector2D(x + v.x, y + v.y);
  119.     }
  120.     Vector2D operator-(const Vector2D& v) {
  121.         return Vector2D(x - v.x, y - v.y);
  122.     }
  123.     float operator*(const Vector2D& v) {    // dot product
  124.         return (x * v.x + y * v.y);
  125.     }
  126.     float Length() { return sqrt(x * x + y * y); }
  127. };
  128.  
  129. struct CatmullRom {
  130.  
  131.     Vector2D center;
  132.     Vector2D speed;
  133.     float time;
  134.     CatmullRom()
  135.     {
  136.         center = Vector2D(0, 0);
  137.         speed = Vector2D(0, 0);
  138.         time = 0;
  139.  
  140.     }
  141.     CatmullRom(Vector2D xy0, Vector2D vxy0, float t0)
  142.     {
  143.         center = xy0;
  144.         speed = vxy0;
  145.         time = t0;
  146.     }
  147. };
  148.  
  149. Vector2D ConvertMousePoints(float x, float y)
  150. {
  151.     Vector2D ret;
  152.     ret.x = x / 600 * 1000;
  153.     ret.y = y / 600 * 1000;
  154.     return ret;
  155. }
  156.  
  157. Vector2D CalculateCatmullSpeed(Vector2D r0, Vector2D r1, Vector2D r2, float t0, float t1, float t2)
  158. {
  159.     Vector2D ret;
  160.     ret = ((r2 - r1) / (t2 - t1) + (r1 - r0) / (t1 - t0)) * 0.5;
  161.     return ret;
  162. }
  163.  
  164. //--------------------------------------------------------
  165. // Spektrum illetve szin
  166. //--------------------------------------------------------
  167. struct Color {
  168.     float r, g, b;
  169.  
  170.     Color() {
  171.         r = g = b = 0;
  172.     }
  173.     Color(float r0, float g0, float b0) {
  174.         r = r0; g = g0; b = b0;
  175.     }
  176.     Color operator*(float a) {
  177.         return Color(r * a, g * a, b * a);
  178.     }
  179.     Color operator*(const Color& c) {
  180.         return Color(r * c.r, g * c.g, b * c.b);
  181.     }
  182.     Color operator+(const Color& c) {
  183.         return Color(r + c.r, g + c.g, b + c.b);
  184.     }
  185. };
  186.  
  187. Color image[screenWidth*screenHeight];  // egy alkalmazĂĄs ablaknyi kĂŠp
  188.  
  189. CatmullRom splinepoints[1500];
  190. Vector2D parabolapoints[4000];
  191. int indexp = 0;
  192. int index = 0;
  193. int last_time = glutGet(GLUT_ELAPSED_TIME);
  194.  
  195. struct Camera{
  196.  
  197.     Vector2D center;
  198.     Vector2D speed;
  199.  
  200.     Camera()
  201.     {
  202.         center = Vector2D(0, 0);
  203.         speed = Vector2D(0, 0);
  204.     }
  205. };
  206.  
  207. Camera camera;
  208. // Inicializacio, a program futasanak kezdeten, az OpenGL kontextus letrehozasa utan hivodik meg (ld. main() fv.)
  209. void onInitialization() {
  210.  
  211.     glViewport(0, 0, screenWidth, screenHeight);
  212.     glClearColor(0.1f, 0.2f, 0.3f, 1.0f);       // torlesi szin beallitasa
  213.     //glClearColor(0, 1, 1, 1);
  214.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // kepernyo torles
  215.  
  216.     camera.center = Vector2D(0, 0);
  217.     //camera.speed = Vector2D(20, 30);
  218.     camera.speed = Vector2D(-20, -30);
  219.     gluOrtho2D(0, 1000,1000, 0);
  220.     last_time = glutGet(GLUT_ELAPSED_TIME);
  221. }
  222.  
  223. void DrawCircle(CatmullRom v)
  224. {
  225.     float radius = 5; //1000-es skálán nézve
  226.     int RESOLUTION = 150;
  227.     glBegin(GL_TRIANGLE_FAN);
  228.     glColor3f(1.0f, 0.0f, 0.0f);
  229.     glVertex2f(v.center.x, v.center.y);
  230.     for (int j = 0; j <= RESOLUTION; j++)
  231.     {
  232.         float angle = float(j) / RESOLUTION*2.0f*M_PI;
  233.         glVertex2f(v.center.x + radius*cos(angle), v.center.y + radius*sin(angle));
  234.     }
  235.     glEnd();
  236.     glBegin(GL_LINE_STRIP);
  237.     glColor3f(1.0f, 1.0f, 1.0f);
  238.     for (int j = 0; j <= RESOLUTION; j++)
  239.     {
  240.         float angle = float(j) / RESOLUTION*2.0f*M_PI;
  241.         glVertex2f(v.center.x + radius*cos(angle), v.center.y + radius*sin(angle));
  242.     }
  243.     glEnd();
  244. }
  245.  
  246. void DrawCatmullRomSpline()
  247. {
  248.     glColor3f(1.0f, 1.0f, 1.0f);
  249.     for (int i = 0; i < index - 1; i++)
  250.     {
  251.         glBegin(GL_LINE_STRIP);
  252.  
  253.         Vector2D a0 = splinepoints[i].center;
  254.         Vector2D a1 = splinepoints[i].speed;
  255.         Vector2D a2 = ((splinepoints[i + 1].center - splinepoints[i].center) * 3) / (pow((splinepoints[i + 1].time - splinepoints[i].time), 2)) - (splinepoints[i + 1].speed + splinepoints[i].speed * 2) / (splinepoints[i + 1].time - splinepoints[i].time);
  256.         Vector2D a3 = ((splinepoints[i].center - splinepoints[i + 1].center) * 2) / (pow((splinepoints[i + 1].time - splinepoints[i].time), 3)) + (splinepoints[i + 1].speed + splinepoints[i].speed) / (pow((splinepoints[i + 1].time - splinepoints[i].time),2));
  257.  
  258.  
  259.         for (float j = splinepoints[i].time; j < splinepoints[i + 1].time; j ++)
  260.         {
  261.             float t = j - splinepoints[i].time;
  262.             Vector2D v = a3*pow(t, 3) + a2*pow(t, 2) + a1*t + a0;
  263.             glVertex2f(v.x,v.y);
  264.         }
  265.         glEnd();
  266.     }
  267.  
  268.     glBegin(GL_LINE_STRIP);
  269.  
  270.     Vector2D a0 = splinepoints[index - 1].center;
  271.     Vector2D a1 = splinepoints[index - 1].speed;
  272.     Vector2D a2 = ((splinepoints[0].center - splinepoints[index - 1].center) * 3) / (pow(splinepoints[0].time, 2)) - (splinepoints[0].speed + splinepoints[index - 1].speed * 2) / (splinepoints[0].time);
  273.     Vector2D a3 = ((splinepoints[index - 1].center - splinepoints[0].center) * 2) / (pow(splinepoints[0].time, 3)) + (splinepoints[0].speed + splinepoints[index - 1].speed) / (pow(splinepoints[0].time, 2));
  274.  
  275.     for (float j = splinepoints[index - 1].time; j < (splinepoints[index - 1].time + splinepoints[0].time); j ++)
  276.     {
  277.         float t = j - splinepoints[index - 1].time;
  278.         Vector2D v = a3*pow(t, 3) + a2*pow(t, 2) + a1*t + a0;
  279.         glVertex2f(v.x, v.y);
  280.     }
  281.     glEnd();
  282.  
  283. }
  284.  
  285. void DrawParabole()
  286. {
  287.     Vector2D p1 = splinepoints[0].center;
  288.     Vector2D p2 = splinepoints[1].center;
  289.     Vector2D p3 = splinepoints[2].center;
  290.  
  291.     Vector2D i = p2 - p1;
  292.     Vector2D n(i.y*(-1.0),i.x);
  293.     float C = -1.0*(n.x * p1.x + n.y * p1.y);
  294.     float A = n.x;
  295.     float B = n.y;
  296.     float distance = (abs(A * p3.x + B * p3.y + C)) / (sqrt(A * A + B * B));
  297.  
  298.     distance = round(distance);
  299.     if (bouncestart)
  300.     {
  301.         glBegin(GL_POINTS);
  302.         glColor3f(1.0f, 1.0f, 0.0f);
  303.         for (float i = 0; i < 1000; i=i+0.5)
  304.         {
  305.             for (float j = 0; j < 1000; j=j+0.5)
  306.             {
  307.                 float distancefromline = round((abs(A * i + B * j + C)) / (sqrt(A * A + B * B)));
  308.  
  309.                 float distancefrompoint = round(sqrt(pow(i - p3.x, 2) + pow(j - p3.y, 2)));
  310.  
  311.                 if (distancefrompoint == distancefromline)
  312.                 {
  313.                     glColor3f(1, 1, 0);
  314.  
  315.                 }
  316.                 else if (distancefrompoint < distancefromline)
  317.                 {
  318.                     glColor3f(1, 1, 0);
  319.                 }
  320.                 else
  321.                 {
  322.                     glColor3f(0, 1, 1);
  323.                 }
  324.                 glVertex2f(i, j);
  325.             }
  326.         }
  327.         glEnd();
  328.     }
  329.     else
  330.     {
  331.         glBegin(GL_POINTS);
  332.         glColor3f(1.0f, 1.0f, 0.0f);
  333.         for (int i = 0; i < 1000; i++)
  334.         {
  335.             for (int j = 0; j < 1000; j++)
  336.             {
  337.                 float distancefromline = round((abs(A * i + B * j + C)) / (sqrt(A * A + B * B)));
  338.  
  339.                 float distancefrompoint = round(sqrt(pow(i - p3.x, 2) + pow(j - p3.y, 2)));
  340.  
  341.                 if (distancefrompoint == distancefromline)
  342.                 {
  343.                     parabolapoints[indexp] = Vector2D(i, j);
  344.                     glColor3f(1, 1, 0);
  345.                     indexp++;
  346.                 }
  347.                 else if (distancefrompoint < distancefromline)
  348.                 {
  349.                     glColor3f(1, 1, 0);
  350.                 }
  351.                 else
  352.                 {
  353.                     glColor3f(0, 1, 1);
  354.                 }
  355.                 glVertex2f(i, j);
  356.             }
  357.         }
  358.         glEnd();
  359.     }
  360. }
  361.  
  362. void DrawTouchLine()
  363. {
  364.     Vector2D p1 = splinepoints[0].center;
  365.     Vector2D p2 = splinepoints[1].center;
  366.     Vector2D p3 = splinepoints[2].center;
  367.  
  368.     Vector2D a0 = splinepoints[1].center;
  369.     Vector2D a1 = splinepoints[1].speed;
  370.     Vector2D a2 = ((splinepoints[2].center - splinepoints[1].center) * 3) / (pow((splinepoints[2].time - splinepoints[1].time), 2)) - (splinepoints[2].speed + splinepoints[1].speed * 2) / (splinepoints[2].time - splinepoints[1].time);
  371.     Vector2D a3 = ((splinepoints[1].center - splinepoints[2].center) * 2) / (pow((splinepoints[2].time - splinepoints[1].time), 3)) + (splinepoints[2].speed + splinepoints[1].speed) / (pow((splinepoints[2].time - splinepoints[1].time), 2));
  372.     bool found = false;
  373.  
  374.     for (float j = splinepoints[1].time; j < splinepoints[2].time; j++)
  375.     {
  376.         float t = j - splinepoints[1].time;
  377.         Vector2D v = a3*pow(t, 3) + a2*pow(t, 2) + a1*t + a0;
  378.        
  379.         for (int i = 0; i < indexp; i++)
  380.         {
  381.             if (abs(parabolapoints[i].x - v.x) < 3 && abs(parabolapoints[i].y - v.y) < 3)
  382.             {
  383.                 found = true;
  384.                 Vector2D C;
  385.                 float distance = sqrt(pow(p3.x - parabolapoints[i].x, 2) + pow(p3.y - parabolapoints[i].y, 2));
  386.  
  387.                 for (float t = -2; t < 2; t+=0.1)
  388.                 {
  389.                     int x = p1.x * (1 - t) + p2.x * t;
  390.                     int y = p1.y * (1 - t) + p2.y * t;
  391.  
  392.                     float distancefrompoint = sqrt(pow(x - parabolapoints[i].x, 2) + pow(y - parabolapoints[i].y, 2));
  393.  
  394.                     if (abs(distance - distancefrompoint) < 5)
  395.                     {
  396.                         C.x = x;
  397.                         C.y = y;
  398.                         break;
  399.                     }
  400.                 }
  401.  
  402.                 Vector2D S(((p3.x + C.x) / 2), ((p3.y + C.y) / 2));
  403.  
  404.                 glColor3f(0.0, 1.0, 0.0);
  405.                 glLineWidth(3);
  406.                 glBegin(GL_LINE_STRIP);
  407.                 for (int t = -1000; t < 1000; t++)
  408.                 {
  409.                     int x = S.x * (1 - t) + parabolapoints[i].x * t;
  410.                     int y = S.y * (1 - t) + parabolapoints[i].y * t;
  411.                     glVertex2f(x, y);
  412.                 }
  413.                 glEnd();
  414.  
  415.                 glBegin(GL_LINE_STRIP);
  416.                 Vector2D n(a1.y*(-1.0), a1.x);
  417.                 for (int t = -1000; t < 1000; t++)
  418.                 {
  419.                     int x = n.x * (1 - t) + parabolapoints[i].x * t;
  420.                     int y = n.y * (1 - t) + parabolapoints[i].y * t;
  421.                     glVertex2f(x, y);
  422.                 }
  423.                 glEnd();
  424.                 glLineWidth(1);
  425.                 break;
  426.             }
  427.         }
  428.         if (found)
  429.         {
  430.             break;
  431.         }
  432.     }
  433. }
  434. // Rajzolas, ha az alkalmazas ablak ervenytelenne valik, akkor ez a fuggveny hivodik meg
  435. void onDisplay() {
  436.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  437.     if (index >= 3)
  438.     {
  439.         DrawParabole();
  440.         DrawCatmullRomSpline();
  441.         DrawTouchLine();
  442.     }
  443.     for (int i = 0; i < index; i++)
  444.     {
  445.         DrawCircle(splinepoints[i]);
  446.     }
  447.  
  448.     glutSwapBuffers();
  449.  
  450. }
  451.  
  452. // Billentyuzet esemenyeket lekezelo fuggveny (lenyomas)
  453. void onKeyboard(unsigned char key, int x, int y) {
  454.     if (key == ' ')
  455.     {
  456.         bouncestart = true;
  457.         glTranslatef(camera.center.x + 250, camera.center.y + 250, 0);
  458.         glScalef(0.5, 0.5, 0);
  459.         glutPostRedisplay();
  460.     }
  461.  
  462. }
  463.  
  464. // Billentyuzet esemenyeket lekezelo fuggveny (felengedes)
  465. void onKeyboardUp(unsigned char key, int x, int y) {
  466.  
  467. }
  468.  
  469. // Eger esemenyeket lekezelo fuggveny
  470. void onMouse(int button, int state, int x, int y) {
  471.     if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)   // A GLUT_LEFT_BUTTON / GLUT_RIGHT_BUTTON illetve GLUT_DOWN / GLUT_UP
  472.     {
  473.         CatmullRom cr;
  474.         cr.center = ConvertMousePoints((float)x, (float)y);
  475.         cr.time = glutGet(GLUT_ELAPSED_TIME);
  476.         splinepoints[index] = cr;
  477.         index++;
  478.         if (index >= 3)
  479.         {
  480.             splinepoints[index - 2].speed = CalculateCatmullSpeed(splinepoints[index - 3].center, splinepoints[index - 2].center, splinepoints[index - 1].center, splinepoints[index - 3].time, splinepoints[index - 2].time, splinepoints[index - 1].time);
  481.             splinepoints[0].speed = CalculateCatmullSpeed(splinepoints[0].center, splinepoints[1].center, splinepoints[2].center, splinepoints[0].time, splinepoints[1].time, splinepoints[2].time);
  482.             splinepoints[index - 1].speed = CalculateCatmullSpeed(splinepoints[index - 2].center, splinepoints[index - 1].center, splinepoints[0].center, splinepoints[index - 2].time, splinepoints[index - 1].time, splinepoints[0].time);
  483.         }
  484.        
  485.         glutPostRedisplay();
  486.     }
  487. }
  488. // Eger mozgast lekezelo fuggveny
  489. void onMouseMotion(int x, int y)
  490. {
  491.  
  492. }
  493.  
  494. // `Idle' esemenykezelo, jelzi, hogy az ido telik, az Idle esemenyek frekvenciajara csak a 0 a garantalt minimalis ertek
  495. void onIdle() {
  496.     int current_time = glutGet(GLUT_ELAPSED_TIME);
  497.     int diff = current_time - last_time;
  498.     if (bouncestart)
  499.     {
  500.         if (diff >= 1000)
  501.         {
  502.             diff = diff / 1000;
  503.            
  504.             //if (camera.center.x <= -250 || camera.center.x >= 250 )
  505.             if (camera.center.x <= -500 || camera.center.x >= 500)
  506.             {
  507.                 camera.speed.x = -camera.speed.x;
  508.             }
  509.             //if (camera.center.y <= -250 || camera.center.y >= 250 )
  510.             if (camera.center.y <= -500 || camera.center.y >= 500)
  511.             {
  512.                 camera.speed.y = -camera.speed.y;
  513.             }
  514.             camera.center = camera.center + (camera.speed * diff);
  515.             last_time = current_time;
  516.             glMatrixMode(GL_MODELVIEW);             // A MODELVIEW transzformaciot egysegmatrixra inicializaljuk
  517.             glLoadIdentity();
  518.             glMatrixMode(GL_PROJECTION);            // A PROJECTION transzformaciot egysegmatrixra inicializaljuk
  519.             glLoadIdentity();
  520.             gluOrtho2D(0, 1000, 1000, 0);
  521.             //glTranslatef(camera.center.x + 250, camera.center.y + 250, 0);
  522.             //glScalef(0.5, 0.5, 0);
  523.             glTranslatef(camera.center.x - 500, camera.center.y - 500, 0);
  524.             glScalef(2, 2, 0);
  525.             cout << camera.center.x << camera.center.y << "\n";
  526.             glutPostRedisplay();
  527.         }
  528.     }
  529. }
  530.  
  531. // ...Idaig modosithatod
  532. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  533.  
  534. // A C++ program belepesi pontja, a main fuggvenyt mar nem szabad bantani
  535. int main(int argc, char **argv) {
  536.     glutInit(&argc, argv);              // GLUT inicializalasa
  537.     glutInitWindowSize(600, 600);           // Alkalmazas ablak kezdeti merete 600x600 pixel
  538.     glutInitWindowPosition(100, 100);           // Az elozo alkalmazas ablakhoz kepest hol tunik fel
  539.     glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);  // 8 bites R,G,B,A + dupla buffer + melyseg buffer
  540.  
  541.     glutCreateWindow("Grafika hazi feladat");       // Alkalmazas ablak megszuletik es megjelenik a kepernyon
  542.  
  543.     glMatrixMode(GL_MODELVIEW);             // A MODELVIEW transzformaciot egysegmatrixra inicializaljuk
  544.     glLoadIdentity();
  545.     glMatrixMode(GL_PROJECTION);            // A PROJECTION transzformaciot egysegmatrixra inicializaljuk
  546.     glLoadIdentity();
  547.  
  548.     onInitialization();                 // Az altalad irt inicializalast lefuttatjuk
  549.  
  550.     glutDisplayFunc(onDisplay);             // Esemenykezelok regisztralasa
  551.     glutMouseFunc(onMouse);
  552.     glutIdleFunc(onIdle);
  553.     glutKeyboardFunc(onKeyboard);
  554.     glutKeyboardUpFunc(onKeyboardUp);
  555.     glutMotionFunc(onMouseMotion);
  556.  
  557.     glutMainLoop();                 // Esemenykezelo hurok
  558.  
  559.     return 0;
  560. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement