SHARE
TWEET

Untitled

a guest Jun 18th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <GL/glut.h>
  7. #include "RgbImage.h"
  8. #include "materiais.h"
  9.  
  10. //--------------------------------- Definir cores
  11. #define BLUE     0.0, 0.0, 1.0, 1.0
  12. #define RED      1.0, 0.0, 0.0, 1.0
  13. #define YELLOW   1.0, 1.0, 0.0, 1.0
  14. #define GREEN    0.0, 1.0, 0.0, 1.0
  15. #define WHITE    1.0, 1.0, 1.0, 1.0
  16. #define BLACK    0.0, 0.0, 0.0, 1.0
  17. #define PI       3.14159
  18. #define SIZE     156
  19. #define SIZEMINI 96
  20.  
  21. #define frand()         ((float)rand()/RAND_MAX)
  22. #define MAX_PARTICULAS  1500
  23.  
  24. #define RandomFactor 2.0    //cannot be variable, because it is only use in InitFountain(),
  25.                             //zero for perfect physical
  26.  
  27. GLint ListNum;  //The number of the diplay list
  28.  
  29. GLfloat OuterRadius = 1.2;
  30. GLfloat InnerRadius = 1.0;
  31. GLint NumOfVerticesStone = 32;    //only a quarter of the finally used vertices
  32. GLfloat StoneHeight = 0.5;
  33. GLfloat WaterHeight = 0.45;
  34.  
  35. GLint Turned = 0;
  36. bool DoTurn = true;
  37. bool DoMoveUp = true;
  38. bool DoUpdateScene = true;
  39. GLfloat MoveUp = 0.8;
  40. GLfloat ChangeMoveUp = 0.01;
  41.  
  42.  
  43.  
  44. //---------------------------------------- Particle attributes
  45. typedef struct {
  46.     float   size;       // tamanho
  47.     float   life;       // vida
  48.     float   fade;       // fade
  49.     float   r, g, b;    // color
  50.     GLfloat x, y, z;    // posicao
  51.     GLfloat vx, vy, vz; // velocidade
  52.     GLfloat ax, ay, az; // aceleracao
  53. } Particle;
  54.  
  55. //---------------------------------------- fonte agua
  56. /*struct Svertex{       //posicao
  57.     GLfloat x,y,z;
  58. };*/
  59.  
  60. struct SVertex
  61. {
  62.     GLfloat x,y,z;
  63. };
  64.  
  65. //It's not the best style to put classes into the main file,
  66. //but here it is easier for you and me!
  67. class CDrop
  68. {
  69. private:
  70.     GLfloat time;  //How many steps the drop was "outside", when it falls into the water, time is set back to 0
  71.     SVertex Speed;  //See the doc for explanation of the physics
  72.     GLfloat AccFactor;
  73. public:
  74.     void SetTime(GLfloat NewTime);
  75.     void SetConstantSpeed (SVertex NewSpeed);
  76.     void SetAccFactor(GLfloat NewAccFactor);
  77.     void ComputeNewPosition(SVertex *PositionVertex);  //increments time, gets the new position
  78. };
  79.  
  80. void CDrop::SetConstantSpeed(SVertex NewSpeed)
  81. {
  82.     Speed = NewSpeed;
  83. }
  84.  
  85. void CDrop::SetAccFactor (GLfloat NewAccFactor)
  86. {
  87.     AccFactor = NewAccFactor;
  88. }
  89.  
  90. void CDrop::SetTime(GLfloat NewTime)
  91. {
  92.     time = NewTime;
  93. }
  94.  
  95. void CDrop::ComputeNewPosition(SVertex * PositionVertex)
  96. {
  97.     SVertex Position;
  98.     time = time+ 1.0;
  99.     //--------------------------------------- Posicao
  100.     Position.x = Speed.x * time;
  101.     Position.y = Speed.y * time - AccFactor * time * time;
  102.     Position.z = Speed.z * time;
  103.    
  104.     PositionVertex->x = Position.x;
  105.     PositionVertex->y = Position.y;// + WaterHeight;
  106.     PositionVertex->z = Position.z;
  107.    
  108.     //---------------------------------------- Bate no chao
  109.     if (Position.y < 0.0)
  110.     {
  111.         /*the drop has fallen into the water. The problem is now, that we cannot
  112.         set time to 0.0, because if there are more "DropsPerRay" than "TimeNeeded" (See InitFountain())
  113.         several drops would be seen as one. Check it out.
  114.         */
  115.         time = time - int(time);
  116.         if (time > 0.0) time -= 1.0;
  117.     }
  118.        
  119. }
  120.  
  121. ////////////////////////////////////////////////////////////////////////////////
  122.  
  123. CDrop * FountainDrops;
  124. SVertex * FountainVertices;
  125. GLint Steps = 3;   //a fountain has several steps, each with its own height
  126. GLint RaysPerStep = 8;  
  127. GLint DropsPerRay = 50;
  128. GLfloat DropsTotal = Steps * RaysPerStep * DropsPerRay;
  129. GLfloat AngleOfDeepestStep = 80;
  130. GLfloat AccFactor = 0.011;
  131.  
  132. GLfloat GetRandomFloat(GLfloat range)
  133. {
  134.     return (GLfloat)rand() / (GLfloat)RAND_MAX * range * RandomFactor;
  135. }
  136.  
  137. void InitFountain(void)
  138. {
  139.     //This function needn't be and isn't speed optimized
  140.     FountainDrops = new CDrop [ 3*8*50 ];//DropsComplete ];
  141.     FountainVertices = new SVertex [ 3*8*50];//DropsComplete ];
  142.     SVertex NewSpeed;
  143.     GLfloat DropAccFactor; //different from AccFactor because of the random change
  144.     GLfloat TimeNeeded;
  145.     GLfloat StepAngle; //Angle, which the ray gets out of the fountain with
  146.     GLfloat RayAngle;   //Angle you see when you look down on the fountain
  147.     GLint i,j,k;
  148.     for (k = 0; k <Steps; k++)
  149.     {
  150.         for (j = 0; j < RaysPerStep; j++)
  151.         {
  152.             for (i = 0; i < DropsPerRay; i++)
  153.             {
  154.                 //------------------------------------------------- Aceleracao - random
  155.                 DropAccFactor = AccFactor + GetRandomFloat(0.0005);
  156.                 StepAngle = AngleOfDeepestStep + (90.0-AngleOfDeepestStep)
  157.                         * GLfloat(k) / (Steps-1) + GetRandomFloat(0.2+0.8*(Steps-k-1)/(Steps-1));
  158.                
  159.                 RayAngle = (GLfloat)j / (GLfloat)RaysPerStep * 360.0;
  160.                
  161.                 //------------------------------------------------- velocidade - - random
  162.                 //This is the speed caused by the step:
  163.                 NewSpeed.x = cos ( StepAngle * PI / 180.0) * (0.2+0.04*k);
  164.                 NewSpeed.y = sin ( StepAngle * PI / 180.0) * (0.2+0.04*k);
  165.                 //This is the speed caused by the ray:
  166.    
  167.                
  168.                 //for the next computations "NewSpeed.x" is the radius. Care! Dont swap the two
  169.                 //lines, because the second one changes NewSpeed.x!
  170.                 NewSpeed.z = NewSpeed.x * sin ( RayAngle * PI /180.0);
  171.                 NewSpeed.x = NewSpeed.x * cos ( RayAngle * PI /180.0);
  172.                
  173.                 //Calculate how many steps are required, that a drop comes out and falls down again
  174.                 //--------------------------------------------------- Tempo de vida util
  175.                 TimeNeeded = NewSpeed.y/ DropAccFactor;
  176.                 //--------------------------------------------------- Vertex Array
  177.                 FountainDrops[i+j*DropsPerRay+k*DropsPerRay*RaysPerStep].SetConstantSpeed ( NewSpeed );
  178.                 FountainDrops[i+j*DropsPerRay+k*DropsPerRay*RaysPerStep].SetAccFactor (DropAccFactor);
  179.                 FountainDrops[i+j*DropsPerRay+k*DropsPerRay*RaysPerStep].SetTime(TimeNeeded * i / DropsPerRay);
  180.             }
  181.         }
  182.     }
  183.  
  184.     //Tell OGL that we'll use the vertex array function
  185.     glEnableClientState(GL_VERTEX_ARRAY);
  186.     //Pass the date position
  187.     glVertexPointer(    3,          //x,y,z-components
  188.                         GL_FLOAT,   //data type of SVertex
  189.                         0,          //the vertices are tightly packed
  190.                         FountainVertices);
  191.                        
  192. }
  193.  
  194.  
  195.  
  196. void Reshape(int x, int y)
  197. {
  198.     if (y == 0 || x == 0) return;  //Nothing is visible then, so return
  199.     //Set a new projection matrix
  200.     glMatrixMode(GL_PROJECTION);  
  201.     glLoadIdentity();
  202.     //Angle of view:40 degrees
  203.     //Near clipping plane distance: 0.5
  204.     //Far clipping plane distance: 20.0
  205.     gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
  206.     glMatrixMode(GL_MODELVIEW);
  207.     glViewport(0,0,x,y);  //Use the whole window for rendering
  208.     //Adjust point size to window size
  209.     glPointSize(GLfloat(x)/200.0);
  210. }
  211.  
  212.  
  213.  
  214. //================================================================================
  215. //===========================================================Variaveis e constantes
  216.  
  217. //------------------------------------------------------------ Sistema Coordenadas + objectos
  218. GLint       wScreen=1000, hScreen=800;      //.. janela (pixeis)
  219. GLfloat     xC=1000.0, yC=1000.0, zC=1000.0;        //.. Mundo  (unidades mundo)
  220.  
  221. //------------------------------------------------------------ Observador
  222. GLfloat  rVisao=-300, aVisao=1*PI, incVisao=0.05;
  223. GLfloat  obsP[] ={rVisao*cos(aVisao), 50, rVisao*sin(aVisao)};
  224. GLfloat  angZoom=90;
  225. GLfloat  incZoom=3;
  226.  
  227.  
  228. GLdouble tx=obsP[0];
  229. GLdouble ty=0;
  230. GLdouble tz=obsP[2];
  231.  
  232. GLdouble Upx=0;
  233. GLdouble Upy=1;
  234. GLdouble Upz=0;
  235.  
  236. GLint temp[24];
  237.  
  238. //para subir e descer
  239. GLint flagSED = 0; //1->sobe, 0->inativa, -1 -> desce
  240. GLdouble sobeEdesce= 0;
  241.  
  242. //controlo do fogo de artificio
  243. GLint flagFA = 0; //1->fogo ativo, 0->inativo
  244.  
  245. //controlo colunas
  246. GLint flagColunas = 0; //1->colunas ativas, 0->inativas
  247.  
  248. //auxiliar de camera
  249.  
  250. float movementSpeed = 0.05;
  251.  
  252. GLfloat forwardVector[3] = {tx - obsP[0],ty - obsP[1], tz - obsP[2]};
  253. //forwardVector.normalise(); //lol
  254.  
  255. //particulas
  256. Particle  particula1[MAX_PARTICULAS];
  257.  
  258.  
  259. //texturas
  260. GLuint texture[6];
  261. RgbImage imag;
  262.  
  263.  
  264. static GLfloat arrayTexture[]={
  265. 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1,  0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1, 0,0, 1,0, 1,1, 0,1
  266. };
  267.  
  268.  
  269. //=========================================================== FACES DA MESA
  270. GLboolean   frenteVisivel=1;
  271. static GLuint     **ordem = new GLuint*[SIZE/4]();
  272. static GLuint     **ordemMini = new GLuint*[SIZEMINI/4]();
  273.  
  274. GLfloat tam=2.0;
  275. static GLfloat vertices[]={
  276.     -30.000000, -0.000000, 96.000000, 30.000000, -0.000000, 96.000000, 30.000000, 0.000000, 0.000000, -30.000000, 0.000000, 0.000000, -30.000000, 0.000000, 96.000000, 30.000000, 0.000000, 96.000000, 30.000000, 16.000000, 96.000000, -30.000000, 16.000000, 96.000000, -30.000000, 16.000000, 128.000000, 30.000000, 16.000000, 128.000000, 30.000000, 16.000000, 96.000000, -30.000000, 16.000000, 96.000000, -30.000000, 16.000000, 128.000000, 30.000000, 16.000000, 128.000000, 30.000000, 32.000000, 128.000000, -30.000000, 32.000000, 128.000000, -30.000000, 32.000000, 160.000000, 30.000000, 32.000000, 160.000000, 30.000000, 32.000000, 128.000000, -30.000000, 32.000000, 128.000000, -30.000000, 32.000000, 160.000000, 30.000000, 32.000000, 160.000000, 30.000000, 48.000000, 160.000000, -30.000000, 48.000000, 160.000000, -30.000000, 48.000000, 192.000000, 30.000000, 48.000000, 192.000000, 30.000000, 48.000000, 160.000000, -30.000000, 48.000000, 160.000000, -30.000000, 48.000000, 192.000000, 30.000000, 48.000000, 192.000000, 30.000000, 64.000000, 192.000000, -30.000000, 64.000000, 192.000000, -30.000000, 64.000000, 224.000000, 30.000000, 64.000000, 224.000000, 30.000000, 64.000000, 192.000000, -30.000000, 64.000000, 192.000000, -30.000000, 64.000000, 224.000000, 30.000000, 64.000000, 224.000000, 30.000000, 80.000000, 224.000000, -30.000000, 80.000000, 224.000000, -30.000000, 80.000000, 256.000000, 30.000000, 80.000000, 256.000000, 30.000000, 80.000000, 224.000000, -30.000000, 80.000000, 224.000000, -30.000000, 80.000000, 256.000000, 30.000000, 80.000000, 256.000000, 30.000000, 96.000000, 256.000000, -30.000000, 96.000000, 256.000000, -30.000000, 96.000000, 352.000000, 30.000000, 96.000000, 352.000000, 30.000000, 96.000000, 256.000000, -30.000000, 96.000000, 256.000000
  277. };
  278.  
  279.  
  280. static GLfloat normais[] = {
  281.     0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000
  282. };
  283. //------------------------------------------------------------ Cores
  284. static GLfloat cores[]={
  285.     0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000
  286. };
  287.  
  288.  
  289. static GLfloat verticesMini[]={
  290. -30.000000, 0.000000, 0.000000, 30.000000, 0.000000, 0.000000, 30.000000, 16.000000, 0.000000, -30.000000, 16.000000, 0.000000, -30.000000, 16.000000, 32.000000, 30.000000, 16.000000, 32.000000, 30.000000, 16.000000, 0.000000, -30.000000, 16.000000, 0.000000, -30.000000, 16.000000, 32.000000, 30.000000, 16.000000, 32.000000, 30.000000, 32.000000, 32.000000, -30.000000, 32.000000, 32.000000, -30.000000, 32.000000, 64.000000, 30.000000, 32.000000, 64.000000, 30.000000, 32.000000, 32.000000, -30.000000, 32.000000, 32.000000, -30.000000, 32.000000, 64.000000, 30.000000, 32.000000, 64.000000, 30.000000, 48.000000, 64.000000, -30.000000, 48.000000, 64.000000, -30.000000, 48.000000, 96.000000, 30.000000, 48.000000, 96.000000, 30.000000, 48.000000, 64.000000, -30.000000, 48.000000, 64.000000, -30.000000, 48.000000, 96.000000, 30.000000, 48.000000, 96.000000, 30.000000, 64.000000, 96.000000, -30.000000, 64.000000, 96.000000, -30.000000, 64.000000, 192.000000, 30.000000, 64.000000, 192.000000, 30.000000, 64.000000, 96.000000, -30.000000, 64.000000, 96.000000
  291. };
  292.  
  293. static GLfloat normaisMini[] = {
  294.     0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000
  295. };
  296.  
  297. static GLfloat coresMini[]={
  298.     0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000
  299. };
  300.  
  301. //================================================================================
  302. //=========================================================================== INIT
  303. void inicializa(int escada)
  304. {
  305.     glClearColor(BLACK);        //………………………………………………………………………………Apagar
  306.     glEnable(GL_DEPTH_TEST);    //………………………………………………………………………………Profundidade
  307.     glShadeModel(GL_SMOOTH);    //………………………………………………………………………………Interpolacao de cores
  308.  
  309.    
  310.     if(escada==1){
  311.         glVertexPointer(3, GL_FLOAT, 0, vertices); //………………………………………Vertex arrays
  312.         glEnableClientState(GL_VERTEX_ARRAY);
  313.         glNormalPointer(GL_FLOAT, 0, normais);// normais
  314.         glEnableClientState(GL_NORMAL_ARRAY);
  315.         glColorPointer(3, GL_FLOAT, 0, cores);
  316.         glEnableClientState(GL_COLOR_ARRAY);  
  317.     } if(escada==0) {
  318.         glVertexPointer(3, GL_FLOAT, 0, verticesMini); //………………………………………Vertex arrays
  319.         glEnableClientState(GL_VERTEX_ARRAY);
  320.         glNormalPointer(GL_FLOAT, 0, normaisMini);// normais
  321.         glEnableClientState(GL_NORMAL_ARRAY);
  322.         glColorPointer(3, GL_FLOAT, 0, coresMini);
  323.         glEnableClientState(GL_COLOR_ARRAY);  
  324.     } if(escada == 2) { //paredes em volta
  325.        
  326.     }
  327.    
  328.    
  329. }
  330.  
  331. void initTexturas()
  332. {  
  333.     //----------------------------------------- paredes
  334.     glGenTextures(1, &texture[0]);
  335.     glBindTexture(GL_TEXTURE_2D, texture[0]);
  336.     //imag.LoadBmpFile("pedra.bmp");
  337.     RgbImage pedra("pedra.bmp");
  338.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  
  339.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  340.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  341.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  342.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  343.    
  344.     /*glTexImage2D(GL_TEXTURE_2D, 0, 3,
  345.         imag.GetNumCols(),
  346.         imag.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
  347.         imag.ImageData()); */
  348.        
  349.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
  350.         pedra.GetNumCols(),
  351.         pedra.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE,
  352.         pedra.ImageData());  
  353.        
  354.  
  355.     //----------------------------------------- tubos
  356.     glGenTextures(1, &texture[1]);
  357.     glBindTexture(GL_TEXTURE_2D, texture[1]);
  358.     //imag.LoadBmpFile("blackMetal.bmp");
  359.     RgbImage blackMetal("blackMetal.bmp");
  360.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  
  361.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  362.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  363.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  364.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  365.    
  366.     /*glTexImage2D(GL_TEXTURE_2D, 0, 3,
  367.         imag.GetNumCols(),
  368.         imag.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
  369.         imag.ImageData());  */
  370.        
  371.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
  372.         blackMetal.GetNumCols(),
  373.         blackMetal.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE,
  374.         blackMetal.ImageData());
  375.  
  376.     //----------------------------------------- escadas
  377.     glGenTextures(1, &texture[2]);
  378.     glBindTexture(GL_TEXTURE_2D, texture[2]);
  379.     //imag.LoadBmpFile("gucciGang.bmp");
  380.     RgbImage gucciGang("gucciGang.bmp");
  381.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  
  382.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  383.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  384.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  385.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  386.    
  387.     /*glTexImage2D(GL_TEXTURE_2D, 0, 3,
  388.         imag.GetNumCols(),
  389.         imag.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
  390.         imag.ImageData());*/
  391.        
  392.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
  393.         gucciGang.GetNumCols(),
  394.         gucciGang.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE,
  395.         gucciGang.ImageData());
  396.        
  397.     //----------------------------------------- escadasv2
  398.     glGenTextures(1, &texture[3]);
  399.     glBindTexture(GL_TEXTURE_2D, texture[3]);
  400.     //imag.LoadBmpFile("wood.bmp");
  401.     RgbImage wood("wood.bmp");
  402.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  
  403.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  404.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  405.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  406.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  407.    
  408.     /*glTexImage2D(GL_TEXTURE_2D, 0, 3,
  409.         imag.GetNumCols(),
  410.         imag.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
  411.         imag.ImageData());*/
  412.    
  413.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
  414.         wood.GetNumCols(),
  415.         wood.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE,
  416.         wood.ImageData());
  417.    
  418.     //-------------------------------------------------fogo artificio
  419.     glGenTextures(1, &texture[4]);
  420.     glBindTexture(GL_TEXTURE_2D, texture[4]);
  421.     //imag.LoadBmpFile("brilho0.bmp");
  422.     RgbImage brilho("fogo.bmp");
  423.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  424.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  425.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  426.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  427.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  428.     /*glTexImage2D(GL_TEXTURE_2D, 0, 3,
  429.         imag.GetNumCols(),
  430.         imag.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
  431.         imag.ImageData());  */
  432.                  
  433.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
  434.         brilho.GetNumCols(),
  435.         brilho.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE,
  436.         brilho.ImageData());
  437.        
  438.     //-------------------------------------------------agua
  439.     glGenTextures(1, &texture[5]);
  440.     glBindTexture(GL_TEXTURE_2D, texture[5]);
  441.     //imag.LoadBmpFile("brilho0.bmp");
  442.     RgbImage water("water.bmp");
  443.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  444.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  445.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  446.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  447.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  448.     /*glTexImage2D(GL_TEXTURE_2D, 0, 3,
  449.         imag.GetNumCols(),
  450.         imag.GetNumRows(), 0, GL_RGB, GL_UNSIGNED_BYTE,
  451.         imag.ImageData());  */
  452.                  
  453.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
  454.         water.GetNumCols(),
  455.         water.GetNumRows(), GL_RGB, GL_UNSIGNED_BYTE,
  456.         water.ImageData());
  457.    
  458.        
  459. }
  460.  
  461. //==========================================================
  462. void iniParticulas(Particle *particula, int tipo)
  463. {
  464.     GLfloat v, theta, phi;
  465.     int i;
  466.     GLfloat px, py, pz;
  467.     GLfloat ps;
  468.  
  469.     /*px = 175.0;
  470.     py = 290.0;
  471.     pz = 200.0;*/
  472.    
  473.     if(tipo == 1){
  474.         px = 175.0+0.5*frand()*175;
  475.         py = 290.0;//+0.25*frand()*290;
  476.         pz = 200.0+0.5*frand()*200;
  477.         ps = 1.5;
  478.    
  479.        
  480.         for(i=0; i<MAX_PARTICULAS; i++)  {
  481.    
  482.             //---------------------------------  
  483.             v = 3*frand()+0.02;
  484.             theta = 2.0*frand()*M_PI;   // [0..2pi]
  485.             phi   = frand()*M_PI;       // [0.. pi]
  486.    
  487.             particula[i].size = ps ;        // tamanh de cada particula
  488.             particula[i].x    = px ;//+ 0.1*frand()*px;    // [-200 200]
  489.             particula[i].y    = py ;//+ 0.1*frand()*py; // [-200 200]
  490.             particula[i].z    = pz ;//+ 0.1*frand()*pz; // [-200 200]
  491.        
  492.             particula[i].vx = v * cos(theta) * sin(phi);    // esferico
  493.             particula[i].vy = v * cos(phi);
  494.             particula[i].vz = v * sin(theta) * sin(phi);
  495.             particula[i].ax = 0.01f;
  496.             particula[i].ay = -0.01f;
  497.             particula[i].az = 0.015f;
  498.  
  499.         particula[i].r = 0.1f;
  500.         particula[i].g = 0.1f;
  501.         particula[i].b = 0.1f;
  502.         particula[i].life = 1.0f;                      
  503.         particula[i].fade = 0.001f; // Em 100=1/0.01 iteracoes desaparece
  504.         }
  505.     }
  506.     else if(tipo == 2){
  507.         px = 20.0;//175.0+0.5*frand()*175;
  508.         py = 10.0;//290.0;//+0.25*frand()*290;
  509.         pz = 0.0;//200.0+0.5*frand()*200;
  510.         ps = 4.5;
  511.    
  512.        
  513.         for(i=0; i<MAX_PARTICULAS; i++)  {
  514.    
  515.             //---------------------------------  
  516.             v = 3*frand()+0.02;
  517.             theta = 2.0*frand()*M_PI;   // [0..2pi]
  518.             phi   = frand()*M_PI;       // [0.. pi]
  519.    
  520.             particula[i].size = ps ;        // tamanh de cada particula
  521.             particula[i].x    = px ;//+ 0.1*frand()*px;    // [-200 200]
  522.             particula[i].y    = py ;//+ 0.1*frand()*py; // [-200 200]
  523.             particula[i].z    = pz ;//+ 0.1*frand()*pz; // [-200 200]
  524.        
  525.             particula[i].vx = 0;//v ;//* cos(theta) * sin(phi); // esferico
  526.             particula[i].vy = v;
  527.             particula[i].vz = 0;//v ;//* sin(theta) * sin(phi);
  528.             particula[i].ax = 0;//0.01f;
  529.             particula[i].ay = 0;//-0.01f;
  530.             particula[i].az = 0;//0.015f;
  531.  
  532.         particula[i].r = 0.1f;
  533.         particula[i].g = 0.1f;
  534.         particula[i].b = 0.1f;
  535.         particula[i].life = 1.0f;                      
  536.         particula[i].fade = 0.001f; // Em 100=1/0.01 iteracoes desaparece
  537.         }
  538.     }
  539. }
  540.  
  541.  
  542.  
  543. void showParticulas(Particle *particula, int sistema) {
  544.     int i;
  545.     int numero;
  546.  
  547.     numero=(int) (frand()*10.0);
  548.     for (i=0; i<MAX_PARTICULAS; i++){
  549.  
  550.         glColor4f(1,1,1, particula[i].life);
  551.         glEnable(GL_TEXTURE_2D);
  552.         glBindTexture(GL_TEXTURE_2D,texture[5]);
  553.         glBegin(GL_POINTS);                
  554.             glTexCoord2d(0,0); glVertex3f(particula[i].x -particula[i].size, particula[i].y -particula[i].size, particula[i].z);      
  555.             glTexCoord2d(1,0); glVertex3f(particula[i].x +particula[i].size+40, particula[i].y -particula[i].size, particula[i].z);        
  556.             /*glTexCoord2d(1,1); glVertex3f(particula[i].x +particula[i].size, particula[i].y +particula[i].size, particula[i].z);            
  557.             glTexCoord2d(0,1); glVertex3f(particula[i].x -particula[i].size, particula[i].y +particula[i].size, particula[i].z);*/
  558.         glEnd();
  559.         glDisable(GL_TEXTURE_2D);
  560.         particula[i].x += particula[i].vx;
  561.         particula[i].y += particula[i].vy;
  562.         particula[i].z += particula[i].vz;
  563.         particula[i].vx += particula[i].ax;
  564.         particula[i].vy += particula[i].ay;
  565.         particula[i].vz += particula[i].az;
  566.         particula[i].life -= particula[i].fade;
  567.     }
  568.  
  569. }
  570.  
  571. void DrawFountain(void)
  572. {
  573.     glColor4f(0.8,0.8,0.8,0.8);
  574.     for (int i = 0; i < DropsTotal; i++)
  575.     {
  576.         FountainDrops[i].ComputeNewPosition(&FountainVertices[i]);
  577.     }
  578.     glEnable(GL_TEXTURE_2D);
  579.     glBindTexture(GL_TEXTURE_2D,texture[5]);
  580.     glDrawArrays(GL_POINTS, 0, DropsTotal);     // desenhar pontos
  581.     glDisable(GL_TEXTURE_2D);
  582. }
  583.  
  584.  
  585. void drawEixos()
  586. {  
  587.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo X
  588.     glColor4f(RED);
  589.     glBegin(GL_LINES);
  590.         glVertex3i( 0, 0, 0);
  591.         glVertex3i(200, 0, 0);
  592.     glEnd();
  593.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo Y
  594.     glColor4f(GREEN);
  595.     glBegin(GL_LINES);
  596.         glVertex3i(0,  0, 0);
  597.         glVertex3i(0, 200, 0);
  598.     glEnd();
  599.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo Z
  600.     glColor4f(BLUE);
  601.     glBegin(GL_LINES);
  602.         glVertex3i( 0, 0, 0);
  603.         glVertex3i( 0, 0, 200);
  604.     glEnd();
  605.  
  606. }  
  607.  
  608. void tubos(){
  609.     glClearColor(BLACK);        //………………………………………………………………………………Apagar
  610.     glEnable(GL_DEPTH_TEST);    //………………………………………………………………………………Profundidade
  611.    
  612.     glEnable(GL_TEXTURE_2D);
  613.     glBindTexture(GL_TEXTURE_2D,texture[1]);
  614.    
  615.     int acum = 0;
  616.     int i = 0;
  617.     //PARTE FRENTE
  618.     glPushMatrix();
  619.         while(acum<=352){
  620.             glBegin(GL_POLYGON);
  621.                 glTexCoord2f ( 0, 0 ); glVertex3f(  -30, 0+sobeEdesce, acum );
  622.            
  623.             acum += temp[i];
  624.                 glTexCoord2f ( 1, 0 ); glVertex3f(  -30, 0+sobeEdesce, acum );    
  625.                 glTexCoord2f ( 0, 1 ); glVertex3f( -30,  325, acum);    
  626.                 glTexCoord2f ( 1, 1 ); glVertex3f( -30, 325, acum-temp[i] );
  627.             glEnd();
  628.             //printf("%d\t", temp);
  629.  
  630.             acum += temp[i];
  631.             i++;
  632.             //printf("%d\t", temp);
  633.         }    
  634.         i=0;
  635.     //  printf("parte da frente -> %d\t", aux); aux = 0;
  636.     glPopMatrix();
  637.     //PARTE TRAS
  638.     glPushMatrix();
  639.         acum = -30;
  640.         while(acum<=220 + 30){
  641.             glBegin(GL_POLYGON);
  642.                 glTexCoord2f ( 0, 0 ); glVertex3f(  acum, 0+sobeEdesce, 352 );
  643.        
  644.             acum += temp[i];
  645.                 glTexCoord2f ( 1, 0 ); glVertex3f(  acum, 0+sobeEdesce, 352 );    
  646.                 glTexCoord2f ( 0, 1 ); glVertex3f( acum,  325, 352);    
  647.                 glTexCoord2f ( 1, 1 ); glVertex3f( acum-temp[i], 325, 352 );
  648.             glEnd();
  649.             //printf("%d\t", temp);
  650.            
  651.             acum += temp[i];
  652.             //printf("%d\t", temp);
  653.             i++;
  654.         }    
  655.         i=0;
  656.         //printf("parte da lado -> %d\t", aux); aux = 0;
  657.     glPopMatrix();
  658.     //PARTE TRAS2
  659.     glPushMatrix();
  660.         acum = 0;
  661.         while(acum<=352){
  662.             glBegin(GL_POLYGON);
  663.                 glTexCoord2f ( 0, 0 ); glVertex3f(  250, 0+sobeEdesce, acum );
  664.            
  665.             acum += temp[i];
  666.                 glTexCoord2f ( 0, 1 ); glVertex3f(  250, 0+sobeEdesce, acum );    
  667.                 glTexCoord2f ( 1, 0 ); glVertex3f( 250,  325, acum);    
  668.                 glTexCoord2f ( 1, 1 ); glVertex3f( 250, 325, acum-temp[i] );
  669.             glEnd();
  670.             //printf("%d\t", temp);
  671.            
  672.             acum += temp[i];
  673.             i++;
  674.             //printf("%d\t", temp);
  675.         }    
  676.         i=0;
  677.     glPopMatrix();
  678.     //PARTE FRENTE2 LOL
  679.     glPushMatrix();
  680.         acum = -30;
  681.         while(acum<=220 + 30){
  682.             glBegin(GL_POLYGON);
  683.                 glTexCoord2f ( 0, 0 );glVertex3f(  acum, 0+sobeEdesce, 0 );
  684.            
  685.             acum += temp[i];
  686.                 glTexCoord2f ( 0, 1 );glVertex3f(  acum, 0+sobeEdesce, 0 );    
  687.                 glTexCoord2f ( 1, 0 );glVertex3f( acum,  325, 0);    
  688.                 glTexCoord2f ( 1, 1 );  glVertex3f( acum-temp[i], 325, 0 );
  689.             glEnd();
  690.             //printf("%d\t", temp);
  691.            
  692.             acum += temp[i];
  693.             i++;
  694.             //printf("%d\t", temp);
  695.         }    
  696.         i=0;
  697.         glDisable(GL_TEXTURE_2D);
  698.        
  699.     glPopMatrix();
  700.    
  701. }
  702.  
  703. void cenario(){
  704.     glClearColor(WHITE);        //………………………………………………………………………………Apagar
  705.     glEnable(GL_DEPTH_TEST);    //………………………………………………………………………………Profundidade
  706.    
  707.    
  708.    
  709.     glEnable(GL_TEXTURE_2D);
  710.     glBindTexture(GL_TEXTURE_2D,texture[0]);
  711.    
  712.     glPushMatrix();
  713.         glTranslatef(0,162.5,100); //nivelar
  714.         glScalef( 650.0, 650.0/2, 650.0 );
  715.        
  716.        
  717.         glBegin(GL_POLYGON);
  718.         glTexCoord2f ( 0, 0 ); glVertex3f(  0.5, -0.5, -0.5 );    
  719.         glTexCoord2f ( 1, 0 ); glVertex3f(  0.5,  0.5, -0.5 );      
  720.         glTexCoord2f ( 0, 1 ); glVertex3f( -0.5,  0.5, -0.5 );    
  721.         glTexCoord2f ( 1, 1 ); glVertex3f( -0.5, -0.5, -0.5 );  
  722.        
  723.            
  724.         glEnd();
  725.        
  726.         glBegin(GL_POLYGON);
  727.         glTexCoord2f ( 0, 0 ); glVertex3f(  0.5, -0.5, 0.5 );
  728.         glTexCoord2f ( 1, 0 ); glVertex3f(  0.5,  0.5, 0.5 );
  729.         glTexCoord2f ( 0, 1 ); glVertex3f( -0.5,  0.5, 0.5 );
  730.         glTexCoord2f ( 1, 1 ); glVertex3f( -0.5, -0.5, 0.5 );
  731.         glEnd();
  732.        
  733.         glBegin(GL_POLYGON);
  734.         glTexCoord2f ( 0, 0 ); glVertex3f( 0.5, -0.5, -0.5 );
  735.         glTexCoord2f ( 1, 0 ); glVertex3f( 0.5,  0.5, -0.5 );
  736.         glTexCoord2f ( 0, 1 ); glVertex3f( 0.5,  0.5,  0.5 );
  737.         glTexCoord2f ( 1, 1 ); glVertex3f( 0.5, -0.5,  0.5 );
  738.         glEnd();
  739.        
  740.         glBegin(GL_POLYGON);
  741.         glTexCoord2f ( 0, 0 ); glVertex3f( -0.5, -0.5, 0.5 );
  742.         glTexCoord2f ( 1, 0 ); glVertex3f( -0.5,  0.5,  0.5 );
  743.         glTexCoord2f ( 0, 1 ); glVertex3f( -0.5,  0.5, -0.5 );
  744.         glTexCoord2f ( 1, 1 ); glVertex3f( -0.5, -0.5, -0.5 );
  745.         glEnd();
  746.        
  747.         glBegin(GL_POLYGON);
  748.         glTexCoord2f ( 0, 0 ); glVertex3f(  0.5,  0.5,  0.5 );
  749.         glTexCoord2f ( 1, 0 ); glVertex3f(  0.5,  0.5, -0.5 );
  750.         glTexCoord2f ( 0, 1 ); glVertex3f( -0.5,  0.5, -0.5 );
  751.         glTexCoord2f ( 1, 1 );glVertex3f( -0.5,  0.5,  0.5 );
  752.         glEnd();
  753.        
  754.         glBegin(GL_POLYGON);
  755.         glTexCoord2f ( 0, 0 ); glVertex3f(  0.5, -0.5, -0.5 );
  756.         glTexCoord2f ( 1, 0 ); glVertex3f(  0.5, -0.5,  0.5 );
  757.         glTexCoord2f ( 0, 1 ); glVertex3f( -0.5, -0.5, 0.5 );
  758.         glTexCoord2f ( 1, 1 ); glVertex3f( -0.5, -0.5, -0.5 );
  759.         glEnd();
  760.     glPopMatrix();
  761.      
  762.      
  763.      glDisable(GL_TEXTURE_2D);
  764.      
  765.      //tubos
  766.      tubos();  
  767.  
  768. }
  769.  
  770.  
  771.  
  772. void drawScene(){
  773.  
  774.     //subir e descer os tubos que nao sao tubos
  775.    
  776.    
  777.    
  778. //cenario
  779.     cenario();
  780.     inicializa(1);
  781.    
  782.     glEnable(GL_TEXTURE_2D);
  783.    
  784.     glBindTexture(GL_TEXTURE_2D,texture[2]);
  785.     //em frente
  786.     glPushMatrix();
  787.     //glTranslatef(40, 0, 0);
  788.     for(int i=0; i<SIZE/4; i++) {
  789.         if(i%2==0)
  790.             glBindTexture(GL_TEXTURE_2D,texture[2]);
  791.         else
  792.             glBindTexture(GL_TEXTURE_2D,texture[3]);
  793.         glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, ordem[i]);
  794.     }
  795.     glPopMatrix();
  796.    
  797.     //para tras
  798.     glPushMatrix();
  799.     glTranslatef(222, 160, 351);
  800.     glRotatef(180,0,1,0);
  801.     for(int i=0; i<SIZE/4; i++) {
  802.         if(i%2==0)
  803.             glBindTexture(GL_TEXTURE_2D,texture[2]);
  804.         else
  805.             glBindTexture(GL_TEXTURE_2D,texture[3]);
  806.         glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, ordem[i]);
  807.     }
  808.     glPopMatrix();
  809.    
  810.     //para o lado
  811.     inicializa(0);
  812.     glPushMatrix();
  813.     glTranslatef(30, 96, 322);
  814.     glRotatef(90,0,1,0);
  815.     for(int i=0; i<SIZEMINI/4; i++) {
  816.         if(i%2==0)
  817.             glBindTexture(GL_TEXTURE_2D,texture[2]);
  818.         else
  819.             glBindTexture(GL_TEXTURE_2D,texture[3]);
  820.         glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, ordem[i]);
  821.     }
  822.     glPopMatrix();
  823.    
  824. }
  825.  
  826. void display(void){
  827.    
  828.     //================================================================= APaga ecran/profundidade
  829.      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  830.    
  831.     //3D
  832.     //glViewport (0, 0, wScreen, hScreen);                                // ESQUECER PoR AGORA
  833.     glMatrixMode(GL_PROJECTION);                                        // ESQUECER PoR AGORA
  834.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  835.     //glOrtho( -20, 20, -20, 20, -20, 20);
  836.     gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC);         // ESQUECER PoR AGORA
  837.     glMatrixMode(GL_MODELVIEW);                                         // ESQUECER PoR AGORA  
  838.     glLoadIdentity();
  839.     //-------------------------------------------------------------- observador
  840.     gluLookAt(obsP[0], obsP[1], obsP[2], tx,ty,tz, Upx, Upy, Upz);
  841.    
  842.  
  843.     //drawEixos();
  844.     drawScene();
  845.    
  846.     showParticulas(particula1, 1);
  847.    
  848.     DrawFountain();
  849.     glFlush();
  850.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actualizacao
  851.     glutSwapBuffers();
  852. }
  853.  
  854. void keyboard(unsigned char key, int x, int y){
  855.  
  856.     forwardVector[0] = tx - obsP[0];
  857.     forwardVector[1] = ty - obsP[1];
  858.     forwardVector[2] = tz - obsP[2];
  859.  
  860.     switch (key) {
  861.    
  862.     case 'W':
  863.     case 'w':
  864.         //moving forward :
  865.         obsP[0] += forwardVector[0] * movementSpeed;
  866.         obsP[1] += forwardVector[1] * movementSpeed;
  867.         obsP[2] += forwardVector[2] * movementSpeed;
  868.         tx += forwardVector[0] * movementSpeed;
  869.         ty += forwardVector[1] * movementSpeed;
  870.         tz += forwardVector[2] * movementSpeed;
  871.         glutPostRedisplay();
  872.     break;
  873.  
  874.     case 'S':
  875.     case 's':
  876.         //moving backward :
  877.         obsP[0] -= forwardVector[0] * movementSpeed;
  878.         obsP[1] -= forwardVector[1] * movementSpeed;
  879.         obsP[2] -= forwardVector[2] * movementSpeed;
  880.         tx -= forwardVector[0] * movementSpeed;
  881.         ty -= forwardVector[1] * movementSpeed;
  882.         tz -= forwardVector[2] * movementSpeed;
  883.         glutPostRedisplay();
  884.     break;
  885.  
  886.     case 'U':
  887.     case 'u':
  888.         if(flagSED == 1) {
  889.             flagSED = 0;
  890.         } else {
  891.             flagSED = 1;  
  892.         }
  893.    
  894.        
  895.         glutPostRedisplay();
  896.     break;
  897.    
  898.     case 'D':
  899.     case 'd':
  900.         if(flagSED == -1) {
  901.             flagSED = 0;
  902.         } else {
  903.             flagSED = -1;  
  904.         }
  905.         glutPostRedisplay();
  906.     break;
  907.    
  908.     case 'F':
  909.     case 'f':
  910.         if(flagFA == 1) {
  911.             flagFA = 0;
  912.         } else {
  913.             flagFA = 1;
  914.         }
  915.    
  916.     case 'E':
  917.     case 'e':
  918.         if(flagColunas == 1) {
  919.             flagColunas = 0;
  920.         } else {
  921.             flagColunas = 1;
  922.         }
  923.            
  924.         break;
  925.    
  926. //--------------------------- Escape
  927.     case 27:
  928.         exit(0);
  929.         break;
  930.   }
  931.  
  932. }
  933.  
  934.  
  935.  
  936. void teclasNotAscii(int key, int x, int y){
  937.  
  938.         if(key == GLUT_KEY_UP){
  939.             //aVisaoAux = (aVisaoAux + 0.1) ;
  940.             //printf("antes -> %f\n", ty);
  941.             ty = ty + rVisao*sin(-0.1);
  942.             //printf("depois -> %f\n", ty);
  943.         }  
  944.         if(key == GLUT_KEY_DOWN){
  945.             //aVisaoAux = (aVisaoAux - 0.1) ;
  946.             ty = ty + rVisao*sin(0.1);
  947.         }
  948.  
  949.         if(key == GLUT_KEY_LEFT) {
  950.             aVisao = (aVisao - 0.1) ;
  951.             //printf("antes -> %f\n", tx);
  952.             tx = obsP[0] + rVisao*cos(aVisao);
  953.             tz = obsP[2] + rVisao*sin(aVisao);
  954.             //printf("depois -> %f\n", tx);
  955.            
  956.         }                                                  
  957.            
  958.         if(key == GLUT_KEY_RIGHT){
  959.             aVisao = (aVisao + 0.1) ;
  960.             tx =obsP[0] + rVisao*cos(aVisao);
  961.             tz =obsP[2] + rVisao*sin(aVisao);  
  962.         }                            
  963.                        
  964.     glutPostRedisplay();  
  965.  
  966. }
  967.  
  968. void Timer(int value) {
  969.     if(flagSED == 1) { //vai subir
  970.         if(sobeEdesce<315) {
  971.             sobeEdesce += 8;
  972.         }
  973.         else {
  974.             flagSED = 0;
  975.         }
  976.     }  
  977.    
  978.     if(flagSED == -1) { //vai descer
  979.         if(sobeEdesce>0) {
  980.             sobeEdesce -= 8;
  981.         }
  982.         else {
  983.             flagSED = 0;
  984.         }
  985.     }
  986.     glutPostRedisplay();
  987.     glutTimerFunc(100, Timer, 1);
  988.    
  989. }
  990.  
  991. //loop do fogo de artificio
  992. void TimerFogo(int value)
  993. {
  994.     if(flagFA == 1) { //vai comecar o fogo
  995.         iniParticulas(particula1, 1);
  996.        
  997.     }
  998.     else {
  999.         flagFA = 0;
  1000.     }
  1001.  
  1002.     glutPostRedisplay();
  1003.     glutTimerFunc(3500 ,TimerFogo, 1);   //.. Espera msecDelay milisegundos
  1004. }
  1005.  
  1006. //loop do fogo de artificio
  1007. void TimerColunas(int value)
  1008. {
  1009.     if(flagColunas == 1) { //vai comecar o fogo
  1010.         iniParticulas(particula1, 2);
  1011.        
  1012.     }
  1013.     else {
  1014.         flagColunas = 0;
  1015.     }
  1016.  
  1017.     glutPostRedisplay();
  1018.     glutTimerFunc(3500 ,TimerColunas, 1);   //.. Espera msecDelay milisegundos
  1019. }
  1020.  
  1021. //======================================================= MAIN
  1022. //======================================================= MAIN
  1023. int main(int argc, char** argv){
  1024.  
  1025.    
  1026.     glutInit(&argc, argv);
  1027.     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
  1028.     glutInitWindowSize (wScreen, hScreen);
  1029.     glutInitWindowPosition (300, 100);
  1030.     glutCreateWindow ("|Fogo-artificio:'f'|      |Observador:'SETAS'|        |Andar-'w/s'|        |Colunas-'e'|        |Barras -'u/d'| ");
  1031.    
  1032.     glTexCoordPointer(2, GL_FLOAT, 0, arrayTexture);
  1033.     glEnableClientState(GL_TEXTURE_COORD_ARRAY);  
  1034.    
  1035.     glEnable(GL_DEPTH_TEST);
  1036.     glClearColor(0.1,0.1,0.1,0.0);
  1037.     glEnable(GL_POINT_SMOOTH);
  1038.     glEnable(GL_BLEND);
  1039.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1040.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  1041.    
  1042.     //escadas grandes
  1043.     int acum = 0;
  1044.     for(int i = 0; i < SIZE/4; i++){
  1045.         ordem[i] = new GLuint[4];
  1046.     }
  1047.        
  1048.     for(int i = 0; i<SIZE/4; i++) {
  1049.         for(int j=0; j<4; j++){
  1050.             ordem[i][j] = acum;
  1051.             acum++;
  1052.         }
  1053.     }
  1054.    
  1055.     //escadas pequenas
  1056.     acum = 0;
  1057.     for(int i = 0; i < SIZEMINI/4; i++){
  1058.         ordemMini[i] = new GLuint[4];
  1059.     }
  1060.        
  1061.     for(int i = 0; i<SIZEMINI/4; i++) {
  1062.         for(int j=0; j<4; j++){
  1063.             ordemMini[i][j] = acum;
  1064.             acum++;
  1065.         }
  1066.     }
  1067.    
  1068.     //aleatorios para tubos
  1069.     for(int i=0; i<24; i++){
  1070.         temp[i]= rand() %10 + 8;  
  1071.     }
  1072.     initTexturas();
  1073.     InitFountain();
  1074.    
  1075.     glutSpecialFunc(teclasNotAscii);
  1076.     glutDisplayFunc(display);
  1077.     glutReshapeFunc(Reshape);
  1078.     glutKeyboardFunc(keyboard);
  1079.    
  1080.     //motor
  1081.     glutTimerFunc(100, Timer, 1);
  1082.     glutTimerFunc(3500, TimerFogo, 1);
  1083.     glutTimerFunc(3500, TimerColunas, 1);
  1084.    
  1085.     glutMainLoop();
  1086.  
  1087.     return 0;
  1088. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top