Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.81 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<GL/glut.h>
  3. #include<math.h>
  4. #include<stdio.h>
  5. #include<string.h>
  6. #include <ctime>
  7.  
  8. void init();
  9. void cube();
  10. void dafna();
  11. void dafna2();
  12. void ball();
  13. void StopBalls();
  14. void init_ball();
  15. void color_ball(float red, float green, float blue);
  16.  
  17. int rot = 0, rot2 = 0, rot3 = 0, flag = 0, flag1 = 1, flag3 = 0, flag4, flag5 = 0, arrlenght = 9;
  18. int temp, reflex = 0, score = 0, start = 1;
  19. int temp_score;
  20. char s[10], str[100], *str2;
  21. float a = 15, aC, xC, zC, dis, speed = 0.005, tempS, rot_temp = 0;
  22. int fr[9] = { 0 }, fl[9] = { 0 }, fi[9] = { 0 }, fo[9] = { 0 };
  23. //clock_t starttime = clock();
  24. //clock_t endtime;
  25. double duration;
  26.  
  27. typedef struct {
  28.  
  29. float x;
  30. float y;
  31. float z;
  32. float red;
  33. float green;
  34. float blue;
  35. int status;
  36. int flag;
  37.  
  38. }Ball;
  39. Ball balls[9];
  40.  
  41. void reset() // reset all values when starting new game
  42. {
  43. rot = 0;
  44. rot2 = 0; rot3 = 0; flag = 0; flag1 = 1; flag3 = 0; flag5 = 0;
  45. reflex = 0;
  46. start = 1; a = 15; speed = 0.005; rot_temp = 0;
  47. }
  48. void up() // When new game starts the table going up
  49. {
  50.  
  51. rot_temp += 0.03;
  52.  
  53. if (rot_temp >= 1.0)
  54. {
  55. rot2 += 1.0;
  56. rot_temp = 0;
  57. }
  58.  
  59. if (rot2 >= 60)
  60. {
  61. flag5 = 1;
  62. //starttime = clock();
  63. }
  64. }
  65. void print_score() /// and timer
  66. {
  67. sprintf(str, "Score : %d", score);
  68. str2 = str;
  69. glColor3f(1.0, 1.0, 0.0);
  70. glRasterPos3f(-9, 10, 0);
  71. do glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str2);
  72. while (*(++str2));
  73.  
  74. if (flag5) { /// when the table stop moving up
  75. //endtime = clock();
  76. //duration = (endtime - starttime) / (double)CLOCKS_PER_SEC;
  77. //sprintf(str, "Timer : %0.f", 60.0 - duration);
  78. str2 = str;
  79. glColor3f(0.0, 0.0, 1.0);
  80. glRasterPos3f(-8.5, 11, 0);
  81. do glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str2);
  82. while (*(++str2));
  83.  
  84. if (duration >= 60) {
  85. StopBalls();
  86. reset();
  87. }
  88. }
  89. }
  90. int move_x(int i)
  91. {
  92. int j;
  93. for (j = 0; j<arrlenght; j++)
  94. {
  95. if (j != i && balls[j].flag == 0) {
  96. if (balls[i].x >= balls[j].x - 0.6 && balls[i].x <= balls[j].x + 0.6 && balls[i].z >= balls[j].z - 0.6 && balls[i].z <= balls[j].z + 0.6)
  97. return j;
  98. }
  99. }
  100. return -1;
  101. }
  102. void StopBalls() // Stop's Balls Moving
  103. {
  104.  
  105. balls[0].status = 1;
  106.  
  107. for (int i = 0; i < arrlenght; i++)
  108. {
  109. if (i != 0)
  110. balls[i].status = 0;
  111.  
  112. fr[i] = 0;
  113. fl[i] = 0;
  114. fi[i] = 0;
  115. fo[i] = 0;
  116. }
  117. }
  118. void checkgame() /// To Check if All the Ball's are inserted to the hools (End Game)
  119. {
  120. for (int i = 1; i < 9 && balls[i].flag == 1; i++)
  121. if (i == 8)
  122. {
  123. StopBalls();
  124. reset();
  125. }
  126. }
  127. void keyboard(unsigned char key, int x, int y)
  128. {
  129. if (key == 27) exit(1);
  130.  
  131. if (key == 'n' && start == 1)
  132. {
  133. init_ball();
  134. start = 0;
  135. score = 0;
  136. } ///
  137. if (key == 'd')
  138. {
  139. rot += 5;
  140. rot %= 360;
  141. } ///
  142. if (key == 'w')
  143. {
  144. rot2 += 5;
  145. rot2 %= 360;
  146. } ///
  147. if (key == 's')
  148. {
  149. rot2 -= 5;
  150. rot2 %= 360;
  151. } ///
  152. if (key == 'b')
  153. {
  154. StopBalls();
  155. reset();
  156. start = 1;
  157. } ///
  158. if (key == 'a')
  159. {
  160. rot -= 5;
  161. rot %= 360;
  162. } ///
  163. if (key == 'z')
  164. {
  165. rot3 += 5;
  166. rot3 %= 360;
  167. } ///
  168. if (key == 'x')
  169. {
  170. rot3 -= 5;
  171. rot3 %= 360;
  172. } ///
  173. if (key == '6')//d
  174. {
  175. fr[0] = 1;
  176. fl[0] = 0;
  177.  
  178. } ///
  179. if (key == '4')//a
  180. {
  181. fl[0] = 1;
  182. fr[0] = 0;
  183. } ///
  184. if (key == '8')//w
  185. {
  186. fi[0] = 0;
  187. fo[0] = 1;
  188. } ///
  189. if (key == '2')//s
  190. {
  191. fo[0] = 0;
  192. fi[0] = 1;
  193. } ///
  194. if (key == '5')
  195. {
  196. StopBalls();
  197. } ///
  198. if (key == '+') // increase ball speed
  199. {
  200. flag4 = 0;
  201. if (speed < 0.025) {
  202. for (int i = 1; i < 9; i++)
  203. {
  204. if (balls[i].status == 1)
  205. flag4 = 1;
  206. }
  207. if (flag4 == 0)
  208. speed = speed + 0.002;
  209. }
  210. } ///
  211. if (key == '-') // slow ball speed
  212. {
  213. flag4 = 0;
  214. if (speed > 0.005) {
  215. for (int i = 1; i < 9; i++)
  216. {
  217. if (balls[i].status == 1)
  218. flag4 = 1;
  219. }
  220. if (flag4 == 0)
  221. speed = speed - 0.002;
  222. }
  223. } ///
  224. glutPostRedisplay();
  225. }
  226. void draw()
  227. {
  228. glClear(GL_COLOR_BUFFER_BIT |
  229. GL_DEPTH_BUFFER_BIT);
  230.  
  231. glLoadIdentity();
  232. glTranslatef(0, -15, -30);
  233. glRotatef(rot, 0, 1, 0);
  234. glRotatef(rot2, 1, 0, 0);
  235. glRotatef(rot3, 0, 0, 1);
  236. /************************************************************/
  237.  
  238. //if (start == 1)
  239. //{
  240.  
  241. // ////str2 = "Press N To Start New Game";
  242. // //glColor3f(1.0, 1.0, 0.0);
  243. // //glRasterPos3f(-8, 15, 0);
  244. // //do glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str2);
  245. // //while (*(++str2));
  246.  
  247. // //sprintf(str, "Your Score : %d", score);
  248. // //str2 = str;
  249. // //glColor3f(1.0, 1.0, 0.0);
  250. // //glRasterPos3f(-6, 19, 0);
  251. // //do glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str2);
  252. // //while (*(++str2));
  253.  
  254. //}
  255.  
  256. if (start == 0)
  257. {
  258.  
  259. if (!flag5)
  260. up();
  261.  
  262. checkgame();
  263.  
  264. glTranslatef(0, 4, -12);
  265. glColor3f(1, 1, 0.8);
  266. // Floor
  267. glBegin(GL_QUADS);
  268. glNormal3f(0, 1, 0); // normal straight up
  269. glVertex3f(-20, 0, -25);
  270. glVertex3f(20, 0, -25);
  271. glVertex3f(20, 0, 25);
  272. glVertex3f(-20, 0, 25);
  273. glEnd();
  274.  
  275. glColor3f(0.2, 0.7, 0.3);
  276. glTranslatef(0, 8, 0);
  277. // Table
  278. glBegin(GL_QUADS);
  279. glNormal3f(0, 1, 0); // normal straight up
  280. glVertex3f(-9, 0, -12);
  281. glVertex3f(9, 0, -12);
  282. glVertex3f(9, 0, 12);
  283. glVertex3f(-9, 0, 12);
  284. glEnd();
  285.  
  286. // Table Legs
  287. glColor3f(0.2, 0.2, 0.5);
  288.  
  289. glTranslatef(-8.5, 0, 11.5);
  290. cube();
  291.  
  292. glTranslatef(0, 0, -23);
  293. cube();
  294.  
  295. glTranslatef(17, 0, 0);
  296. cube();
  297.  
  298. glTranslatef(0, 0, 23);
  299. cube();
  300.  
  301. glTranslatef(-8.5, 0, -11.5); // 0 point
  302.  
  303. print_score();
  304.  
  305. //Walls//
  306. glColor3f(0.6, 0.6, 0.6);
  307. glBegin(GL_QUADS);
  308. glNormal3f(0, 1, 0); // normal straight up
  309. glVertex3f(-20, -8, -25);
  310. glVertex3f(20, -8, -25);
  311. glVertex3f(20, 20, -25);
  312. glVertex3f(-20, 20, -25);
  313. glEnd();
  314.  
  315. glBegin(GL_QUADS);
  316. glNormal3f(0, 1, 0); // normal straight up
  317. glVertex3f(-20, -8, -25);
  318. glVertex3f(-20, 20, -25);
  319. glVertex3f(-20, 20, 25);
  320. glVertex3f(-20, -8, 25);
  321. glEnd();
  322.  
  323. glBegin(GL_QUADS);
  324. glNormal3f(0, 1, 0); // normal straight up
  325. glVertex3f(20, -8, -25);
  326. glVertex3f(20, 20, -25);
  327. glVertex3f(20, 20, 25);
  328. glVertex3f(20, -8, 25);
  329. glEnd();
  330.  
  331. // Dafnot //
  332.  
  333. glColor3f(0.4, 0.3, 0.1);
  334. glTranslatef(0, 0, -11.5);
  335. dafna();
  336.  
  337. glTranslatef(0, 0, 23);
  338. dafna();
  339.  
  340. glTranslatef(8.5, 0, -11.5);
  341. dafna2();
  342.  
  343. glTranslatef(-17, 0, 0);
  344. dafna2();
  345.  
  346. glTranslatef(8.5, 0, 0); // 0 point
  347.  
  348.  
  349. // Hools //
  350. glColor3f(1, 0, 0);
  351. glTranslatef(6.5, 0.1, 9.5);
  352.  
  353. glBegin(GL_POLYGON);
  354. for (int i = 0; i <= 720; i++) {
  355. aC = 3.14 * i;
  356. xC = cos(aC / 360);
  357. zC = sin(aC / 360);
  358. glVertex3d(xC, 0, zC);
  359. }
  360. glEnd();
  361. ///////////////////////////////////////////
  362. glColor3f(0, 0, 0);
  363. glTranslatef(-13, 0, 0);
  364.  
  365. glBegin(GL_POLYGON);
  366. for (int i = 0; i <= 720; i++) {
  367. aC = 3.14 * i;
  368. xC = cos(aC / 360);
  369. zC = sin(aC / 360);
  370. glVertex3d(xC, 0, zC);
  371. }
  372. glEnd();
  373. ///////////////////////////////////////////
  374. glColor3f(1, 0, 0);
  375. glTranslatef(0, 0, -19);
  376.  
  377. glBegin(GL_POLYGON);
  378. for (int i = 0; i <= 720; i++) {
  379. aC = 3.14 * i;
  380. xC = cos(aC / 360);
  381. zC = sin(aC / 360);
  382. glVertex3d(xC, 0, zC);
  383. }
  384. glEnd();
  385. ///////////////////////////////////////////
  386. glColor3f(0, 0, 0);
  387. glTranslatef(13, 0, 0);
  388.  
  389. glBegin(GL_POLYGON);
  390. for (int i = 0; i <= 720; i++) {
  391. aC = 3.14 * i;
  392. xC = cos(aC / 360);
  393. zC = sin(aC / 360);
  394. glVertex3d(xC, 0, zC);
  395. }
  396. glEnd();
  397.  
  398. ///////////Draw Balls/////////////
  399. glTranslatef(-6.5, -0.1, 9.5); // 0 point
  400.  
  401. glTranslatef(0, 0.3, 0); // ball's radius
  402.  
  403. for (int i = 0; i < arrlenght; i++)
  404. {
  405. glTranslatef(balls[i].x, balls[i].y, balls[i].z);
  406. color_ball(balls[i].red, balls[i].green, balls[i].blue);
  407. glTranslatef(-balls[i].x, -balls[i].y, -balls[i].z);
  408. }
  409.  
  410. glTranslatef(0, -0.3, 0);
  411. }
  412.  
  413. glutSwapBuffers(); // display the output
  414.  
  415. }
  416. void Checkflag(int i) // to check if a ball hit a holl
  417. {
  418. if (balls[i].flag == 0) { // to check if the ball still in the game
  419. dis = sqrt(pow(balls[i].x - (-6.5), 2) + pow(balls[i].z - 9.5, 2));
  420. if (dis < 0.9) {
  421. if (i) {
  422. score -= 10;
  423. balls[i].flag = 2;
  424. balls[i].status = 0;
  425. printf("%d\n", score);
  426. }
  427. else {
  428. score -= 5;
  429. balls[0].x = balls[0].x + 5;
  430. fr[i] = 0;
  431. fl[i] = 0;
  432. fi[i] = 0;
  433. fo[i] = 0;
  434. printf("%d\n", score);
  435. }
  436. }
  437. dis = sqrt(pow(balls[i].x - (6.5), 2) + pow(balls[i].z - 9.5, 2));
  438. if (dis < 0.9) {
  439. if (i) {
  440. score += 10;
  441. balls[i].flag = 2;
  442. balls[i].status = 0;
  443. printf("%d\n", score);
  444. }
  445. else {
  446. score -= 5;
  447. balls[0].x = balls[0].x - 5;
  448. fr[i] = 0;
  449. fl[i] = 0;
  450. fi[i] = 0;
  451. fo[i] = 0;
  452. printf("%d\n", score);
  453. }
  454. }
  455. dis = sqrt(pow(balls[i].x - (-6.5), 2) + pow(balls[i].z - (-9.5), 2));
  456. if (dis < 0.9) {
  457. if (i) {
  458. score += 10;
  459. balls[i].flag = 2;
  460. balls[i].status = 0;
  461. printf("%d\n", score);
  462. }
  463. else {
  464. score -= 5;
  465. balls[0].x = balls[0].x + 5;
  466. fr[i] = 0;
  467. fl[i] = 0;
  468. fi[i] = 0;
  469. fo[i] = 0;
  470. printf("%d\n", score);
  471. }
  472. }
  473. dis = sqrt(pow(balls[i].x - (6.5), 2) + pow(balls[i].z - (-9.5), 2));
  474. if (dis < 0.9) {
  475. if (i) {
  476. score -= 10;
  477. balls[i].flag = 2;
  478. balls[i].status = 0;
  479. printf("%d\n", score);
  480. }
  481. else {
  482. score -= 5;
  483. balls[0].x = balls[0].x - 5;
  484. fr[i] = 0; // reset the flags
  485. fl[i] = 0;
  486. fi[i] = 0;
  487. fo[i] = 0;
  488. printf("%d\n", score);
  489. }
  490. }
  491. }
  492. }
  493. void Idle()
  494. {
  495. for (int i = 0; i < arrlenght; i++) {
  496.  
  497. Checkflag(i); // check if the ball hit a hole
  498. if (balls[i].flag == 0) { /// check of the ball still in the table
  499.  
  500.  
  501. if (fr[i]) // each ball have her own flags
  502. {
  503. if (balls[i].status == 1 && move_x(i) == -1)
  504. if (balls[i].x < 7.7)
  505. balls[i].x += speed;
  506. else {
  507. fl[i] = 1;
  508. fr[i] = 0;
  509. }
  510. if (balls[i].status == 1 && move_x(i) != -1) {
  511. temp = move_x(i);
  512. balls[temp].status = 1;
  513. fr[temp] = 1;
  514. fl[temp] = 0;
  515. //reflex = 1;
  516. balls[i].x -= speed;
  517. fl[i] = 1;
  518. fr[i] = 0;
  519.  
  520. if (fo[i] == 1)
  521. fo[temp] = 1;
  522. if (fi[i] == 1)
  523. fi[temp] = 1;
  524. }
  525. }
  526. if (fl[i])
  527. {
  528. if (balls[i].status == 1 && move_x(i) == -1)
  529. if (balls[i].x > -7.7)
  530. balls[i].x -= speed;
  531. else {
  532. fl[i] = 0;
  533. fr[i] = 1;
  534. }
  535. if (balls[i].status == 1 && move_x(i) != -1) {
  536. temp = move_x(i);
  537. balls[temp].status = 1;
  538. fr[temp] = 0;
  539. fl[temp] = 1;
  540. reflex = 1;
  541. balls[i].x += speed;
  542. fl[i] = 0;
  543. fr[i] = 1;
  544. if (fo[i] == 1)
  545. fo[temp] = 1;
  546. if (fi[i] == 1)
  547. fi[temp] = 1;
  548. }
  549. }
  550. if (fo[i])
  551. {
  552. if (balls[i].status == 1 && move_x(i) == -1)
  553. if (balls[i].z > -10.7)
  554. balls[i].z -= speed;
  555. else
  556. {
  557. fo[i] = 0;
  558. fi[i] = 1;
  559. }
  560. if (balls[i].status == 1 && move_x(i) != -1) {
  561. temp = move_x(i);
  562. balls[temp].status = 1;
  563. fo[temp] = 1;
  564. fi[temp] = 0;
  565. balls[i].z += speed;
  566. reflex = 1;
  567. fi[i] = 1;
  568. fo[i] = 0;
  569.  
  570. if (fl[i] == 1)
  571. fl[temp] = 1;
  572. if (fr[i] == 1)
  573. fr[temp] = 1;
  574. }
  575. }
  576. if (fi[i])
  577. {
  578. if (balls[i].status == 1 && move_x(i) == -1)
  579. if (balls[i].z < 10.7)
  580. balls[i].z += speed;
  581. else
  582. {
  583. fo[i] = 1;
  584. fi[i] = 0;
  585. }
  586. if (balls[i].status == 1 && move_x(i) != -1) {
  587.  
  588. temp = move_x(i);
  589. balls[temp].status = 1;
  590. fo[temp] = 0;
  591. fi[temp] = 1;
  592. balls[i].z -= speed;
  593. reflex = 1;
  594. fi[i] = 0;
  595. fo[i] = 1;
  596. if (fl[i] == 1)
  597. fl[temp] = 1;
  598. if (fr[i] == 1)
  599. fr[temp] = 1;
  600. }
  601. }
  602. }
  603.  
  604. if (balls[i].flag == 2)
  605. {
  606.  
  607. balls[i].y = balls[i].y - 0.002;
  608.  
  609. if (balls[i].y <-7.7)
  610. balls[i].flag = 1;
  611.  
  612. }
  613.  
  614.  
  615. }
  616.  
  617. if (reflex) { // if a ball hit another ball reflex=1
  618. if (a > 0) {
  619.  
  620. if (flag3 == 0) {
  621. tempS = speed; // saving the speed
  622. printf("%f\n", tempS);
  623. flag3 = 1;
  624. printf("here\n");
  625. }
  626. a -= tempS;
  627. speed = speed - (0.0007*speed);
  628. if (flag1 && a < 10) {
  629. balls[0].status = 0;
  630. flag1 = 0;
  631. }
  632. }
  633. else { // stop ball's moving
  634. speed = tempS; // return speed
  635. a = 15;
  636. flag1 = 1;
  637. flag3 = 0;
  638. StopBalls();
  639. reflex = 0;
  640. }
  641. }
  642. draw();
  643. }
  644. int main(int argc, char *argv[])
  645. {
  646. glutInit(&argc, argv);
  647. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // RGB display, double-buffered, with Z-Buffer
  648. glutInitWindowSize(600, 600); // 500 x 500 pixels
  649. glutCreateWindow("3D");
  650. glutDisplayFunc(draw); // Set the display function
  651. glutKeyboardFunc(keyboard); // Set the keyboard function
  652. init();
  653. init_ball();
  654. glutIdleFunc(Idle);
  655. glutMainLoop(); // Start the main event loop
  656.  
  657. }
  658. // Set OpenGL parameters
  659. void init()
  660. {
  661. glMatrixMode(GL_PROJECTION);
  662. glLoadIdentity();
  663. gluPerspective(60, 1.0, 0.1, 100);
  664. glMatrixMode(GL_MODELVIEW);
  665.  
  666. // Lighting parameters
  667.  
  668. GLfloat mat_ambdif[] = { 1.0,2.0, 0.0, 1.0 };
  669. GLfloat mat_specular[] = { 0.0, 0.0, 0.0, 1.0 };
  670. GLfloat mat_shininess[] = { 80.0 };
  671. GLfloat light_position[] = { 0.0, 5.0, 0.0, 1.0 };
  672. glClearColor(0.0, 0.0, 0.0, 0.0);
  673.  
  674. glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_ambdif); // set both amb and diff components
  675. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); // set specular
  676. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // set shininess
  677. glLightfv(GL_LIGHT0, GL_POSITION, light_position); // set light "position", in this case direction
  678. glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // active material changes by glColor3f(..)
  679.  
  680. glEnable(GL_LIGHTING);
  681. glEnable(GL_LIGHT0);
  682. glEnable(GL_COLOR_MATERIAL);
  683. glEnable(GL_DEPTH_TEST);
  684. }
  685. void cube()
  686. {
  687. glBegin(GL_QUADS);
  688. // Front
  689. glNormal3f(0, 0, 1);
  690. glVertex3f(-0.5, 0, 0.5);
  691. glVertex3f(-0.5, -8, 0.5);
  692. glVertex3f(0.5, -8, 0.5);
  693. glVertex3f(0.5, 0, 0.5);
  694.  
  695. // Back
  696. glNormal3f(0, 0, 1);
  697. glVertex3f(-0.5, 0, -0.5);
  698. glVertex3f(0.5, 0, -0.5);
  699. glVertex3f(0.5, -8, -0.5);
  700. glVertex3f(-0.5, -8, -0.5);
  701.  
  702. // Left side
  703. glNormal3f(1, 0, 0);
  704. glVertex3f(-0.5, 0, 0.5);
  705. glVertex3f(-0.5, -8, 0.5);
  706. glVertex3f(-0.5, -8, -0.5);
  707. glVertex3f(-0.5, 0, -0.5);
  708.  
  709. // Right side
  710. glNormal3f(1, 0, 0);
  711. glVertex3f(0.5, 0, 0.5);
  712. glVertex3f(0.5, 0, -0.5);
  713. glVertex3f(0.5, -8, -0.5);
  714. glVertex3f(0.5, -8, 0.5);
  715. glEnd();
  716. }
  717. void dafna()
  718. {
  719. glBegin(GL_QUADS);
  720. // Front
  721. glNormal3f(0, 0, 1);
  722. glVertex3f(-9, 0, 0.5);
  723. glVertex3f(-9, 0.6, 0.5);
  724. glVertex3f(9, 0.6, 0.5);
  725. glVertex3f(9, 0, 0.5);
  726.  
  727. // Back
  728. glNormal3f(0, 0, 1);
  729. glVertex3f(-9, 0, -0.5);
  730. glVertex3f(9, 0, -0.5);
  731. glVertex3f(9, 0.6, -0.5);
  732. glVertex3f(-9, 0.6, -0.5);
  733.  
  734. // Left side
  735. glNormal3f(-1, 0, 0);
  736. glVertex3f(-9, 0, 0.5);
  737. glVertex3f(-9, 0.6, 0.5);
  738. glVertex3f(-9, 0.6, -0.5);
  739. glVertex3f(-9, 0, -0.5);
  740.  
  741. // Right side
  742. glNormal3f(1, 0, 0);
  743. glVertex3f(9, 0, 0.5);
  744. glVertex3f(9, 0, -0.5);
  745. glVertex3f(9, 0.6, -0.5);
  746. glVertex3f(9, 0.6, 0.5);
  747.  
  748. // Up side
  749. glNormal3f(1, 0, 0);
  750. glVertex3f(9, 0.6, 0.5);
  751. glVertex3f(9, 0.6, -0.5);
  752. glVertex3f(-9, 0.6, -0.5);
  753. glVertex3f(-9, 0.6, 0.5);
  754.  
  755. glEnd();
  756. }
  757. void dafna2()
  758. {
  759. glBegin(GL_QUADS);
  760. // Front
  761. glNormal3f(1, 0, 0.5);
  762. glVertex3f(-0.5, 0, 12);
  763. glVertex3f(-0.5, 0.6, 12);
  764. glVertex3f(0.5, 0.6, 12);
  765. glVertex3f(0.5, 0, 12);
  766.  
  767. // Back
  768. glNormal3f(0, 0, 1);
  769. glVertex3f(-0.5, 0, -12);
  770. glVertex3f(-0.5, 0.6, -12);
  771. glVertex3f(0.5, 0.6, -12);
  772. glVertex3f(0.5, 0, -12);
  773.  
  774. // Left side
  775. glNormal3f(1, 0, 0);
  776. glVertex3f(-0.5, 0, -12);
  777. glVertex3f(-0.5, 0.6, -12);
  778. glVertex3f(-0.5, 0.6, 12);
  779. glVertex3f(-0.5, 0, 12);
  780.  
  781. // Right side
  782. glNormal3f(1, 0, 0);
  783. glVertex3f(0.5, 0, -12);
  784. glVertex3f(0.5, 0.6, -12);
  785. glVertex3f(0.5, 0.6, 12);
  786. glVertex3f(0.5, 0, 12);
  787.  
  788. // Up side
  789. glNormal3f(0, 1, 0);
  790. glVertex3f(0.5, 0.6, 12);
  791. glVertex3f(0.5, 0.6, -12);
  792. glVertex3f(-0.5, 0.6, -12);
  793. glVertex3f(-0.5, 0.6, 12);
  794.  
  795. glEnd();
  796. }
  797. void ball()
  798. {
  799. glutSolidSphere(0.3, 32, 32);
  800. }
  801. void color_ball(float red, float green, float blue)
  802. {
  803. glColor3f(red, green, blue);
  804. ball();
  805. }
  806. void init_ball()
  807. {
  808. balls[0].x = 0;
  809. balls[0].y = 0;
  810. balls[0].z = -5;
  811. balls[0].red = 1;
  812. balls[0].green = 1;
  813. balls[0].blue = 1;
  814. balls[0].status = 1;
  815. balls[0].flag = 0;
  816. ////////////////////////////
  817. balls[1].x = 0;
  818. balls[1].y = 0;
  819. balls[1].z = 0;
  820. balls[1].red = 0;
  821. balls[1].green = 0;
  822. balls[1].blue = 1;
  823. balls[1].status = 0.9;
  824. balls[1].flag = 0;
  825. ////////////////////////////
  826. balls[2].x = -1;
  827. balls[2].y = 0;
  828. balls[2].z = 2;
  829. balls[2].red = 1;
  830. balls[2].green = 0;
  831. balls[2].blue = 0;
  832. balls[2].status = 0.8;
  833. balls[2].flag = 0;
  834. ////////////////////////////
  835. balls[3].x = 1;
  836. balls[3].y = 0;
  837. balls[3].z = 2;
  838. balls[3].red = 0;
  839. balls[3].green = 1;
  840. balls[3].blue = 0.0;
  841. balls[3].status = 0.7;
  842. balls[3].flag = 0;
  843. ////////////////////////////
  844. balls[4].x = -4;
  845. balls[4].y = 0;
  846. balls[4].z = 4;
  847. balls[4].red = 0.8;
  848. balls[4].green = 0.6;
  849. balls[4].blue = 0.2;
  850. balls[4].status = 0.6;
  851. balls[4].flag = 0;
  852. ////////////////////////////
  853. balls[5].x = 4;
  854. balls[5].y = 0;
  855. balls[5].z = 4;
  856. balls[5].red = 0.2;
  857. balls[5].green = 0.5;
  858. balls[5].blue = 0.86;
  859. balls[5].status = 0.5;
  860. balls[5].flag = 0;
  861. ////////////////////////////
  862. balls[6].x = 0;
  863. balls[6].y = 0;
  864. balls[6].z = 4;
  865. balls[6].red = 0.2;
  866. balls[6].green = 0.7;
  867. balls[6].blue = 0.7;
  868. balls[6].status = 0.5;
  869. balls[6].flag = 0;
  870. ////////////////////////////
  871. balls[7].x = -6;
  872. balls[7].y = 0;
  873. balls[7].z = 6;
  874. balls[7].red = 0.3;
  875. balls[7].green = 0.1;
  876. balls[7].blue = 0.6;
  877. balls[7].status = 0.3;
  878. balls[7].flag = 0;
  879. ////////////////////////////
  880. balls[8].x = 6;
  881. balls[8].y = 0;
  882. balls[8].z = 6;
  883. balls[8].red = 0.8;
  884. balls[8].green = 0.6;
  885. balls[8].blue = 0.2;
  886. balls[8].status = 0.2;
  887. balls[8].flag = 0;
  888. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement