LordMirai

tractor :)

Apr 11th, 2022 (edited)
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.00 KB | None | 0 0
  1. #include "glos.h"
  2.  
  3. #include <GL/gl.h>
  4. #include <GL/glu.h>
  5. #include <GL/glut.h>
  6. #include <GL/glaux.h>
  7. #include <math.h>
  8.  
  9. void myinit(void);
  10. void CALLBACK display(void);
  11. void CALLBACK myReshape(GLsizei w, GLsizei h);
  12. void CALLBACK MutaStanga(void);
  13. void CALLBACK MutaDreapta(void);
  14. void CALLBACK MutaSus(void);
  15. void CALLBACK MutaJos(void);
  16. void CALLBACK rot_z_up(AUX_EVENTREC* event);
  17. void CALLBACK rot_z_down(AUX_EVENTREC* event);
  18.  
  19.  
  20. static GLfloat x = 0, y = 0, alfa = 0;
  21. GLUquadricObj* qobj;
  22. GLUnurbsObj* theNurb;
  23.  
  24. void myinit(void) {
  25.     glClearColor(1.0, 1.0, 1.0, 1.0);
  26.     glShadeModel(GL_FLAT);
  27.     theNurb = gluNewNurbsRenderer();
  28.     gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 10.0);
  29. }
  30.  
  31. void CALLBACK MutaStanga(void)
  32. {
  33.     x = x - 10;
  34. }
  35.  
  36. void CALLBACK MutaDreapta(void)
  37. {
  38.     x = x + 10;
  39. }
  40.  
  41. void CALLBACK MutaSus(void)
  42. {
  43.     y = y + 10;
  44. }
  45.  
  46. void CALLBACK MutaJos(void)
  47. {
  48.     y = y - 10;
  49. }
  50.  
  51. void CALLBACK rot_z_up(AUX_EVENTREC* event)
  52. {
  53.     alfa = alfa + 10;
  54. }
  55.  
  56. void CALLBACK rot_z_down(AUX_EVENTREC* event)
  57. {
  58.     alfa = alfa - 10;
  59. }
  60.  
  61. void CALLBACK display(void)
  62. {
  63.     glClear(GL_COLOR_BUFFER_BIT);
  64.  
  65.     glLoadIdentity();
  66.  
  67.     qobj = gluNewQuadric();
  68.     glRotatef(alfa, 0, 1, 0);
  69.  
  70.     // TRACTOR START: doua discuri, cateva dreptunghiuri
  71.  
  72.     // corp principal (orizontal (dreapta))
  73.     glPushMatrix();
  74.     gluQuadricDrawStyle(qobj, GLU_LINE);
  75.     glTranslatef(x + 10, y + 80, 0);
  76.     glRotatef(90, 1, 0, 0);
  77.     glColor3f(0.6, 0, 0);
  78.     gluCylinder(qobj, 20, 20, 40, 4, 100);
  79.     glPopMatrix();
  80.  
  81.     // corp principal (orizontal (stanga))
  82.     glPushMatrix();
  83.     gluQuadricDrawStyle(qobj, GLU_LINE);
  84.     glTranslatef(x -30, y + 80, 0);
  85.     glRotatef(90, 1, 0, 0);
  86.     glColor3f(0.6, 0, 0);
  87.     gluCylinder(qobj, 20, 20, 40, 4, 100);
  88.     glPopMatrix(); 
  89.  
  90.     // cabina (vertical)
  91.     glPushMatrix();
  92.     gluQuadricDrawStyle(qobj, GLU_LINE);
  93.     glTranslatef(x + 50, y + 110, 0);
  94.     glRotatef(90, 1, 0, 0);
  95.     glColor3f(0, 0, 0.5);
  96.     gluCylinder(qobj, 20, 20, 70, 4, 250);
  97.     glPopMatrix();
  98.  
  99.     // esapament
  100.     glPushMatrix();
  101.     gluQuadricDrawStyle(qobj, GLU_LINE);
  102.     glTranslatef(x - 30, y + 98, 0);
  103.     glRotatef(90, 1, 0, 0);
  104.     glColor3f(0.3, 0.05, 0);
  105.     gluCylinder(qobj, 5, 5, 18, 4, 60);
  106.     glPopMatrix();
  107.  
  108.     // roata spate-dreapta
  109.     glPushMatrix();
  110.     gluQuadricDrawStyle(qobj, GLU_LINE);
  111.     glTranslatef(x + 50, y + 28, 26);
  112.     glColor3f(0.3,0, 0.4);
  113.     glutSolidTorus(10, 30, 80, 80);
  114.     glPopMatrix();
  115.  
  116.     // roata spate-stanga
  117.     glPushMatrix();
  118.     gluQuadricDrawStyle(qobj, GLU_LINE);
  119.     glTranslatef(x + 50, y + 28, -26);
  120.     glColor3f(0.2, 0, 0.3);
  121.     glutSolidTorus(10, 30, 80, 80);
  122.     glPopMatrix();
  123.  
  124.     //roata fata-stanga
  125.     glPushMatrix();
  126.     gluQuadricDrawStyle(qobj, GLU_LINE);
  127.     glTranslatef(x - 40, y + 20, -20);
  128.     glColor3f(0, 0.25, 0.2);
  129.     glutSolidTorus(7, 20, 50, 50);
  130.     glPopMatrix();
  131.  
  132.     //roata fata-dreapta
  133.     glPushMatrix();
  134.     gluQuadricDrawStyle(qobj, GLU_LINE);
  135.     glTranslatef(x - 40, y + 20, 20);
  136.     glColor3f(0, 0.2, 0.15);
  137.     glutSolidTorus(7, 20, 50, 50);
  138.     glPopMatrix();
  139.  
  140.  
  141.     auxSwapBuffers();
  142.  
  143.     GLfloat ctlpoints[4][3] = { {-.75, -.75, 0.0},
  144.     {-.5, .75, 0.0}, {.5, .75, 0.0}, {.75, -.75, 0.0} };
  145.     GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 };
  146.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  147.     glColor3f(1.0, 1.0, 1.0); // culoarea curenta de desenare
  148.     // incepe corpul de redare al curbei Spline
  149.     gluBeginCurve(theNurb);
  150.     gluNurbsCurve(theNurb,  // pointer obiect NURBS
  151.         8, knots,           //numar noduri, tablou noduri
  152.         3,                  // intervalul de valori dintre doua puncte de control consecutive
  153.         &ctlpoints[0][0],   // vector puncte de control
  154.         4,                  // ordinul curbei
  155.         GL_MAP1_VERTEX_3);  // tip evaluator
  156.     gluEndCurve(theNurb);
  157.  
  158.     glFlush();
  159. }
  160.  
  161. /*void CALLBACK myReshape(GLsizei w, GLsizei h)
  162. {
  163. if (!h) return;         //transformare anizotropica, forma se modifica functie de forma(dimens) viewportului
  164. glViewport(0, 0, w, h); //daca w>h stabilim ca baza inaltime, si stab unit logica de dimens in fct de h(h/320, 320 lungime lat patrat)
  165. glMatrixMode(GL_PROJECTION);
  166. glLoadIdentity();
  167. glOrtho (-160.0, 160.0, -160.0,
  168. 160.0, -10.0, 10.0);
  169. glMatrixMode(GL_MODELVIEW);
  170. }*/
  171.  
  172. void CALLBACK myReshape(GLsizei w, GLsizei h)
  173. {
  174.     if (!h) return;
  175.     glViewport(0, 0, w, h);
  176.     glMatrixMode(GL_PROJECTION);
  177.     glLoadIdentity();
  178.     if (w <= h)
  179.         glOrtho(-160.0, 160.0, 160.0 * (GLfloat)h / (GLfloat)w,
  180.             -160.0 * (GLfloat)h / (GLfloat)w, -100.0, 100.0);
  181.     else
  182.         glOrtho(-160.0 * (GLfloat)w / (GLfloat)h,
  183.             160.0 * (GLfloat)w / (GLfloat)h, -160.0, 160.0, -100.0, 100.0);
  184.     glMatrixMode(GL_MODELVIEW);
  185. }
  186.  
  187. int main(int argc, char** argv)
  188. {
  189.     auxInitDisplayMode(AUX_DOUBLE | AUX_RGB | AUX_DEPTH);
  190.     auxInitPosition(0, 0, 1000, 800);
  191.     auxInitWindow("Un patrat care se translateaza pe axa x");
  192.     myinit();
  193.  
  194.     glEnable(GL_DEPTH_TEST);
  195.  
  196.     auxKeyFunc(AUX_LEFT, MutaStanga);
  197.     auxKeyFunc(AUX_RIGHT, MutaDreapta);
  198.     auxKeyFunc(AUX_UP, MutaSus);
  199.     auxKeyFunc(AUX_DOWN, MutaJos);
  200.     auxMouseFunc(AUX_LEFTBUTTON, AUX_MOUSEDOWN, rot_z_up);
  201.     auxMouseFunc(AUX_RIGHTBUTTON, AUX_MOUSEDOWN, rot_z_down);
  202.  
  203.  
  204.     auxReshapeFunc(myReshape);
  205.     auxMainLoop(display);
  206.     return(0);
  207. }
Advertisement
Add Comment
Please, Sign In to add comment