Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.88 KB | None | 0 0
  1.  
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <GL/glut.h>
  7.  
  8. //--------------------------------- Definir cores
  9. #define BLUE 0.0, 0.0, 1.0, 1.0
  10. #define RED 1.0, 0.0, 0.0, 1.0
  11. #define YELLOW 1.0, 1.0, 0.0, 1.0
  12. #define GREEN 0.0, 1.0, 0.0, 1.0
  13. #define WHITE 1.0, 1.0, 1.0, 1.0
  14. #define BLACK 0.0, 0.0, 0.0, 1.0
  15. #define PI 3.14159
  16. #define SIZE 156
  17. #define SIZEMINI 96
  18.  
  19. //================================================================================
  20. //===========================================================Variaveis e constantes
  21.  
  22. //------------------------------------------------------------ Sistema Coordenadas + objectos
  23. GLint wScreen=1000, hScreen=800; //.. janela (pixeis)
  24. GLfloat xC=1000.0, yC=1000.0, zC=1000.0; //.. Mundo (unidades mundo)
  25.  
  26. //------------------------------------------------------------ Observador
  27. GLfloat rVisao=-300, aVisao=1*PI, incVisao=0.05;
  28. GLfloat obsP[] ={rVisao*cos(aVisao), 50, rVisao*sin(aVisao)};
  29. GLfloat angZoom=90;
  30. GLfloat incZoom=3;
  31.  
  32. GLdouble tx=0;
  33. GLdouble ty=0;
  34. GLdouble tz=0;
  35.  
  36. GLdouble Upx=0;
  37. GLdouble Upy=1;
  38. GLdouble Upz=0;
  39.  
  40. //auxiliar de camera
  41.  
  42. float movementSpeed = 0.05;
  43.  
  44. GLfloat forwardVector[3] = {tx - obsP[0],ty - obsP[1], tz - obsP[2]};
  45. //forwardVector.normalise(); //lol
  46.  
  47. //=========================================================== FACES DA MESA
  48. GLboolean frenteVisivel=1;
  49. static GLuint **ordem = new GLuint*[SIZE/4]();
  50. static GLuint **ordemMini = new GLuint*[SIZEMINI/4]();
  51.  
  52. GLfloat tam=2.0;
  53. static GLfloat vertices[]={
  54. -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
  55. };
  56.  
  57.  
  58. static GLfloat normais[] = {
  59. 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
  60. };
  61. //------------------------------------------------------------ Cores
  62. static GLfloat cores[]={
  63. 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
  64. };
  65.  
  66.  
  67. static GLfloat verticesMini[]={
  68. -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
  69. };
  70.  
  71. static GLfloat normaisMini[] = {
  72. 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
  73. };
  74.  
  75. static GLfloat coresMini[]={
  76. 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
  77. };
  78.  
  79.  
  80.  
  81.  
  82. //================================================================================
  83. //=========================================================================== INIT
  84. void inicializa(int escada)
  85. {
  86. glClearColor(BLACK); //………………………………………………………………………………Apagar
  87. glEnable(GL_DEPTH_TEST); //………………………………………………………………………………Profundidade
  88. glShadeModel(GL_SMOOTH); //………………………………………………………………………………Interpolacao de cores
  89.  
  90. if(escada==1){
  91. glVertexPointer(3, GL_FLOAT, 0, vertices); //………………………………………Vertex arrays
  92. glEnableClientState(GL_VERTEX_ARRAY);
  93. glNormalPointer(GL_FLOAT, 0, normais);// normais
  94. glEnableClientState(GL_NORMAL_ARRAY);
  95. glColorPointer(3, GL_FLOAT, 0, cores);
  96. glEnableClientState(GL_COLOR_ARRAY);
  97. } if(escada==0) {
  98. glVertexPointer(3, GL_FLOAT, 0, verticesMini); //………………………………………Vertex arrays
  99. glEnableClientState(GL_VERTEX_ARRAY);
  100. glNormalPointer(GL_FLOAT, 0, normaisMini);// normais
  101. glEnableClientState(GL_NORMAL_ARRAY);
  102. glColorPointer(3, GL_FLOAT, 0, coresMini);
  103. glEnableClientState(GL_COLOR_ARRAY);
  104. } if(escada == 2) { //paredes em volta
  105.  
  106. }
  107.  
  108. }
  109.  
  110.  
  111.  
  112. void drawEixos()
  113. {
  114. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo X
  115. glColor4f(RED);
  116. glBegin(GL_LINES);
  117. glVertex3i( 0, 0, 0);
  118. glVertex3i(200, 0, 0);
  119. glEnd();
  120. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo Y
  121. glColor4f(GREEN);
  122. glBegin(GL_LINES);
  123. glVertex3i(0, 0, 0);
  124. glVertex3i(0, 200, 0);
  125. glEnd();
  126. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo Z
  127. glColor4f(BLUE);
  128. glBegin(GL_LINES);
  129. glVertex3i( 0, 0, 0);
  130. glVertex3i( 0, 0, 200);
  131. glEnd();
  132.  
  133. }
  134.  
  135. void tubos(){
  136. glClearColor(BLACK); //………………………………………………………………………………Apagar
  137. glEnable(GL_DEPTH_TEST); //………………………………………………………………………………Profundidade
  138. glShadeModel(GL_SMOOTH); //………………………………………………………………………………Interpolacao de cores
  139.  
  140. int acum = 0, temp;
  141.  
  142. //PARTE FRENTE
  143. glPushMatrix();
  144. glColor4f(WHITE);
  145. while(acum<=352){
  146. glBegin(GL_POLYGON);
  147. glVertex3f( -30, 0, acum );
  148. temp = rand() %10 + 5;
  149. acum += temp;
  150. glVertex3f( -30, 0, acum );
  151. glVertex3f( -30, 325, acum);
  152. glVertex3f( -30, 325, acum-temp );
  153. glEnd();
  154. //printf("%d\t", temp);
  155.  
  156. acum += temp;
  157. //printf("%d\t", temp);
  158. }
  159. glPopMatrix();
  160. //PARTE TRAS
  161. glPushMatrix();
  162. glColor4f(WHITE);
  163. acum = -30;
  164. while(acum<=220 + 30){
  165. glBegin(GL_POLYGON);
  166. glVertex3f( acum, 0, 352 );
  167. temp = rand() %10 + 8;
  168. acum += temp;
  169. glVertex3f( acum, 0, 352 );
  170. glVertex3f( acum, 325, 352);
  171. glVertex3f( acum-temp, 325, 352 );
  172. glEnd();
  173. //printf("%d\t", temp);
  174.  
  175. acum += temp;
  176. //printf("%d\t", temp);
  177. }
  178. glPopMatrix();
  179. //PARTE TRAS2
  180. glPushMatrix();
  181. glColor4f(WHITE);
  182. acum = 0;
  183. while(acum<=352){
  184. glBegin(GL_POLYGON);
  185. glVertex3f( 250, 0, acum );
  186. temp = rand() %10 + 8;
  187. acum += temp;
  188. glVertex3f( 250, 0, acum );
  189. glVertex3f( 250, 325, acum);
  190. glVertex3f( 250, 325, acum-temp );
  191. glEnd();
  192. //printf("%d\t", temp);
  193.  
  194. acum += temp;
  195. //printf("%d\t", temp);
  196. }
  197. glPopMatrix();
  198. //PARTE FRENTE2 LOL
  199. glPushMatrix();
  200. glColor4f(WHITE);
  201. acum = -30;
  202. while(acum<=220 + 30){
  203. glBegin(GL_POLYGON);
  204. glVertex3f( acum, 0, 0 );
  205. temp = rand() %10 + 8;
  206. acum += temp;
  207. glVertex3f( acum, 0, 0 );
  208. glVertex3f( acum, 325, 0);
  209. glVertex3f( acum-temp, 325, 0 );
  210. glEnd();
  211. //printf("%d\t", temp);
  212.  
  213. acum += temp;
  214. //printf("%d\t", temp);
  215. }
  216. glPopMatrix();
  217.  
  218. }
  219.  
  220. void cenario(){
  221. glClearColor(BLACK); //………………………………………………………………………………Apagar
  222. glEnable(GL_DEPTH_TEST); //………………………………………………………………………………Profundidade
  223. glShadeModel(GL_SMOOTH); //………………………………………………………………………………Interpolacao de cores
  224. glPushMatrix();
  225. glTranslatef(0,162.5,100); //nivelar
  226. glScalef( 650.0, 650.0/2, 650.0 );
  227.  
  228. glBegin(GL_POLYGON);
  229.  
  230. glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( 0.5, -0.5, -0.5 );
  231. glColor3f( 0.0, 1.0, 0.0 ); glVertex3f( 0.5, 0.5, -0.5 );
  232. glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( -0.5, 0.5, -0.5 );
  233. glColor3f( 1.0, 0.0, 1.0 ); glVertex3f( -0.5, -0.5, -0.5 );
  234.  
  235. glEnd();
  236.  
  237. glBegin(GL_POLYGON);
  238. glColor3f( 1.0, 1.0, 1.0 );
  239. glVertex3f( 0.5, -0.5, 0.5 );
  240. glVertex3f( 0.5, 0.5, 0.5 );
  241. glVertex3f( -0.5, 0.5, 0.5 );
  242. glVertex3f( -0.5, -0.5, 0.5 );
  243. glEnd();
  244.  
  245. glBegin(GL_POLYGON);
  246. glColor3f( 1.0, 0.0, 1.0 );
  247. glVertex3f( 0.5, -0.5, -0.5 );
  248. glVertex3f( 0.5, 0.5, -0.5 );
  249. glVertex3f( 0.5, 0.5, 0.5 );
  250. glVertex3f( 0.5, -0.5, 0.5 );
  251. glEnd();
  252.  
  253. glBegin(GL_POLYGON);
  254. glColor3f( 0.0, 1.0, 0.0 );
  255. glVertex3f( -0.5, -0.5, 0.5 );
  256. glVertex3f( -0.5, 0.5, 0.5 );
  257. glVertex3f( -0.5, 0.5, -0.5 );
  258. glVertex3f( -0.5, -0.5, -0.5 );
  259. glEnd();
  260.  
  261. // TOPO
  262. glBegin(GL_POLYGON);
  263. glColor3f( 0.0, 0.0, 1.0 );
  264. glVertex3f( 0.5, 0.5, 0.5 );
  265. glVertex3f( 0.5, 0.5, -0.5 );
  266. glVertex3f( -0.5, 0.5, -0.5 );
  267. glVertex3f( -0.5, 0.5, 0.5 );
  268. glEnd();
  269.  
  270. glBegin(GL_POLYGON);
  271. glColor3f( 1.0, 0.0, 0.0 );
  272. glVertex3f( 0.5, -0.5, -0.5 );
  273. glVertex3f( 0.5, -0.5, 0.5 );
  274. glVertex3f( -0.5, -0.5, 0.5 );
  275. glVertex3f( -0.5, -0.5, -0.5 );
  276. glEnd();
  277. glPopMatrix();
  278.  
  279. //tubos
  280. tubos();
  281.  
  282. }
  283.  
  284.  
  285.  
  286. void drawScene(){
  287. //cenario
  288. cenario();
  289. inicializa(1);
  290. //em frente
  291. glPushMatrix();
  292. //glTranslatef(40, 0, 0);
  293. for(int i=0; i<SIZE/4; i++) {
  294. glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, ordem[i]);
  295. }
  296. glPopMatrix();
  297.  
  298. //para tras
  299. glPushMatrix();
  300. glTranslatef(222, 160, 351);
  301. glRotatef(180,0,1,0);
  302. for(int i=0; i<SIZE/4; i++) {
  303. glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, ordem[i]);
  304. }
  305. glPopMatrix();
  306.  
  307. //para o lado
  308. inicializa(0);
  309. glPushMatrix();
  310. glTranslatef(30, 96, 322);
  311. glRotatef(90,0,1,0);
  312. for(int i=0; i<SIZEMINI/4; i++) {
  313. glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, ordemMini[i]);
  314. }
  315. glPopMatrix();
  316.  
  317. }
  318.  
  319. void display(void){
  320.  
  321. //================================================================= APaga ecran/profundidade
  322. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  323.  
  324.  
  325. //3D
  326. glViewport (0, 0, wScreen, hScreen); // ESQUECER PoR AGORA
  327. glMatrixMode(GL_PROJECTION); // ESQUECER PoR AGORA
  328. glLoadIdentity(); // ESQUECER PoR AGORA
  329. //glOrtho( -20, 20, -20, 20, -20, 20);
  330. gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC); // ESQUECER PoR AGORA
  331. glMatrixMode(GL_MODELVIEW); // ESQUECER PoR AGORA
  332. glLoadIdentity();
  333.  
  334. //-------------------------------------------------------------- observador
  335. gluLookAt(obsP[0], obsP[1], obsP[2], tx,ty,tz, Upx, Upy, Upz);
  336.  
  337. drawEixos();
  338. drawScene();
  339. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actualizacao
  340. glutSwapBuffers();
  341. }
  342.  
  343.  
  344. void keyboard(unsigned char key, int x, int y){
  345. forwardVector[0] = tx - obsP[0];
  346. forwardVector[1] = ty - obsP[1];
  347. forwardVector[2] = tz - obsP[2];
  348.  
  349. switch (key) {
  350.  
  351. case 'W':
  352. case 'w':
  353. //moving forward :
  354. obsP[0] += forwardVector[0] * movementSpeed;
  355. obsP[1] += forwardVector[1] * movementSpeed;
  356. obsP[2] += forwardVector[2] * movementSpeed;
  357. tx += forwardVector[0] * movementSpeed;
  358. ty += forwardVector[1] * movementSpeed;
  359. tz += forwardVector[2] * movementSpeed;
  360. glutPostRedisplay();
  361. break;
  362.  
  363. case 'S':
  364. case 's':
  365. //moving backward :
  366. obsP[0] -= forwardVector[0] * movementSpeed;
  367. obsP[1] -= forwardVector[1] * movementSpeed;
  368. obsP[2] -= forwardVector[2] * movementSpeed;
  369. tx -= forwardVector[0] * movementSpeed;
  370. ty -= forwardVector[1] * movementSpeed;
  371. tz -= forwardVector[2] * movementSpeed;
  372. glutPostRedisplay();
  373. break;
  374.  
  375.  
  376.  
  377.  
  378.  
  379. //--------------------------- Escape
  380. case 27:
  381. exit(0);
  382. break;
  383. }
  384.  
  385. }
  386.  
  387.  
  388.  
  389. void teclasNotAscii(int key, int x, int y){
  390.  
  391. if(key == GLUT_KEY_UP){
  392. //aVisaoAux = (aVisaoAux + 0.1) ;
  393. //printf("antes -> %d\n", ty);
  394. ty = ty + rVisao*sin(-0.1);
  395. //printf("depois -> %d\n", ty);
  396. }
  397. if(key == GLUT_KEY_DOWN){
  398. //aVisaoAux = (aVisaoAux - 0.1) ;
  399. ty = ty + rVisao*sin(0.1);
  400. }
  401.  
  402. if(key == GLUT_KEY_LEFT)
  403. aVisao = (aVisao - 0.1) ;
  404. tx =obsP[0] + rVisao*cos(aVisao);
  405. tz =obsP[2] + rVisao*sin(aVisao);
  406.  
  407. if(key == GLUT_KEY_RIGHT){
  408. aVisao = (aVisao + 0.1) ;
  409. tx =obsP[0] + rVisao*cos(aVisao);
  410. tz =obsP[2] + rVisao*sin(aVisao);
  411. }
  412.  
  413. glutPostRedisplay();
  414.  
  415. }
  416.  
  417.  
  418.  
  419.  
  420. //======================================================= MAIN
  421. //======================================================= MAIN
  422. int main(int argc, char** argv){
  423.  
  424.  
  425. glutInit(&argc, argv);
  426. glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
  427. glutInitWindowSize (wScreen, hScreen);
  428. glutInitWindowPosition (300, 100);
  429. glutCreateWindow ("{jh,pjmm}@dei.uc.pt| |FaceVisivel:'f'| |Observador:'SETAS'| |Andar-'a/s'| |Rodar -'e/d'| ");
  430.  
  431. //escadas grandes
  432. int acum = 0;
  433. for(int i = 0; i < SIZE/4; i++){
  434. ordem[i] = new GLuint[4];
  435. }
  436.  
  437. for(int i = 0; i<SIZE/4; i++) {
  438. for(int j=0; j<4; j++){
  439. ordem[i][j] = acum;
  440. acum++;
  441. }
  442. }
  443.  
  444. //escadas pequenas
  445. acum = 0;
  446. for(int i = 0; i < SIZEMINI/4; i++){
  447. ordemMini[i] = new GLuint[4];
  448. }
  449.  
  450. for(int i = 0; i<SIZEMINI/4; i++) {
  451. for(int j=0; j<4; j++){
  452. ordemMini[i][j] = acum;
  453. acum++;
  454. }
  455. }
  456.  
  457. glutSpecialFunc(teclasNotAscii);
  458. glutDisplayFunc(display);
  459. glutKeyboardFunc(keyboard);
  460.  
  461. glutMainLoop();
  462.  
  463. return 0;
  464. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement