Advertisement
machalda

OpenGL stromeček :-)

Sep 30th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include "Tree.h"
  2. #include <windows.h>
  3. #include <GL/glut.h>
  4. #include <stdlib.h>
  5.  
  6. Tree::Tree(const int x, const int y, const int height):GraphicObject(x,y)
  7. {
  8.     if(height<2)
  9.     {
  10.         this->height=2;
  11.         this->div=7;
  12.         colorChange = 0.2;
  13.     }
  14.     else
  15.     {
  16.         if(height<=7)
  17.         {
  18.             this->height=height;
  19.             this->div=10-height+1;
  20.             colorChange = 0.08-div/100;
  21.         }
  22.         else
  23.         {
  24.             this->height=7;
  25.             this->div=4;
  26.             colorChange = 0.08;
  27.         }
  28.     }
  29.         for(int i = 0;i<=20;i++) //kmen
  30.         {
  31.             colPoints.insert(std::pair<int, int>(28, i));
  32.         }
  33. /*
  34.         int pom = height * 32;
  35.         for(int z = 32*height;z>=0;z--) //vrch
  36.         {
  37.             colPoints.insert(std::pair<int, int>(i, 0));
  38.         }*/
  39.  
  40.     for(int i=0;i<this->height;i++)
  41.     {
  42.         colPoints.insert(std::pair<int, int>(6+i*div, 20+i*12));
  43.         colPoints.insert(std::pair<int, int>(58-i*div, 20+i*12));
  44.         colPoints.insert(std::pair<int, int>(32, 34+i*12));
  45.  
  46.     }
  47. };
  48. void Tree::draw()
  49. {
  50.  
  51.     glBegin(GL_POLYGON); //kmen
  52.         glColor3f(0.5, 0.15, 0.15);
  53.         glVertex2i(28+x, 0+y); //1
  54.         glVertex2i(36+x, 0+y);
  55.         glVertex2i(36+x, 20+y);
  56.         glVertex2i(28+x, 20+y);
  57.     glEnd();
  58.  
  59.     for(int i=0;i<this->height;i++)
  60.     {
  61.         glBegin(GL_TRIANGLES);
  62.             glColor3f(0.4, 0.65-i*this->colorChange, 0.45-i*this->colorChange);
  63.             glVertex2i(6+i*div+x, 20+i*12+y);
  64.             glVertex2i(58-i*div+x, 20+i*12+y);
  65.             glVertex2i(32+x, 34+i*12+y);
  66.         glEnd();
  67.     }
  68.  
  69. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement