Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.95 KB | None | 0 0
  1. #include "TextureBuilder.h"
  2. #include "Model_3DS.h"
  3. #include "GLTexture.h"
  4. #include <math.h>
  5. #include <glut.h>
  6. #include <iostream>
  7. #include <string>
  8. #include <iomanip>
  9.  
  10.  
  11. #define DEG2RAD(a) (a * 0.0174532925)
  12. #define GLUT_KEY_ESCAPE 27
  13. class Vector3f {
  14. public:
  15. float x, y, z;
  16.  
  17. Vector3f(float _x = 0.0f, float _y = 0.0f, float _z = 0.0f) {
  18. x = _x;
  19. y = _y;
  20. z = _z;
  21. }
  22.  
  23. Vector3f operator+(Vector3f &v) {
  24. return Vector3f(x + v.x, y + v.y, z + v.z);
  25. }
  26.  
  27. Vector3f operator-(Vector3f &v) {
  28. return Vector3f(x - v.x, y - v.y, z - v.z);
  29. }
  30.  
  31. Vector3f operator*(float n) {
  32. return Vector3f(x * n, y * n, z * n);
  33. }
  34.  
  35. Vector3f operator/(float n) {
  36. return Vector3f(x / n, y / n, z / n);
  37. }
  38.  
  39. Vector3f unit() {
  40. return *this / sqrt(x * x + y * y + z * z);
  41. }
  42.  
  43. Vector3f cross(Vector3f v) {
  44. return Vector3f(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
  45. }
  46. };
  47. void Axis(){
  48.  
  49. glColor3f(1.0, 0.0, 0.0); // red x
  50. glBegin(GL_LINES);
  51. // x aix
  52.  
  53. glVertex3f(-4.0, 0.0f, 0.0f);
  54. glVertex3f(4.0, 0.0f, 0.0f);
  55.  
  56. // arrow
  57. glVertex3f(4.0, 0.0f, 0.0f);
  58. glVertex3f(3.0, 1.0f, 0.0f);
  59.  
  60. glVertex3f(4.0, 0.0f, 0.0f);
  61. glVertex3f(3.0, -1.0f, 0.0f);
  62. glEnd();
  63. glFlush();
  64.  
  65.  
  66.  
  67. // y
  68. glColor3f(0.0, 1.0, 0.0); // green y
  69. glBegin(GL_LINES);
  70. glVertex3f(0.0, -4.0f, 0.0f);
  71. glVertex3f(0.0, 4.0f, 0.0f);
  72.  
  73. // arrow
  74. glVertex3f(0.0, 4.0f, 0.0f);
  75. glVertex3f(1.0, 3.0f, 0.0f);
  76.  
  77. glVertex3f(0.0, 4.0f, 0.0f);
  78. glVertex3f(-1.0, 3.0f, 0.0f);
  79. glEnd();
  80. glFlush();
  81.  
  82. // z
  83. glColor3f(0.0, 0.0, 1.0); // blue z
  84. glBegin(GL_LINES);
  85. glVertex3f(0.0, 0.0f, -4.0f);
  86. glVertex3f(0.0, 0.0f, 4.0f);
  87.  
  88. // arrow
  89. glVertex3f(0.0, 0.0f, 4.0f);
  90. glVertex3f(0.0, 1.0f, 3.0f);
  91.  
  92. glVertex3f(0.0, 0.0f, 4.0f);
  93. glVertex3f(0.0, -1.0f, 3.0f);
  94. glEnd();
  95. glFlush();
  96. }
  97. class Camera {
  98. public:
  99. Vector3f eye, center, up;
  100. Camera(float eyeX = 1.2f, float eyeY = 10.1f, float eyeZ = 32.3f, float centerX = 1.22f, float centerY = 9.6f, float centerZ = 31.4f, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f) {
  101. eye = Vector3f(eyeX, eyeY, eyeZ);
  102. center = Vector3f(centerX, centerY, centerZ);
  103. up = Vector3f(upX, upY, upZ);
  104. }
  105.  
  106. void moveX(float d) {
  107. Vector3f right = up.cross(center - eye).unit();
  108. eye = eye + right * d;
  109. center = center + right * d;
  110. }
  111.  
  112. void moveY(float d) {
  113. eye = eye + up.unit() * d;
  114. center = center + up.unit() * d;
  115. }
  116.  
  117. void moveZ(float d) {
  118. Vector3f view = (center - eye).unit();
  119. eye = eye + view * d;
  120. center = center + view * d;
  121. }
  122. void changePrespective(float x, float y, float z){
  123. float centerX = 0.0f;
  124. float centerY = 0.0f;
  125. float centerZ = 0.0f;
  126. float upX = 0.0f;
  127. float upY = 1.0f;
  128. float upZ = 0.0f;
  129. eye = Vector3f(x, y, z);
  130. center = Vector3f(centerX, centerY, centerZ);
  131. up = Vector3f(upX, upY, upZ);
  132. }
  133.  
  134. void rotateX(float a) {
  135. Vector3f view = (center - eye).unit();
  136. Vector3f right = up.cross(view).unit();
  137. view = view * cos(DEG2RAD(a)) + up * sin(DEG2RAD(a));
  138. up = view.cross(right);
  139. center = eye + view;
  140. }
  141.  
  142. void rotateY(float a) {
  143. Vector3f view = (center - eye).unit();
  144. Vector3f right = up.cross(view).unit();
  145. view = view * cos(DEG2RAD(a)) + right * sin(DEG2RAD(a));
  146. right = view.cross(up);
  147. center = eye + view;
  148. }
  149.  
  150. void look(float frogx,float frogy,float frogz,int perspective,int xValue) {
  151. if (perspective == 3){
  152. center.z = frogz;
  153. center.y = frogy;
  154. center.x = frogx;
  155. eye.z = frogz + 15;
  156. eye.y = frogy + 15;
  157. eye.x = frogx;
  158. }
  159. else{
  160. eye.z = frogz-1;
  161. eye.y = frogy+2;
  162. eye.x = frogx;
  163. center.x = frogx + xValue;
  164. center.y = frogy+2;
  165. center.z = -200;
  166. }
  167.  
  168. gluLookAt(
  169. eye.x, eye.y, eye.z,
  170. center.x, center.y, center.z,
  171. up.x, up.y, up.z
  172. );
  173. }
  174. };
  175.  
  176. struct Obstacle { // TODO : Change static variables
  177. float x;
  178. float y=1.3;
  179. float z;
  180. bool drawable = false;
  181. int direction; //1 = left-> right / -1 = right ->left / 0 not initalized
  182. int timeToLive=100;
  183. int timeToStart;
  184. int timer = 0;
  185. int modelNumber = 0;
  186. float speed = 1;
  187. };
  188. int* bezier(float t, int* p0, int* p1, int* p2, int* p3);
  189. void FrogKeyboard(unsigned char, int, int);
  190. void print(int x, int y, int z, char *string);
  191. void initalizeFrog();
  192. void Anim();
  193. void drawBush(double, double);
  194. int WIDTH = 1800;
  195. int HEIGHT = 800;
  196.  
  197. GLuint tex;
  198. char title[] = "3D Model Loader Sample";
  199.  
  200. // 3D Projection Options
  201. Model_3DS model_car;
  202. Model_3DS model_truck;
  203. Model_3DS model_police;
  204. Model_3DS model_batcar;
  205. Model_3DS model_tank;
  206. Model_3DS model_gallardo;
  207. Model_3DS model_ferrari;
  208. Model_3DS model_bike;
  209. Model_3DS model_Camaro;
  210. Model_3DS model_trophy;
  211. Model_3DS model_aston;
  212. Model_3DS model_bushes;
  213. Model_3DS model_tree2;
  214. Model_3DS model_tree;
  215.  
  216.  
  217. Model_3DS models[11]; //TODO: change LAter
  218. GLuint fskin;
  219. GLuint fneck;
  220. GLuint feyes;
  221. GLuint dskin;
  222. GLuint feet;
  223. GLuint flegs;
  224. GLuint ground;
  225. GLdouble fovy = 45.0;
  226. GLdouble aspectRatio = (GLdouble)WIDTH / (GLdouble)HEIGHT;
  227. GLdouble zNear = 0.001;
  228. GLdouble zFar = 500;
  229. Camera camera;
  230. Obstacle allCars[5][50];
  231. int level = 1;
  232. float angle = 0.0f;
  233. float angle1 = 0.0f;
  234. float alpha = 0.0f;
  235. float frogrotation = 180; //global variable for frog orientation
  236. float legrotation = 0; //global variable for leg movement
  237. float armrotation = 0; //global variable for arm movement
  238. float movement = 0; //useless for now
  239. float frogx; //starting x
  240. float frogy; //starting y
  241. float frogz; //starting z
  242. float lightx = 0.7;
  243. float lighty = 0.7;
  244. float lightz = 0.7;
  245. int frogcoord[2]; //Used to gather coordinates from bezier to set x,y,z
  246. int frogbezier1[2]; //used for bezier movement
  247. int frogbezier2[2]; //used for bezier movement
  248. int frogbezier3[2]; //used for bezier movement
  249. int frogbezier4[2]; //used for bezier movement
  250. float frogtimer = 0; //used for leg and arm
  251. bool enablefrog = true; //flag to enable keg arm and bezier movement
  252. bool flaglegA = true; //flag to enable leg movement
  253. bool frogflagjump = false; //flag to check that we move in one direction
  254. int finalZs[5];
  255. bool developerMode = 0;
  256. int globalTimer = 0;
  257. int xValue = 0;
  258. bool hit = false;
  259. int totalScore=0;
  260. int currentLevelScore=0;
  261. int perspective = 3; // 1->first person view 3->3rd person
  262. bool won = false;
  263. void setupCamera() {
  264. glMatrixMode(GL_PROJECTION);
  265. glLoadIdentity();
  266. gluPerspective(60, 1800 / 800, 0.001, 500);
  267.  
  268. glMatrixMode(GL_MODELVIEW);
  269. glLoadIdentity();
  270. camera.look(frogx,frogy,frogz,perspective,xValue);
  271. }
  272.  
  273. int cameraZoom = 0;
  274.  
  275.  
  276. // Textures
  277.  
  278.  
  279. //=======================================================================
  280. // Lighting Configuration Function
  281. //=======================================================================
  282. void InitLightSource()
  283. {
  284. // Enable Lighting for this OpenGL Program
  285. glEnable(GL_LIGHTING);
  286.  
  287. // Enable Light Source number 0
  288. // OpengL has 8 light sources
  289. glEnable(GL_LIGHT0);
  290.  
  291. // Define Light source 0 ambient light
  292. GLfloat ambient[] = { 0.1f, 0.1f, 0.1, 1.0f };
  293. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  294.  
  295. // Define Light source 0 diffuse light
  296. GLfloat diffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
  297. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  298.  
  299. // Define Light source 0 Specular light
  300. GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  301. glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
  302.  
  303. // Finally, define light source 0 position in World Space
  304. GLfloat light_position[] = { 0.0f, 10.0f, 0.0f, 1.0f };
  305. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  306. }
  307.  
  308. //=======================================================================
  309. // Material Configuration Function
  310. //======================================================================
  311. void InitMaterial()
  312. {
  313. // Enable Material Tracking
  314. glEnable(GL_COLOR_MATERIAL);
  315.  
  316. // Sich will be assigneet Material Properties whd by glColor
  317. glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  318.  
  319. // Set Material's Specular Color
  320. // Will be applied to all objects
  321. GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  322. glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
  323.  
  324. // Set Material's Shine value (0->128)
  325. GLfloat shininess[] = { 96.0f };
  326. glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
  327. }
  328.  
  329. //=======================================================================
  330. // OpengGL Configuration Function
  331. //=======================================================================
  332. void myInit(void)
  333. {
  334. glClearColor(0.0, 0.0, 0.0, 0.0);
  335.  
  336. glMatrixMode(GL_PROJECTION);
  337.  
  338. glLoadIdentity();
  339.  
  340.  
  341.  
  342. glMatrixMode(GL_MODELVIEW);
  343.  
  344. glLoadIdentity();
  345.  
  346. InitMaterial();
  347.  
  348. glEnable(GL_DEPTH_TEST);
  349.  
  350. glEnable(GL_NORMALIZE);
  351. }
  352.  
  353. //=======================================================================
  354. // Render Ground Function
  355. //=======================================================================
  356. void renderGround()
  357. {
  358. glDisable(GL_LIGHTING); // Disable lighting
  359.  
  360. glColor3f(0.6, 0.6, 0.6); // Dim the ground texture a bit
  361.  
  362. glEnable(GL_TEXTURE_2D); // Enable 2D texturing
  363.  
  364. /*glBindTexture(GL_TEXTURE_2D, ground); // Bind the ground texture
  365.  
  366.  
  367. glPushMatrix();
  368. glBegin(GL_QUADS);
  369. glNormal3f(0, 1, 0); // Set quad normal direction.
  370. glTexCoord2f(0, 0); // Set tex coordinates ( Using (0,0) -> (5,5) with texture wrapping set to GL_REPEAT to simulate the ground repeated grass texture).
  371. glVertex3f(-20, 0, -20);
  372. glTexCoord2f(5, 0);
  373. glVertex3f(20, 0, -20);
  374. glTexCoord2f(5, 5);
  375. glVertex3f(20, 0, 20);
  376. glTexCoord2f(0, 5);
  377. glVertex3f(-20, 0, 20);
  378. glEnd();
  379. glPopMatrix();*/
  380.  
  381. glEnable(GL_LIGHTING); // Enable lighting again for other entites coming throung the pipeline.
  382.  
  383. glColor3f(1, 1, 1); // Set material back to white instead of grey used for the ground texture.
  384. }
  385.  
  386. void renderWhiteStripes(float fromX, float toX, float Z, float StepBetweenStripes){
  387.  
  388. glDisable(GL_LIGHTING);
  389.  
  390. while (fromX + 3 < toX){
  391. glPushMatrix();
  392. glBegin(GL_QUADS);
  393. glColor3f(1, 1, 1);
  394. glNormal3f(0, -1, 0);
  395. glVertex3f(fromX, 1.5, Z - 0.4);
  396. glVertex3f(fromX, 1.5, Z + 0.4);
  397. glVertex3f(fromX + 3, 1.5, Z + 0.4);
  398. glVertex3f(fromX + 3, 1.5, Z - 0.4);
  399. fromX += StepBetweenStripes + 3;
  400. glPopMatrix();
  401. }
  402.  
  403. glEnable(GL_LIGHTING);
  404.  
  405.  
  406. }
  407.  
  408. bool checkOverlapping(float x, float y, float z){
  409. bool ox = false;
  410. bool oy = false;
  411. bool oz = false;
  412. if (frogx >= x - 2 && frogx <= x + 2)
  413. ox = true;
  414.  
  415. if (frogz >= z - 1.5&&frogz <= z + 1.5)
  416. oy = true;
  417.  
  418.  
  419. if (frogy >= y - 2 && frogy <= y + 2)
  420. oz = true;
  421.  
  422.  
  423. return ox&&oy&&oz;
  424. }
  425. void collisionOccured(){
  426. PlaySound("jump36.wav", NULL, SND_ASYNC | SND_FILENAME);
  427. hit = true;
  428. lightx = 0;
  429. lighty = 0;
  430. lightz = 0;
  431. initalizeFrog();
  432. }
  433. void checkCollision(){
  434. for (int i = 0; i < (sizeof(allCars[level - 1]) / sizeof(*allCars[level - 1])); i++){
  435. Obstacle car = allCars[level - 1][i];
  436. if (car.direction != 0){
  437. bool status = checkOverlapping(car.x, car.y, car.z);
  438. if (status)
  439. collisionOccured();
  440. }
  441.  
  442.  
  443. }
  444. }
  445.  
  446. void finalWin(){
  447. won = true;
  448. }
  449. void checkWon(){
  450. if (frogz <= finalZs[level-1]){
  451.  
  452. if (level == 3){
  453. finalWin();
  454. return;
  455. }
  456. level++;
  457. hit = true;
  458. totalScore += currentLevelScore;
  459. currentLevelScore = 0;
  460.  
  461. initalizeFrog();
  462.  
  463. }
  464. }
  465. void moveCarRight(int carPos){
  466.  
  467. if (allCars[level-1][carPos].timeToStart <= globalTimer)
  468. allCars[level-1][carPos].drawable = true;
  469.  
  470. if (allCars[level-1][carPos].drawable){
  471. allCars[level-1][carPos].timer++;
  472. allCars[level-1][carPos].x+=allCars[level-1][carPos].speed;
  473.  
  474. if (allCars[level-1][carPos].x > 23)
  475. allCars[level-1][carPos].drawable = false;
  476.  
  477. if (allCars[level-1][carPos].timer > allCars[level-1][carPos].timeToLive)
  478. {
  479. allCars[level-1][carPos].x = -20;
  480. allCars[level-1][carPos].drawable = true;
  481. allCars[level-1][carPos].timer = 0;
  482. }
  483.  
  484. }
  485. }
  486. void moveCarLeft(int carPos){
  487.  
  488. if (allCars[level-1][carPos].timeToStart <= globalTimer)
  489. allCars[level-1][carPos].drawable = true;
  490.  
  491. if (allCars[level-1][carPos].drawable){
  492. allCars[level-1][carPos].timer++;
  493. allCars[level-1][carPos].x-=allCars[level-1][carPos].speed;
  494.  
  495. if (allCars[level-1][carPos].x < -20)
  496. allCars[level-1][carPos].drawable = false;
  497.  
  498. if (allCars[level-1][carPos].timer > allCars[level-1][carPos].timeToLive)
  499. {
  500. allCars[level-1][carPos].x = 20;
  501. allCars[level-1] [carPos].drawable = true;
  502. allCars[level-1][carPos].timer = 0;
  503. }
  504. }
  505. }
  506. void updateScore(){
  507. int numberOfCarsPassed=0;
  508. for (int i = 0; i < (sizeof(allCars[level - 1]) / sizeof(*allCars[level - 1])); i++){
  509. if (frogz < allCars[level - 1][i].z&&allCars[level-1][i].direction!=0){
  510. numberOfCarsPassed++;
  511. }
  512. }
  513. currentLevelScore = numberOfCarsPassed * 10;
  514. }
  515. void restoreLight(){
  516. if (lightx < 0.69){
  517. lightx += 0.1;
  518. lightz += 0.1;
  519. lighty += 0.1;
  520. }
  521. }
  522. void timeF(int val)
  523. {
  524.  
  525. globalTimer++;
  526. for (int i = 0; i < (sizeof(allCars[level-1]) / sizeof(*allCars[level-1])); i++){
  527. if (allCars[level-1][i].direction == 0) // If it is not initalized
  528. continue;
  529. if (allCars[level-1][i].direction == 1)
  530. moveCarRight(i);
  531. else
  532. moveCarLeft(i);
  533. }
  534. checkCollision();
  535. checkWon();
  536. restoreLight();
  537. updateScore();
  538. glutPostRedisplay();
  539.  
  540. glutTimerFunc(100, timeF, 0);
  541. }
  542.  
  543. void skyBox(){
  544. glPushMatrix();
  545.  
  546. GLUquadricObj * qobj;
  547. qobj = gluNewQuadric();
  548. glTranslated(50, 0, 0);
  549. glRotated(90, 1, 0, 1);
  550. glBindTexture(GL_TEXTURE_2D, tex);
  551. gluQuadricTexture(qobj, true);
  552. gluQuadricNormals(qobj, GL_SMOOTH);
  553. gluSphere(qobj, 300, 300, 300);
  554. gluDeleteQuadric(qobj);
  555.  
  556.  
  557. glPopMatrix();
  558.  
  559. }
  560.  
  561. void level1(){
  562. //Our Fancy Level 1
  563.  
  564. //glEnable(GL_TEXTURE_2D);
  565. //glBindTexture(GL_TEXTURE_2D, tex_ground.texture[0]);
  566.  
  567. //First Green Region
  568. glPushMatrix();
  569. glBindTexture(GL_TEXTURE_2D, ground);
  570. glBegin(GL_QUADS);
  571. glColor3f(0, 1, 0);
  572. glNormal3f(0, 1, 0);
  573. glTexCoord2f(0, 0);
  574. glVertex3f(-20, 1, -65);
  575. glTexCoord2f(5, 0);
  576. glVertex3f(-20, 1, 25);
  577. glTexCoord2f(5, 5);
  578. glVertex3f(20, 1, 25);
  579. glTexCoord2f(0, 5);
  580. glVertex3f(20, 1, -65);
  581. glEnd();
  582. glPopMatrix();
  583.  
  584.  
  585. //First Left Portal
  586. glPushMatrix();
  587. glBegin(GL_QUADS);
  588. glColor3f(0, 0, 1);
  589. glNormal3f(0, 1, 0);
  590. glVertex3f(-20, 5, 0);
  591. glVertex3f(-20, 5, -10);
  592.  
  593. glVertex3f(-20, 1, -10);
  594. glVertex3f(-20, 1, 0);
  595. glEnd();
  596. glPopMatrix();
  597.  
  598. //First Right Portal
  599. glPushMatrix();
  600. glBegin(GL_QUADS);
  601. glColor3f(0, 0, 1);
  602. glNormal3f(0, 1, 0);
  603. glVertex3f(20, 5, 0);
  604. glVertex3f(20, 5, -10);
  605. glVertex3f(20, 1, -10);
  606. glVertex3f(20, 1, 0);
  607. glEnd();
  608. glPopMatrix();
  609.  
  610. //First Black Road
  611. glPushMatrix();
  612. glBegin(GL_QUADS);
  613. glColor3f(0, 0, 0);
  614. glNormal3f(0, 1, 0);
  615. glVertex3f(-20, 1.3, 0);
  616. glVertex3f(-20, 1.3, -10);
  617. glVertex3f(20, 1.3, -10);
  618. glVertex3f(20, 1.3, 0);
  619. glEnd();
  620. glPopMatrix();
  621.  
  622. glPushMatrix();
  623. //First White Stripes
  624. renderWhiteStripes(-20, 20, -5, 1);
  625. //Second White Stripes
  626. renderWhiteStripes(-20, 20, -37.5, 1);
  627. //Third White Stripes
  628. renderWhiteStripes(-20, 20, -27.5, 1);
  629. glPopMatrix();
  630.  
  631. //Second Left Portal
  632. glPushMatrix();
  633. glBegin(GL_QUADS);
  634. glColor3f(0, 0, 1);
  635. glNormal3f(0, 1, 0);
  636. glVertex3f(-20, 5, -20);
  637. glVertex3f(-20, 5, -45);
  638. glVertex3f(-20, 1, -45);
  639. glVertex3f(-20, 1, -20);
  640. glEnd();
  641. glPopMatrix();
  642.  
  643. //Second Right Portal
  644. glPushMatrix();
  645. glBegin(GL_QUADS);
  646. glColor3f(0, 0, 1);
  647. glNormal3f(0, 1, 0);
  648. glVertex3f(20, 5, -20);
  649. glVertex3f(20, 5, -45);
  650. glVertex3f(20, 1, -45);
  651. glVertex3f(20, 1, -20);
  652. glEnd();
  653. glPopMatrix();
  654.  
  655. //Second Black Road
  656. glPushMatrix();
  657. glBegin(GL_QUADS);
  658. glColor3f(0, 0, 0);
  659. glNormal3f(0, 1, 0);
  660. glVertex3f(-20, 1.3, -20);
  661. glVertex3f(-20, 1.3, -45);
  662. glVertex3f(20, 1.3, -45);
  663. glVertex3f(20, 1.3, -20);
  664. glEnd();
  665. glPopMatrix();
  666.  
  667. glColor3f(1, 1, 1);
  668.  
  669. drawBush(-5, 5);
  670. drawBush(10, -55);
  671.  
  672. glPushMatrix();
  673. glTranslatef(18, 0, 5);
  674. glScalef(0.7, 0.7, 0.7);
  675. model_tree.Draw();
  676. glPopMatrix();
  677.  
  678. glPushMatrix();
  679. glTranslatef(-18, 0, 5);
  680. glScalef(0.7, 0.7, 0.7);
  681. model_tree.Draw();
  682. glPopMatrix();
  683.  
  684. glPushMatrix();
  685. glTranslatef(18, 0, -15);
  686. glScalef(0.7, 0.7, 0.7);
  687. model_tree.Draw();
  688. glPopMatrix();
  689.  
  690. glPushMatrix();
  691. glTranslatef(-18, 0, -15);
  692. glScalef(0.7, 0.7, 0.7);
  693. model_tree.Draw();
  694. glPopMatrix();
  695.  
  696. glPushMatrix();
  697. glTranslatef(18, 0, -55);
  698. glScalef(0.7, 0.7, 0.7);
  699. model_tree.Draw();
  700. glPopMatrix();
  701.  
  702. glPushMatrix();
  703. glTranslatef(-18, 0, -55);
  704. glScalef(0.7, 0.7, 0.7);
  705. model_tree.Draw();
  706. glPopMatrix();
  707.  
  708. }
  709.  
  710. void level2(){
  711. //Our Fancy Level 2
  712.  
  713.  
  714. //First Green Region
  715. glPushMatrix();
  716. glBindTexture(GL_TEXTURE_2D, ground);
  717. glBegin(GL_QUADS);
  718. glColor3f(0, 1, 0);
  719. glNormal3f(0, 1, 0);
  720. glTexCoord2f(0, 0);
  721. glVertex3f(-20, 1, -55);
  722. glTexCoord2f(5, 0);
  723. glVertex3f(-20, 1, 25);
  724. glTexCoord2f(5, 5);
  725. glVertex3f(20, 1, 25);
  726. glTexCoord2f(0, 5);
  727. glVertex3f(20, 1, -55);
  728. glEnd();
  729. glPopMatrix();
  730.  
  731.  
  732.  
  733. //First Left Portal
  734. glPushMatrix();
  735. glBegin(GL_QUADS);
  736. glColor3f(0, 0, 1);
  737. glNormal3f(0, 1, 0);
  738. glVertex3f(-20, 5, 10);
  739. glVertex3f(-20, 5, 5);
  740. glVertex3f(-20, 1, 5);
  741. glVertex3f(-20, 1, 10);
  742. glEnd();
  743. glPopMatrix();
  744.  
  745. //First Right Portal
  746. glPushMatrix();
  747. glBegin(GL_QUADS);
  748. glColor3f(0, 0, 1);
  749. glNormal3f(0, 1, 0);
  750. glVertex3f(20, 5, 10);
  751. glVertex3f(20, 5, 5);
  752. glVertex3f(20, 1, 5);
  753. glVertex3f(20, 1, 10);
  754. glEnd();
  755. glPopMatrix();
  756.  
  757. //First Black Road
  758. glPushMatrix();
  759. glBegin(GL_QUADS);
  760. glColor3f(0, 0, 0);
  761. glNormal3f(0, 1, 0);
  762. glVertex3f(-20, 1.3, 10);
  763. glVertex3f(-20, 1.3, 5);
  764. glVertex3f(20, 1.3, 5);
  765. glVertex3f(20, 1.3, 10);
  766. glEnd();
  767. glPopMatrix();
  768.  
  769. //Second Left Portal
  770. glPushMatrix();
  771. glBegin(GL_QUADS);
  772. glColor3f(0, 0, 1);
  773. glNormal3f(0, 1, 0);
  774. glVertex3f(-20, 5, 0);
  775. glVertex3f(-20, 5, -10);
  776. glVertex3f(-20, 1, -10);
  777. glVertex3f(-20, 1, 0);
  778. glEnd();
  779. glPopMatrix();
  780.  
  781. //Second Right Portal
  782. glPushMatrix();
  783. glBegin(GL_QUADS);
  784. glColor3f(0, 0, 1);
  785. glNormal3f(0, 1, 0);
  786. glVertex3f(20, 5, 0);
  787. glVertex3f(20, 5, -10);
  788. glVertex3f(20, 1, -10);
  789. glVertex3f(20, 1, 0);
  790. glEnd();
  791. glPopMatrix();
  792.  
  793. renderWhiteStripes(-20, 20, -5, 1);
  794.  
  795. //Second Black Road
  796. glPushMatrix();
  797. glBegin(GL_QUADS);
  798. glColor3f(0, 0, 0);
  799. glNormal3f(0, 1, 0);
  800. glVertex3f(-20, 1.3, 0);
  801. glVertex3f(-20, 1.3, -10);
  802. glVertex3f(20, 1.3, -10);
  803. glVertex3f(20, 1.3, 0);
  804. glEnd();
  805. glPopMatrix();
  806.  
  807.  
  808. //Third Left Portal
  809. glPushMatrix();
  810. glBegin(GL_QUADS);
  811. glColor3f(0, 0, 1);
  812. glNormal3f(0, 1, 0);
  813. glVertex3f(-20, 5, -20);
  814. glVertex3f(-20, 5, -40);
  815. glVertex3f(-20, 1, -40);
  816. glVertex3f(-20, 1, -20);
  817. glEnd();
  818. glPopMatrix();
  819.  
  820. //Third Right Portal
  821. glPushMatrix();
  822. glBegin(GL_QUADS);
  823. glColor3f(0, 0, 1);
  824. glNormal3f(0, 1, 0);
  825. glVertex3f(20, 5, -20);
  826. glVertex3f(20, 5, -40);
  827. glVertex3f(20, 1, -40);
  828. glVertex3f(20, 1, -20);
  829. glEnd();
  830. glPopMatrix();
  831.  
  832. renderWhiteStripes(-20, 20, -25, 1);
  833. renderWhiteStripes(-20, 20, -30, 1);
  834. renderWhiteStripes(-20, 20, -35, 1);
  835.  
  836. //Third Black Road
  837. glPushMatrix();
  838. glBegin(GL_QUADS);
  839. glColor3f(0, 0, 0);
  840. glNormal3f(0, 1, 0);
  841. glVertex3f(-20, 1.3, -20);
  842. glVertex3f(-20, 1.3, -40);
  843. glVertex3f(20, 1.3, -40);
  844. glVertex3f(20, 1.3, -20);
  845. glEnd();
  846. glPopMatrix();
  847.  
  848. glColor3f(1, 1, 1);
  849.  
  850. drawBush(-15, 3);
  851. drawBush(5, 3);
  852. drawBush(-15, -12);
  853. drawBush(10, -18);
  854. drawBush(0, -49);
  855.  
  856. glPushMatrix();
  857. glTranslatef(-14, 0, 15);
  858. glScalef(0.7, 0.7, 0.7);
  859. model_tree.Draw();
  860. glPopMatrix();
  861.  
  862. glPushMatrix();
  863. glTranslatef(10, 0, 10);
  864. glScalef(0.7, 0.7, 0.7);
  865. model_tree.Draw();
  866. glPopMatrix();
  867.  
  868. glPushMatrix();
  869. glTranslatef(-7, 0, -15);
  870. glScalef(0.7, 0.7, 0.7);
  871. model_tree.Draw();
  872. glPopMatrix();
  873.  
  874. glPushMatrix();
  875. glTranslatef(18, 0, -47);
  876. glScalef(0.7, 0.7, 0.7);
  877. model_tree.Draw();
  878. glPopMatrix();
  879.  
  880. glPushMatrix();
  881. glTranslatef(-18, 0, -47);
  882. glScalef(0.7, 0.7, 0.7);
  883. model_tree.Draw();
  884. glPopMatrix();
  885.  
  886.  
  887.  
  888. }
  889.  
  890. void level3(){
  891. //Our Fancy Level 3
  892.  
  893.  
  894. //First Green Region
  895. glPushMatrix();
  896. glBindTexture(GL_TEXTURE_2D, ground);
  897. glBegin(GL_QUADS);
  898. glColor3f(0, 1, 0);
  899. glNormal3f(0, 1, 0);
  900. glTexCoord2f(0, 0);
  901. glVertex3f(-20, 1, -75);
  902. glTexCoord2f(5, 0);
  903. glVertex3f(-20, 1, 25);
  904. glTexCoord2f(5, 5);
  905. glVertex3f(20, 1, 25);
  906. glTexCoord2f(0, 5);
  907. glVertex3f(20, 1, -75);
  908. glEnd();
  909. glPopMatrix();
  910.  
  911.  
  912.  
  913. //First Left Portal
  914. glPushMatrix();
  915. glBegin(GL_QUADS);
  916. glColor3f(0, 0, 1);
  917. glNormal3f(0, 1, 0);
  918. glVertex3f(-20, 5, 15);
  919. glVertex3f(-20, 5, 0);
  920. glVertex3f(-20, 1, 0);
  921. glVertex3f(-20, 1, 15);
  922. glEnd();
  923. glPopMatrix();
  924.  
  925. //First Right Portal
  926. glPushMatrix();
  927. glBegin(GL_QUADS);
  928. glColor3f(0, 0, 1);
  929. glNormal3f(0, 1, 0);
  930. glVertex3f(20, 5, 15);
  931. glVertex3f(20, 5, 0);
  932. glVertex3f(20, 1, 0);
  933. glVertex3f(20, 1, 15);
  934. glEnd();
  935. glPopMatrix();
  936.  
  937. renderWhiteStripes(-20, 20, 5, 1);
  938. renderWhiteStripes(-20, 20, 10, 1);
  939.  
  940. //First Black Road
  941. glPushMatrix();
  942. glBegin(GL_QUADS);
  943. glColor3f(0, 0, 0);
  944. glNormal3f(0, 1, 0);
  945. glVertex3f(-20, 1.3, 15);
  946. glVertex3f(-20, 1.3, 0);
  947. glVertex3f(20, 1.3, 0);
  948. glVertex3f(20, 1.3, 15);
  949. glEnd();
  950. glPopMatrix();
  951.  
  952. //Second Left Portal
  953. glPushMatrix();
  954. glBegin(GL_QUADS);
  955. glColor3f(0, 0, 1);
  956. glNormal3f(0, 1, 0);
  957. glVertex3f(-20, 5, -5);
  958. glVertex3f(-20, 5, -15);
  959. glVertex3f(-20, 1, -15);
  960. glVertex3f(-20, 1, -5);
  961. glEnd();
  962. glPopMatrix();
  963.  
  964. //Second Right Portal
  965. glPushMatrix();
  966. glBegin(GL_QUADS);
  967. glColor3f(0, 0, 1);
  968. glNormal3f(0, 1, 0);
  969. glVertex3f(20, 5, -5);
  970. glVertex3f(20, 5, -15);
  971. glVertex3f(20, 1, -15);
  972. glVertex3f(20, 1, -5);
  973. glEnd();
  974. glPopMatrix();
  975.  
  976. renderWhiteStripes(-20, 20, -10, 1);
  977.  
  978. //Second Black Road
  979. glPushMatrix();
  980. glBegin(GL_QUADS);
  981. glColor3f(0, 0, 0);
  982. glNormal3f(0, 1, 0);
  983. glVertex3f(-20, 1.3, -5);
  984. glVertex3f(-20, 1.3, -15);
  985. glVertex3f(20, 1.3, -15);
  986. glVertex3f(20, 1.3, -5);
  987. glEnd();
  988. glPopMatrix();
  989.  
  990. //Third Left Portal
  991. glPushMatrix();
  992. glBegin(GL_QUADS);
  993. glColor3f(0, 0, 1);
  994. glNormal3f(0, 1, 0);
  995. glVertex3f(-20, 5, -25);
  996. glVertex3f(-20, 5, -50);
  997. glVertex3f(-20, 1, -50);
  998. glVertex3f(-20, 1, -25);
  999. glEnd();
  1000. glPopMatrix();
  1001.  
  1002. //Third Right Portal
  1003. glPushMatrix();
  1004. glBegin(GL_QUADS);
  1005. glColor3f(0, 0, 1);
  1006. glNormal3f(0, 1, 0);
  1007. glVertex3f(20, 5, -25);
  1008. glVertex3f(20, 5, -50);
  1009. glVertex3f(20, 1, -50);
  1010. glVertex3f(20, 1, -25);
  1011. glEnd();
  1012. glPopMatrix();
  1013.  
  1014. renderWhiteStripes(-20, 20, -30, 1);
  1015. renderWhiteStripes(-20, 20, -35, 1);
  1016. renderWhiteStripes(-20, 20, -40, 1);
  1017. renderWhiteStripes(-20, 20, -45, 1);
  1018.  
  1019. //Third Black Road
  1020. glPushMatrix();
  1021. glBegin(GL_QUADS);
  1022. glColor3f(0, 0, 0);
  1023. glNormal3f(0, 1, 0);
  1024. glVertex3f(-20, 1.3, -25);
  1025. glVertex3f(-20, 1.3, -50);
  1026. glVertex3f(20, 1.3, -50);
  1027. glVertex3f(20, 1.3, -25);
  1028. glEnd();
  1029. glPopMatrix();
  1030.  
  1031. glColor3f(1, 1, 1);
  1032.  
  1033. drawBush(-3, -3);
  1034. drawBush(-7, -16);
  1035. drawBush(9, -22);
  1036. drawBush(-2, -55);
  1037.  
  1038. glPushMatrix();
  1039. glTranslatef(10, 0, 18);
  1040. glScalef(0.7, 0.7, 0.7);
  1041. model_tree.Draw();
  1042. glPopMatrix();
  1043.  
  1044. glPushMatrix();
  1045. glTranslatef(-15, 0, -3);
  1046. glScalef(0.7, 0.7, 0.7);
  1047. model_tree.Draw();
  1048. glPopMatrix();
  1049.  
  1050. glPushMatrix();
  1051. glTranslatef(5, 0, -3);
  1052. glScalef(0.7, 0.7, 0.7);
  1053. model_tree.Draw();
  1054. glPopMatrix();
  1055.  
  1056. glPushMatrix();
  1057. glTranslatef(-10, 0, -20);
  1058. glScalef(0.7, 0.7, 0.7);
  1059. model_tree.Draw();
  1060. glPopMatrix();
  1061.  
  1062. glPushMatrix();
  1063. glTranslatef(15, 0, -60);
  1064. glScalef(0.7, 0.7, 0.7);
  1065. model_tree.Draw();
  1066. glPopMatrix();
  1067.  
  1068. glPushMatrix();
  1069. glTranslatef(-5, 0, -60);
  1070. glScalef(0.7, 0.7, 0.7);
  1071. model_tree.Draw();
  1072. glPopMatrix();
  1073.  
  1074.  
  1075. }
  1076.  
  1077. void level4(){
  1078.  
  1079. //Our Fancy Level 4
  1080.  
  1081.  
  1082. //First Green Region
  1083. glPushMatrix();
  1084. glBindTexture(GL_TEXTURE_2D, ground);
  1085. glBegin(GL_QUADS);
  1086. glColor3f(0, 1, 0);
  1087. glNormal3f(0, 1, 0);
  1088. glTexCoord2f(0, 0);
  1089. glVertex3f(-20, 1, -80);
  1090. glTexCoord2f(5, 0);
  1091. glVertex3f(-20, 1, 25);
  1092. glTexCoord2f(5, 5);
  1093. glVertex3f(20, 1, 25);
  1094. glTexCoord2f(0, 5);
  1095. glVertex3f(20, 1, -80);
  1096. glEnd();
  1097. glPopMatrix();
  1098.  
  1099.  
  1100.  
  1101. //First Left Portal
  1102. glPushMatrix();
  1103. glBegin(GL_QUADS);
  1104. glColor3f(0, 0, 1);
  1105. glNormal3f(0, 1, 0);
  1106. glVertex3f(-20, 5, 10);
  1107. glVertex3f(-20, 5, 0);
  1108. glVertex3f(-20, 1, 0);
  1109. glVertex3f(-20, 1, 10);
  1110. glEnd();
  1111. glPopMatrix();
  1112.  
  1113. //First Right Portal
  1114. glPushMatrix();
  1115. glBegin(GL_QUADS);
  1116. glColor3f(0, 0, 1);
  1117. glNormal3f(0, 1, 0);
  1118. glVertex3f(20, 5, 10);
  1119. glVertex3f(20, 5, 0);
  1120. glVertex3f(20, 1, 0);
  1121. glVertex3f(20, 1, 10);
  1122. glEnd();
  1123. glPopMatrix();
  1124.  
  1125. renderWhiteStripes(-20, 20, 5, 1);
  1126.  
  1127. //First Black Road
  1128. glPushMatrix();
  1129. glBegin(GL_QUADS);
  1130. glColor3f(0, 0, 0);
  1131. glNormal3f(0, 1, 0);
  1132. glVertex3f(-20, 1.3, 10);
  1133. glVertex3f(-20, 1.3, 0);
  1134. glVertex3f(20, 1.3, 0);
  1135. glVertex3f(20, 1.3, 10);
  1136. glEnd();
  1137. glPopMatrix();
  1138.  
  1139. //Second Left Portal
  1140. glPushMatrix();
  1141. glBegin(GL_QUADS);
  1142. glColor3f(0, 0, 1);
  1143. glNormal3f(0, 1, 0);
  1144. glVertex3f(-20, 5, -15);
  1145. glVertex3f(-20, 5, -30);
  1146. glVertex3f(-20, 1, -30);
  1147. glVertex3f(-20, 1, -15);
  1148. glEnd();
  1149. glPopMatrix();
  1150.  
  1151. //Second Right Portal
  1152. glPushMatrix();
  1153. glBegin(GL_QUADS);
  1154. glColor3f(0, 0, 1);
  1155. glNormal3f(0, 1, 0);
  1156. glVertex3f(20, 5, -15);
  1157. glVertex3f(20, 5, -30);
  1158. glVertex3f(20, 1, -30);
  1159. glVertex3f(20, 1, -15);
  1160. glEnd();
  1161. glPopMatrix();
  1162.  
  1163. renderWhiteStripes(-20, 20, -20, 1);
  1164. renderWhiteStripes(-20, 20, -25, 1);
  1165.  
  1166. //Second Black Road
  1167. glPushMatrix();
  1168. glBegin(GL_QUADS);
  1169. glColor3f(0, 0, 0);
  1170. glNormal3f(0, 1, 0);
  1171. glVertex3f(-20, 1.3, -15);
  1172. glVertex3f(-20, 1.3, -30);
  1173. glVertex3f(20, 1.3, -30);
  1174. glVertex3f(20, 1.3, -15);
  1175. glEnd();
  1176. glPopMatrix();
  1177.  
  1178.  
  1179. //Third Left Portal
  1180. glPushMatrix();
  1181. glBegin(GL_QUADS);
  1182. glColor3f(0, 0, 1);
  1183. glNormal3f(0, 1, 0);
  1184. glVertex3f(-20, 5, -40);
  1185. glVertex3f(-20, 5, -55);
  1186. glVertex3f(-20, 1, -55);
  1187. glVertex3f(-20, 1, -40);
  1188. glEnd();
  1189. glPopMatrix();
  1190.  
  1191. //Third Right Portal
  1192. glPushMatrix();
  1193. glBegin(GL_QUADS);
  1194. glColor3f(0, 0, 1);
  1195. glNormal3f(0, 1, 0);
  1196. glVertex3f(20, 5, -40);
  1197. glVertex3f(20, 5, -55);
  1198. glVertex3f(20, 1, -55);
  1199. glVertex3f(20, 1, -40);
  1200. glEnd();
  1201. glPopMatrix();
  1202.  
  1203. renderWhiteStripes(-20, 20, -45, 1);
  1204. renderWhiteStripes(-20, 20, -50, 1);
  1205.  
  1206. //Third Black Road
  1207. glPushMatrix();
  1208. glBegin(GL_QUADS);
  1209. glColor3f(0, 0, 0);
  1210. glNormal3f(0, 1, 0);
  1211. glVertex3f(-20, 1.3, -40);
  1212. glVertex3f(-20, 1.3, -55);
  1213. glVertex3f(20, 1.3, -55);
  1214. glVertex3f(20, 1.3, -40);
  1215. glEnd();
  1216. glPopMatrix();
  1217.  
  1218.  
  1219. //Fourth Left Portal
  1220. glPushMatrix();
  1221. glBegin(GL_QUADS);
  1222. glColor3f(0, 0, 1);
  1223. glNormal3f(0, 1, 0);
  1224. glVertex3f(-20, 5, -60);
  1225. glVertex3f(-20, 5, -75);
  1226. glVertex3f(-20, 1, -75);
  1227. glVertex3f(-20, 1, -60);
  1228. glEnd();
  1229. glPopMatrix();
  1230.  
  1231. //Fourth Right Portal
  1232. glPushMatrix();
  1233. glBegin(GL_QUADS);
  1234. glColor3f(0, 0, 1);
  1235. glNormal3f(0, 1, 0);
  1236. glVertex3f(20, 5, -60);
  1237. glVertex3f(20, 5, -75);
  1238. glVertex3f(20, 1, -75);
  1239. glVertex3f(20, 1, -60);
  1240. glEnd();
  1241. glPopMatrix();
  1242.  
  1243. renderWhiteStripes(-20, 20, -65, 1);
  1244. renderWhiteStripes(-20, 20, -70, 1);
  1245.  
  1246. //Fourth Black Road
  1247. glPushMatrix();
  1248. glBegin(GL_QUADS);
  1249. glColor3f(0, 0, 0);
  1250. glNormal3f(0, 1, 0);
  1251. glVertex3f(-20, 1.3, -60);
  1252. glVertex3f(-20, 1.3, -75);
  1253. glVertex3f(20, 1.3, -75);
  1254. glVertex3f(20, 1.3, -60);
  1255. glEnd();
  1256. glPopMatrix();
  1257.  
  1258. glColor3f(1, 1, 1);
  1259.  
  1260. drawBush(-7, -3);
  1261. drawBush(-18, -8);
  1262. drawBush(17, -12);
  1263. drawBush(4, -35);
  1264. drawBush(2, -57);
  1265. drawBush(-14, -77);
  1266. drawBush(11, -77);
  1267.  
  1268. //First 2 Tree's
  1269. glPushMatrix();
  1270. glTranslatef(-15, 0, 15);
  1271. glScalef(0.7, 0.7, 0.7);
  1272. model_tree.Draw();
  1273. glPopMatrix();
  1274.  
  1275. glPushMatrix();
  1276. glTranslatef(5, 0, 20);
  1277. glScalef(0.7, 0.7, 0.7);
  1278. model_tree.Draw();
  1279. glPopMatrix();
  1280. //Second Tree
  1281. glPushMatrix();
  1282. glTranslatef(5, 0, -3);
  1283. glScalef(0.7, 0.7, 0.7);
  1284. model_tree.Draw();
  1285. glPopMatrix();
  1286. //Third Tree
  1287. glPushMatrix();
  1288. glTranslatef(-5, 0, -12);
  1289. glScalef(0.7, 0.7, 0.7);
  1290. model_tree.Draw();
  1291. glPopMatrix();
  1292. //Fourth Tree
  1293. glPushMatrix();
  1294. glTranslatef(18, 0, -35);
  1295. glScalef(0.7, 0.7, 0.7);
  1296. model_tree.Draw();
  1297. glPopMatrix();
  1298. //Fifth Tree
  1299. glPushMatrix();
  1300. glTranslatef(-18, 0, -58);
  1301. glScalef(0.7, 0.7, 0.7);
  1302. model_tree.Draw();
  1303. glPopMatrix();
  1304.  
  1305. //Sixth Tree
  1306. glPushMatrix();
  1307. glTranslatef(-18, 0, -77);
  1308. glScalef(0.7, 0.7, 0.7);
  1309. model_tree.Draw();
  1310. glPopMatrix();
  1311.  
  1312. //Seventh Tree
  1313. glPushMatrix();
  1314. glTranslatef(-10, 0, -77);
  1315. glScalef(0.7, 0.7, 0.7);
  1316. model_tree.Draw();
  1317. glPopMatrix();
  1318.  
  1319. //Eigth Tree
  1320. glPushMatrix();
  1321. glTranslatef(7, 0, -77);
  1322. glScalef(0.7, 0.7, 0.7);
  1323. model_tree.Draw();
  1324. glPopMatrix();
  1325.  
  1326. //Ninth Tree
  1327. glPushMatrix();
  1328. glTranslatef(15, 0, -77);
  1329. glScalef(0.7, 0.7, 0.7);
  1330. model_tree.Draw();
  1331. glPopMatrix();
  1332.  
  1333. }
  1334.  
  1335. void level5(){
  1336.  
  1337. //Our Fancy Level 5
  1338.  
  1339.  
  1340. //First Green Region
  1341. glPushMatrix();
  1342. glBindTexture(GL_TEXTURE_2D, ground);
  1343. glBegin(GL_QUADS);
  1344. glColor3f(0, 1, 0);
  1345. glNormal3f(0, 1, 0);
  1346. glTexCoord2f(0, 0);
  1347. glVertex3f(-20, 1, -180);
  1348. glTexCoord2f(5, 0);
  1349. glVertex3f(-20, 1, 25);
  1350. glTexCoord2f(5, 5);
  1351. glVertex3f(20, 1, 25);
  1352. glTexCoord2f(0, 5);
  1353. glVertex3f(20, 1, -180);
  1354. glEnd();
  1355. glPopMatrix();
  1356.  
  1357.  
  1358.  
  1359. //First Left Portal
  1360. glPushMatrix();
  1361. glBegin(GL_QUADS);
  1362. glColor3f(0, 0, 1);
  1363. glNormal3f(0, 1, 0);
  1364. glVertex3f(-20, 5, 15);
  1365. glVertex3f(-20, 5, 0);
  1366. glVertex3f(-20, 1, 0);
  1367. glVertex3f(-20, 1, 15);
  1368. glEnd();
  1369. glPopMatrix();
  1370.  
  1371. //First Right Portal
  1372. glPushMatrix();
  1373. glBegin(GL_QUADS);
  1374. glColor3f(0, 0, 1);
  1375. glNormal3f(0, 1, 0);
  1376. glVertex3f(20, 5, 15);
  1377. glVertex3f(20, 5, 0);
  1378. glVertex3f(20, 1, 0);
  1379. glVertex3f(20, 1, 15);
  1380. glEnd();
  1381. glPopMatrix();
  1382.  
  1383. renderWhiteStripes(-20, 20, 5, 1);
  1384. renderWhiteStripes(-20, 20, 10, 1);
  1385.  
  1386. //First Black Road
  1387. glPushMatrix();
  1388. glBegin(GL_QUADS);
  1389. glColor3f(0, 0, 0);
  1390. glNormal3f(0, 1, 0);
  1391. glVertex3f(-20, 1.3, 15);
  1392. glVertex3f(-20, 1.3, 0);
  1393. glVertex3f(20, 1.3, 0);
  1394. glVertex3f(20, 1.3, 15);
  1395. glEnd();
  1396. glPopMatrix();
  1397.  
  1398.  
  1399. //Second Left Portal
  1400. glPushMatrix();
  1401. glBegin(GL_QUADS);
  1402. glColor3f(0, 0, 1);
  1403. glNormal3f(0, 1, 0);
  1404. glVertex3f(-20, 5, -5);
  1405. glVertex3f(-20, 5, -20);
  1406. glVertex3f(-20, 1, -20);
  1407. glVertex3f(-20, 1, -5);
  1408. glEnd();
  1409. glPopMatrix();
  1410.  
  1411. //Second Right Portal
  1412. glPushMatrix();
  1413. glBegin(GL_QUADS);
  1414. glColor3f(0, 0, 1);
  1415. glNormal3f(0, 1, 0);
  1416. glVertex3f(20, 5, -5);
  1417. glVertex3f(20, 5, -20);
  1418. glVertex3f(20, 1, -20);
  1419. glVertex3f(20, 1, -5);
  1420. glEnd();
  1421. glPopMatrix();
  1422.  
  1423. renderWhiteStripes(-20, 20, -10, 1);
  1424. renderWhiteStripes(-20, 20, -15, 1);
  1425.  
  1426. //Second Black Road
  1427. glPushMatrix();
  1428. glBegin(GL_QUADS);
  1429. glColor3f(0, 0, 0);
  1430. glNormal3f(0, 1, 0);
  1431. glVertex3f(-20, 1.3, -5);
  1432. glVertex3f(-20, 1.3, -20);
  1433. glVertex3f(20, 1.3, -20);
  1434. glVertex3f(20, 1.3, -5);
  1435. glEnd();
  1436. glPopMatrix();
  1437.  
  1438. //Third Left Portal
  1439. glPushMatrix();
  1440. glBegin(GL_QUADS);
  1441. glColor3f(0, 0, 1);
  1442. glNormal3f(0, 1, 0);
  1443. glVertex3f(-20, 5, -25);
  1444. glVertex3f(-20, 5, -40);
  1445. glVertex3f(-20, 1, -40);
  1446. glVertex3f(-20, 1, -25);
  1447. glEnd();
  1448. glPopMatrix();
  1449.  
  1450. //Third Right Portal
  1451. glPushMatrix();
  1452. glBegin(GL_QUADS);
  1453. glColor3f(0, 0, 1);
  1454. glNormal3f(0, 1, 0);
  1455. glVertex3f(20, 5, -25);
  1456. glVertex3f(20, 5, -40);
  1457. glVertex3f(20, 1, -40);
  1458. glVertex3f(20, 1, -25);
  1459. glEnd();
  1460. glPopMatrix();
  1461.  
  1462. renderWhiteStripes(-20, 20, -30, 1);
  1463. renderWhiteStripes(-20, 20, -35, 1);
  1464.  
  1465. //Third Black Road
  1466. glPushMatrix();
  1467. glBegin(GL_QUADS);
  1468. glColor3f(0, 0, 0);
  1469. glNormal3f(0, 1, 0);
  1470. glVertex3f(-20, 1.3, -25);
  1471. glVertex3f(-20, 1.3, -40);
  1472. glVertex3f(20, 1.3, -40);
  1473. glVertex3f(20, 1.3, -25);
  1474. glEnd();
  1475. glPopMatrix();
  1476.  
  1477. //Fourth Left Portal
  1478. glPushMatrix();
  1479. glBegin(GL_QUADS);
  1480. glColor3f(0, 0, 1);
  1481. glNormal3f(0, 1, 0);
  1482. glVertex3f(-20, 5, -45);
  1483. glVertex3f(-20, 5, -50);
  1484. glVertex3f(-20, 1, -50);
  1485. glVertex3f(-20, 1, -45);
  1486. glEnd();
  1487. glPopMatrix();
  1488.  
  1489. //Fourth Right Portal
  1490. glPushMatrix();
  1491. glBegin(GL_QUADS);
  1492. glColor3f(0, 0, 1);
  1493. glNormal3f(0, 1, 0);
  1494. glVertex3f(20, 5, -45);
  1495. glVertex3f(20, 5, -50);
  1496. glVertex3f(20, 1, -50);
  1497. glVertex3f(20, 1, -45);
  1498. glEnd();
  1499. glPopMatrix();
  1500.  
  1501. //Fourth Black Road
  1502. glPushMatrix();
  1503. glBegin(GL_QUADS);
  1504. glColor3f(0, 0, 0);
  1505. glNormal3f(0, 1, 0);
  1506. glVertex3f(-20, 1.3, -45);
  1507. glVertex3f(-20, 1.3, -50);
  1508. glVertex3f(20, 1.3, -50);
  1509. glVertex3f(20, 1.3, -45);
  1510. glEnd();
  1511. glPopMatrix();
  1512.  
  1513. //Fifth Left Portal
  1514. glPushMatrix();
  1515. glBegin(GL_QUADS);
  1516. glColor3f(0, 0, 1);
  1517. glNormal3f(0, 1, 0);
  1518. glVertex3f(-20, 5, -55);
  1519. glVertex3f(-20, 5, -105);
  1520. glVertex3f(-20, 1, -105);
  1521. glVertex3f(-20, 1, -55);
  1522. glEnd();
  1523. glPopMatrix();
  1524.  
  1525. //Fifth Right Portal
  1526. glPushMatrix();
  1527. glBegin(GL_QUADS);
  1528. glColor3f(0, 0, 1);
  1529. glNormal3f(0, 1, 0);
  1530. glVertex3f(20, 5, -55);
  1531. glVertex3f(20, 5, -105);
  1532. glVertex3f(20, 1, -105);
  1533. glVertex3f(20, 1, -55);
  1534. glEnd();
  1535. glPopMatrix();
  1536.  
  1537. renderWhiteStripes(-20, 20, -60, 1);
  1538. renderWhiteStripes(-20, 20, -65, 1);
  1539. renderWhiteStripes(-20, 20, -70, 1);
  1540. renderWhiteStripes(-20, 20, -75, 1);
  1541. renderWhiteStripes(-20, 20, -80, 1);
  1542. renderWhiteStripes(-20, 20, -85, 1);
  1543. renderWhiteStripes(-20, 20, -90, 1);
  1544. renderWhiteStripes(-20, 20, -95, 1);
  1545. renderWhiteStripes(-20, 20, -100, 1);
  1546.  
  1547. //Fifth Black Road
  1548. glPushMatrix();
  1549. glBegin(GL_QUADS);
  1550. glColor3f(0, 0, 0);
  1551. glNormal3f(0, 1, 0);
  1552. glVertex3f(-20, 1.3, -55);
  1553. glVertex3f(-20, 1.3, -105);
  1554. glVertex3f(20, 1.3, -105);
  1555. glVertex3f(20, 1.3, -55);
  1556. glEnd();
  1557. glPopMatrix();
  1558.  
  1559. glColor3f(1, 1, 1);
  1560.  
  1561. drawBush(-16, -3);
  1562. drawBush(7, -3);
  1563. drawBush(-12, -22);
  1564. drawBush(-16, -23);
  1565. drawBush(7, -43);
  1566. drawBush(-14, -52);
  1567. drawBush(14, -115);
  1568. //drawBush(14, -125);
  1569. drawBush(14, -135);
  1570. //drawBush(14, -145);
  1571. drawBush(14, -155);
  1572. //drawBush(14, -165);
  1573. drawBush(14, -175);
  1574. //drawBush(-14, -115);
  1575. drawBush(-14, -125);
  1576. //drawBush(-14, -135);
  1577. drawBush(-14, -145);
  1578. //drawBush(-14, -155);
  1579. drawBush(-14, -165);
  1580. //drawBush(-14, -175);
  1581.  
  1582.  
  1583. glPushMatrix();
  1584. glTranslatef(-18, 0, 20);
  1585. glScalef(0.7, 0.7, 0.7);
  1586. model_tree.Draw();
  1587. glPopMatrix();
  1588.  
  1589. glPushMatrix();
  1590. glTranslatef(15, 0, 22);
  1591. glScalef(0.7, 0.7, 0.7);
  1592. model_tree.Draw();
  1593. glPopMatrix();
  1594.  
  1595. glPushMatrix();
  1596. glTranslatef(-18, 0, -2);
  1597. glScalef(0.7, 0.7, 0.7);
  1598. model_tree.Draw();
  1599. glPopMatrix();
  1600.  
  1601. glPushMatrix();
  1602. glTranslatef(-8, 0, -3);
  1603. glScalef(0.7, 0.7, 0.7);
  1604. model_tree.Draw();
  1605. glPopMatrix();
  1606.  
  1607. glPushMatrix();
  1608. glTranslatef(15, 0, -4);
  1609. glScalef(0.7, 0.7, 0.7);
  1610. model_tree.Draw();
  1611. glPopMatrix();
  1612.  
  1613.  
  1614. glPushMatrix();
  1615. glTranslatef(5, 0, -22);
  1616. glScalef(0.7, 0.7, 0.7);
  1617. model_tree.Draw();
  1618. glPopMatrix();
  1619.  
  1620. glPushMatrix();
  1621. glTranslatef(10, 0, -23);
  1622. glScalef(0.7, 0.7, 0.7);
  1623. model_tree.Draw();
  1624. glPopMatrix();
  1625.  
  1626.  
  1627. glPushMatrix();
  1628. glTranslatef(0, 0, -24);
  1629. glScalef(0.7, 0.7, 0.7);
  1630. model_tree.Draw();
  1631. glPopMatrix();
  1632.  
  1633. glPushMatrix();
  1634. glTranslatef(-18, 0, -43);
  1635. glScalef(0.7, 0.7, 0.7);
  1636. model_tree.Draw();
  1637. glPopMatrix();
  1638.  
  1639. glPushMatrix();
  1640. glTranslatef(18, 0, -53);
  1641. glScalef(0.7, 0.7, 0.7);
  1642. model_tree.Draw();
  1643. glPopMatrix();
  1644.  
  1645. /*glPushMatrix();
  1646. glTranslatef(-18, 0, -110);
  1647. glScalef(0.7, 0.7, 0.7);
  1648. model_tree.Draw();
  1649. glPopMatrix();*/
  1650.  
  1651. glPushMatrix();
  1652. glTranslatef(-18, 0, -120);
  1653. glScalef(0.7, 0.7, 0.7);
  1654. model_tree.Draw();
  1655. glPopMatrix();
  1656.  
  1657. /*glPushMatrix();
  1658. glTranslatef(-18, 0, -130);
  1659. glScalef(0.7, 0.7, 0.7);
  1660. model_tree.Draw();
  1661. glPopMatrix();*/
  1662.  
  1663. glPushMatrix();
  1664. glTranslatef(-18, 0, -140);
  1665. glScalef(0.7, 0.7, 0.7);
  1666. model_tree.Draw();
  1667. glPopMatrix();
  1668.  
  1669. /*glPushMatrix();
  1670. glTranslatef(-18, 0, -150);
  1671. glScalef(0.7, 0.7, 0.7);
  1672. model_tree.Draw();
  1673. glPopMatrix();
  1674. */
  1675. glPushMatrix();
  1676. glTranslatef(-18, 0, -160);
  1677. glScalef(0.7, 0.7, 0.7);
  1678. model_tree.Draw();
  1679. glPopMatrix();
  1680.  
  1681. /*glPushMatrix();
  1682. glTranslatef(-18, 0, -170);
  1683. glScalef(0.7, 0.7, 0.7);
  1684. model_tree.Draw();
  1685. glPopMatrix();*/
  1686.  
  1687.  
  1688. glPushMatrix();
  1689. glTranslatef(18, 0, -110);
  1690. glScalef(0.7, 0.7, 0.7);
  1691. model_tree.Draw();
  1692. glPopMatrix();
  1693.  
  1694. /*glPushMatrix();
  1695. glTranslatef(18, 0, -120);
  1696. glScalef(0.7, 0.7, 0.7);
  1697. model_tree.Draw();
  1698. glPopMatrix();*/
  1699.  
  1700. glPushMatrix();
  1701. glTranslatef(18, 0, -130);
  1702. glScalef(0.7, 0.7, 0.7);
  1703. model_tree.Draw();
  1704. glPopMatrix();
  1705.  
  1706. /*glPushMatrix();
  1707. glTranslatef(18, 0, -140);
  1708. glScalef(0.7, 0.7, 0.7);
  1709. model_tree.Draw();
  1710. glPopMatrix();*/
  1711.  
  1712. glPushMatrix();
  1713. glTranslatef(18, 0, -150);
  1714. glScalef(0.7, 0.7, 0.7);
  1715. model_tree.Draw();
  1716. glPopMatrix();
  1717.  
  1718. /*glPushMatrix();
  1719. glTranslatef(18, 0, -160);
  1720. glScalef(0.7, 0.7, 0.7);
  1721. model_tree.Draw();
  1722. glPopMatrix();*/
  1723.  
  1724. glPushMatrix();
  1725. glTranslatef(18, 0, -170);
  1726. glScalef(0.7, 0.7, 0.7);
  1727. model_tree.Draw();
  1728. glPopMatrix();
  1729.  
  1730. }
  1731.  
  1732. void setupLights(){
  1733. GLfloat lightIntensity[] = { lightx, lighty, lightz, 1.0f };
  1734. GLfloat lightPosition[] = { -40.0f, 100.0f, -40.0f, 0.0f };
  1735. glPushMatrix();
  1736. // rotating the light
  1737. glRotated(angle, 1, 0, 0);
  1738. glRotated(angle1, 0, 0, 1);
  1739. glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
  1740. glLightfv(GL_LIGHT0, GL_AMBIENT, lightIntensity);
  1741. glPopMatrix();
  1742. }
  1743. void traceCam(){
  1744. printf("position x %f position y %f position z %f Dir x %f Dir y %f Dir z %f\n", camera.eye.x, camera.eye.y, camera.eye.z, camera.center.x, camera.center.y, camera.center.z);
  1745.  
  1746. }
  1747.  
  1748. void awesomeFrog(){
  1749. //frog
  1750.  
  1751.  
  1752. glPushMatrix();
  1753.  
  1754.  
  1755. glTranslated(frogx, frogy, frogz); //starting xyz
  1756. glScaled(0.5, 0.5, 0.5);
  1757. glRotated(frogrotation, 0, 1, 0); //used for frog rotation
  1758.  
  1759. glPushMatrix();
  1760.  
  1761. GLUquadricObj * frog;
  1762. frog = gluNewQuadric();
  1763. glTranslated(0, 4, 0);
  1764. glBindTexture(GL_TEXTURE_2D, fskin);
  1765. gluQuadricTexture(frog, true);
  1766. gluQuadricNormals(frog, GL_SMOOTH);
  1767. gluSphere(frog, 1, 50, 50);
  1768. gluDeleteQuadric(frog);
  1769.  
  1770. glPopMatrix();
  1771.  
  1772. glPushMatrix();
  1773.  
  1774. GLUquadricObj * froghead;
  1775. froghead = gluNewQuadric();
  1776. glTranslated(0, 5, 1);
  1777. glBindTexture(GL_TEXTURE_2D, fskin);
  1778. gluQuadricTexture(froghead, true);
  1779. gluQuadricNormals(froghead, GL_SMOOTH);
  1780. gluSphere(froghead, 0.7, 50, 50);
  1781. gluDeleteQuadric(froghead);
  1782.  
  1783. glPopMatrix();
  1784.  
  1785. glPushMatrix();
  1786.  
  1787. GLUquadricObj * frogeye;
  1788. frogeye = gluNewQuadric();
  1789. glTranslated(0, 5.5, 1.4);
  1790. glRotated(-35, 0, 1, 0);
  1791. glBindTexture(GL_TEXTURE_2D, feyes);
  1792. gluQuadricTexture(frogeye, true);
  1793. gluQuadricNormals(frogeye, GL_SMOOTH);
  1794. gluSphere(frogeye, 0.3, 50, 50);
  1795. gluDeleteQuadric(frogeye);
  1796.  
  1797. glPopMatrix();
  1798.  
  1799. glPushMatrix();
  1800.  
  1801. GLUquadricObj * frogeye2;
  1802. frogeye2 = gluNewQuadric();
  1803. glTranslated(0.5, 5.5, 1.2);
  1804. glRotated(-35, 0, 1, 0);
  1805. glBindTexture(GL_TEXTURE_2D, feyes);
  1806. gluQuadricTexture(frogeye2, true);
  1807. gluQuadricNormals(frogeye2, GL_SMOOTH);
  1808. gluSphere(frogeye2, 0.3, 50, 50);
  1809. gluDeleteQuadric(frogeye2);
  1810.  
  1811. glPopMatrix();
  1812.  
  1813. glPushMatrix();
  1814.  
  1815. GLUquadricObj * frognose;
  1816. frognose = gluNewQuadric();
  1817. glTranslated(0.2, 5.1, 1.7);
  1818. glBindTexture(GL_TEXTURE_2D, feet);
  1819. gluQuadricTexture(frognose, true);
  1820. gluQuadricNormals(frognose, GL_SMOOTH);
  1821. gluSphere(frognose, 0.07, 50, 50);
  1822. gluDeleteQuadric(frognose);
  1823.  
  1824. glPopMatrix();
  1825.  
  1826. glPushMatrix();
  1827.  
  1828. GLUquadricObj * frognose2;
  1829. frognose2 = gluNewQuadric();
  1830. glTranslated(0.5, 5.1, 1.5);
  1831. glBindTexture(GL_TEXTURE_2D, feet);
  1832. gluQuadricTexture(frognose2, true);
  1833. gluQuadricNormals(frognose2, GL_SMOOTH);
  1834. gluSphere(frognose2, 0.07, 50, 50);
  1835. gluDeleteQuadric(frognose2);
  1836.  
  1837. glPopMatrix();
  1838.  
  1839. glPushMatrix();
  1840.  
  1841. GLUquadricObj * frogmouth;
  1842. frogmouth = gluNewQuadric();
  1843. glTranslated(-0.2, 4.8, 1.7);
  1844. glRotated(180, 1, 0, 1);
  1845. glRotated(270, 0, 0, 1);
  1846. glBindTexture(GL_TEXTURE_2D, feet);
  1847. gluQuadricTexture(frogmouth, true);
  1848. gluQuadricNormals(frogmouth, GL_SMOOTH);
  1849. gluCylinder(frogmouth, 0.07, 0.1, 0.8, 10, 10);
  1850. gluDeleteQuadric(frogmouth);
  1851.  
  1852. glPopMatrix();
  1853.  
  1854. glPushMatrix();
  1855. glRotated(armrotation, 1, 0, 0); //rotation inside matrix of arm
  1856.  
  1857. glPushMatrix();
  1858.  
  1859. GLUquadricObj * frogarm;
  1860. frogarm = gluNewQuadric();
  1861. glTranslated(-0.3, 4, 0.9);
  1862. glRotated(90, 1, 0, 0);
  1863. glRotated(-20, 0, 1, 0);
  1864. glBindTexture(GL_TEXTURE_2D, flegs);
  1865. gluQuadricTexture(frogarm, true);
  1866. gluQuadricNormals(frogarm, GL_SMOOTH);
  1867. gluCylinder(frogarm, 0.1, 0.1, 0.7, 10, 10);
  1868. gluDeleteQuadric(frogarm);
  1869.  
  1870. glPopMatrix();
  1871.  
  1872. glPushMatrix();
  1873.  
  1874. GLUquadricObj * frogarm2;
  1875. frogarm2 = gluNewQuadric();
  1876. glTranslated(-0.55, 3.4, 0.9);
  1877. glRotated(90, 1, 0, 0);
  1878. glRotated(20, 0, 1, 0);
  1879. glBindTexture(GL_TEXTURE_2D, flegs);
  1880. gluQuadricTexture(frogarm2, true);
  1881. gluQuadricNormals(frogarm2, GL_SMOOTH);
  1882. gluCylinder(frogarm2, 0.1, 0.1, 0.7, 10, 10);
  1883. gluDeleteQuadric(frogarm2);
  1884.  
  1885. glPopMatrix();
  1886.  
  1887. glPushMatrix();
  1888.  
  1889. GLUquadricObj * frogarm2s;
  1890. frogarm2s = gluNewQuadric();
  1891. glTranslated(-0.55, 3.4, 0.9);
  1892. glRotated(90, 1, 0, 0);
  1893. glRotated(20, 0, 1, 0);
  1894. glBindTexture(GL_TEXTURE_2D, flegs);
  1895. gluQuadricTexture(frogarm2s, true);
  1896. gluQuadricNormals(frogarm2s, GL_SMOOTH);
  1897. gluSphere(frogarm2s, 0.1, 100, 100);
  1898. gluDeleteQuadric(frogarm2s);
  1899.  
  1900. glPopMatrix();
  1901.  
  1902. glPushMatrix();
  1903.  
  1904. GLUquadricObj * frogarmS;
  1905. frogarmS = gluNewQuadric();
  1906. glTranslated(-0.31, 2.75, 0.9);
  1907. glRotated(90, 1, 0, 0);
  1908. glRotated(20, 0, 1, 0);
  1909. glBindTexture(GL_TEXTURE_2D, flegs);
  1910. gluQuadricTexture(frogarmS, true);
  1911. gluQuadricNormals(frogarmS, GL_SMOOTH);
  1912. gluSphere(frogarmS, 0.1, 100, 100);
  1913. gluDeleteQuadric(frogarmS);
  1914.  
  1915. glPopMatrix();
  1916.  
  1917. glPushMatrix();
  1918.  
  1919. GLUquadricObj * frogfinger;
  1920. frogfinger = gluNewQuadric();
  1921. glTranslated(-0.31, 2.75, 0.9);
  1922. glRotated(-20, 0, 1, 0);
  1923. glBindTexture(GL_TEXTURE_2D, dskin);
  1924. gluQuadricTexture(frogfinger, true);
  1925. gluQuadricNormals(frogfinger, GL_SMOOTH);
  1926. gluCylinder(frogfinger, 0.075, 0.075, 0.2, 10, 10);
  1927. gluDeleteQuadric(frogfinger);
  1928.  
  1929. glPopMatrix();
  1930.  
  1931. glPushMatrix();
  1932.  
  1933. GLUquadricObj * frogfingerS;
  1934. frogfingerS = gluNewQuadric();
  1935. glTranslated(-0.39, 2.75, 1.1);
  1936. glBindTexture(GL_TEXTURE_2D, dskin);
  1937. gluQuadricTexture(frogfingerS, true);
  1938. gluQuadricNormals(frogfingerS, GL_SMOOTH);
  1939. gluSphere(frogfingerS, 0.075, 100, 100);
  1940. gluDeleteQuadric(frogfingerS);
  1941.  
  1942. glPopMatrix();
  1943.  
  1944. glPushMatrix();
  1945.  
  1946. GLUquadricObj * frogfinger2;
  1947. frogfinger2 = gluNewQuadric();
  1948. glTranslated(-0.31, 2.75, 0.9);
  1949. glRotated(20, 0, 1, 0);
  1950. glBindTexture(GL_TEXTURE_2D, dskin);
  1951. gluQuadricTexture(frogfinger2, true);
  1952. gluQuadricNormals(frogfinger2, GL_SMOOTH);
  1953. gluCylinder(frogfinger2, 0.075, 0.075, 0.2, 10, 10);
  1954. gluDeleteQuadric(frogfinger2);
  1955.  
  1956. glPopMatrix();
  1957.  
  1958. glPushMatrix();
  1959.  
  1960. GLUquadricObj * frogfinger2S;
  1961. frogfinger2S = gluNewQuadric();
  1962. glTranslated(-0.235, 2.75, 1.1);
  1963. glBindTexture(GL_TEXTURE_2D, dskin);
  1964. gluQuadricTexture(frogfinger2S, true);
  1965. gluQuadricNormals(frogfinger2S, GL_SMOOTH);
  1966. gluSphere(frogfinger2S, 0.075, 100, 100);
  1967. gluDeleteQuadric(frogfinger2S);
  1968.  
  1969. glPopMatrix();
  1970.  
  1971. //--------
  1972.  
  1973. glPushMatrix();
  1974.  
  1975. GLUquadricObj * frogarmright;
  1976. frogarmright = gluNewQuadric();
  1977. glTranslated(0.3, 4, 0.9);
  1978. glRotated(90, 1, 0, 0);
  1979. glRotated(20, 0, 1, 0);
  1980. glBindTexture(GL_TEXTURE_2D, flegs);
  1981. gluQuadricTexture(frogarmright, true);
  1982. gluQuadricNormals(frogarmright, GL_SMOOTH);
  1983. gluCylinder(frogarmright, 0.1, 0.1, 0.7, 10, 10);
  1984. gluDeleteQuadric(frogarmright);
  1985.  
  1986. glPopMatrix();
  1987.  
  1988. glPushMatrix();
  1989.  
  1990. GLUquadricObj * frogarm2right;
  1991. frogarm2right = gluNewQuadric();
  1992. glTranslated(0.55, 3.4, 0.9);
  1993. glRotated(90, 1, 0, 0);
  1994. glRotated(-20, 0, 1, 0);
  1995. glBindTexture(GL_TEXTURE_2D, flegs);
  1996. gluQuadricTexture(frogarm2right, true);
  1997. gluQuadricNormals(frogarm2right, GL_SMOOTH);
  1998. gluCylinder(frogarm2right, 0.1, 0.1, 0.7, 10, 10);
  1999. gluDeleteQuadric(frogarm2right);
  2000.  
  2001. glPopMatrix();
  2002.  
  2003. glPushMatrix();
  2004.  
  2005. GLUquadricObj * frogarm2sright;
  2006. frogarm2sright = gluNewQuadric();
  2007. glTranslated(0.55, 3.4, 0.9);
  2008. glRotated(90, 1, 0, 0);
  2009. glRotated(20, 0, 1, 0);
  2010. glBindTexture(GL_TEXTURE_2D, flegs);
  2011. gluQuadricTexture(frogarm2sright, true);
  2012. gluQuadricNormals(frogarm2sright, GL_SMOOTH);
  2013. gluSphere(frogarm2sright, 0.1, 100, 100);
  2014. gluDeleteQuadric(frogarm2sright);
  2015.  
  2016. glPopMatrix();
  2017.  
  2018. glPushMatrix();
  2019.  
  2020. GLUquadricObj * frogarmSright;
  2021. frogarmSright = gluNewQuadric();
  2022. glTranslated(0.31, 2.75, 0.9);
  2023. glRotated(90, 1, 0, 0);
  2024. glRotated(20, 0, 1, 0);
  2025. glBindTexture(GL_TEXTURE_2D, flegs);
  2026. gluQuadricTexture(frogarmSright, true);
  2027. gluQuadricNormals(frogarmSright, GL_SMOOTH);
  2028. gluSphere(frogarmSright, 0.1, 100, 100);
  2029. gluDeleteQuadric(frogarmSright);
  2030.  
  2031. glPopMatrix();
  2032.  
  2033. glPushMatrix();
  2034.  
  2035. GLUquadricObj * frogfingerright;
  2036. frogfingerright = gluNewQuadric();
  2037. glTranslated(0.31, 2.75, 0.9);
  2038. glRotated(-20, 0, 1, 0);
  2039. glBindTexture(GL_TEXTURE_2D, dskin);
  2040. gluQuadricTexture(frogfingerright, true);
  2041. gluQuadricNormals(frogfingerright, GL_SMOOTH);
  2042. gluCylinder(frogfingerright, 0.075, 0.075, 0.2, 10, 10);
  2043. gluDeleteQuadric(frogfingerright);
  2044.  
  2045. glPopMatrix();
  2046.  
  2047. glPushMatrix();
  2048.  
  2049. GLUquadricObj * frogfingerSright;
  2050. frogfingerSright = gluNewQuadric();
  2051. glTranslated(0.39, 2.75, 1.1);
  2052. glBindTexture(GL_TEXTURE_2D, dskin);
  2053. gluQuadricTexture(frogfingerSright, true);
  2054. gluQuadricNormals(frogfingerSright, GL_SMOOTH);
  2055. gluSphere(frogfingerSright, 0.075, 100, 100);
  2056. gluDeleteQuadric(frogfingerSright);
  2057.  
  2058. glPopMatrix();
  2059.  
  2060. glPushMatrix();
  2061.  
  2062. GLUquadricObj * frogfinger2right;
  2063. frogfinger2right = gluNewQuadric();
  2064. glTranslated(0.31, 2.75, 0.9);
  2065. glRotated(20, 0, 1, 0);
  2066. glBindTexture(GL_TEXTURE_2D, dskin);
  2067. gluQuadricTexture(frogfinger2right, true);
  2068. gluQuadricNormals(frogfinger2right, GL_SMOOTH);
  2069. gluCylinder(frogfinger2right, 0.075, 0.075, 0.2, 10, 10);
  2070. gluDeleteQuadric(frogfinger2right);
  2071.  
  2072. glPopMatrix();
  2073.  
  2074. glPushMatrix();
  2075.  
  2076. GLUquadricObj * frogfinger2Sright;
  2077. frogfinger2Sright = gluNewQuadric();
  2078. glTranslated(0.435, 2.75, 1.1);
  2079. glBindTexture(GL_TEXTURE_2D, dskin);
  2080. gluQuadricTexture(frogfinger2Sright, true);
  2081. gluQuadricNormals(frogfinger2Sright, GL_SMOOTH);
  2082. gluSphere(frogfinger2Sright, 0.075, 100, 100);
  2083. gluDeleteQuadric(frogfinger2Sright);
  2084.  
  2085. glPopMatrix();
  2086.  
  2087. glPopMatrix();
  2088.  
  2089. glPushMatrix();
  2090. glRotated(legrotation, 1, 0, 0); //rotation inside matrix of legs
  2091.  
  2092. glPushMatrix();
  2093.  
  2094. GLUquadricObj * frognewleg;
  2095. frognewleg = gluNewQuadric();
  2096. glTranslated(0.8, 3.3, -0.2);
  2097. glRotated(-20, 1, 0, 0);
  2098. glBindTexture(GL_TEXTURE_2D, flegs);
  2099. gluQuadricTexture(frognewleg, true);
  2100. gluQuadricNormals(frognewleg, GL_SMOOTH);
  2101. gluCylinder(frognewleg, 0.125, 0.125, 1, 10, 10);
  2102. gluDeleteQuadric(frognewleg);
  2103.  
  2104. glPopMatrix();
  2105.  
  2106. glPushMatrix();
  2107.  
  2108. GLUquadricObj * frognewleg2;
  2109. frognewleg2 = gluNewQuadric();
  2110. glTranslated(0.8, 3.3, -0.2);
  2111. glBindTexture(GL_TEXTURE_2D, flegs);
  2112. gluQuadricTexture(frognewleg2, true);
  2113. gluQuadricNormals(frognewleg2, GL_SMOOTH);
  2114. gluSphere(frognewleg2, 0.125, 100, 100);
  2115. gluDeleteQuadric(frognewleg2);
  2116.  
  2117. glPopMatrix();
  2118.  
  2119. glPushMatrix();
  2120.  
  2121. GLUquadricObj * frognewleg4;
  2122. frognewleg4 = gluNewQuadric();
  2123. glTranslated(0.8, 3.6, 0.7);
  2124. glBindTexture(GL_TEXTURE_2D, flegs);
  2125. gluQuadricTexture(frognewleg4, true);
  2126. gluQuadricNormals(frognewleg4, GL_SMOOTH);
  2127. gluSphere(frognewleg4, 0.125, 100, 100);
  2128. gluDeleteQuadric(frognewleg4);
  2129.  
  2130. glPopMatrix();
  2131.  
  2132.  
  2133. glPushMatrix();
  2134.  
  2135. GLUquadricObj * frognewleg3;
  2136. frognewleg3 = gluNewQuadric();
  2137. glTranslated(0.8, 3.3, -0.2);
  2138. glRotated(20, 1, 0, 0);
  2139. glBindTexture(GL_TEXTURE_2D, flegs);
  2140. gluQuadricTexture(frognewleg3, true);
  2141. gluQuadricNormals(frognewleg3, GL_SMOOTH);
  2142. gluCylinder(frognewleg3, 0.125, 0.125, 1, 10, 10);
  2143. gluDeleteQuadric(frognewleg3);
  2144.  
  2145. glPopMatrix();
  2146.  
  2147. glPushMatrix();
  2148.  
  2149. GLUquadricObj * frognewleg5;
  2150. frognewleg5 = gluNewQuadric();
  2151. glTranslated(0.8, 3, 0.7);
  2152. glBindTexture(GL_TEXTURE_2D, flegs);
  2153. gluQuadricTexture(frognewleg5, true);
  2154. gluQuadricNormals(frognewleg5, GL_SMOOTH);
  2155. gluSphere(frognewleg5, 0.125, 100, 100);
  2156. gluDeleteQuadric(frognewleg5);
  2157.  
  2158. glPopMatrix();
  2159.  
  2160. glPushMatrix();
  2161.  
  2162. GLUquadricObj * frognewtoe;
  2163. frognewtoe = gluNewQuadric();
  2164. glTranslated(0.8, 3, 0.7);
  2165. glRotated(20, 0, 1, 0);
  2166. glBindTexture(GL_TEXTURE_2D, flegs);
  2167. gluQuadricTexture(frognewtoe, true);
  2168. gluQuadricNormals(frognewtoe, GL_SMOOTH);
  2169. gluCylinder(frognewtoe, 0.075, 0.075, 0.4, 10, 10);
  2170. gluDeleteQuadric(frognewtoe);
  2171.  
  2172. glPopMatrix();
  2173.  
  2174. glPushMatrix();
  2175.  
  2176. GLUquadricObj * frognewtoes;
  2177. frognewtoes = gluNewQuadric();
  2178. glTranslated(0.7, 3, 1);
  2179. glRotated(20, 0, 1, 0);
  2180. glBindTexture(GL_TEXTURE_2D, dskin);
  2181. gluQuadricTexture(frognewtoes, true);
  2182. gluQuadricNormals(frognewtoes, GL_SMOOTH);
  2183. gluSphere(frognewtoes, 0.075, 100, 100);
  2184. gluDeleteQuadric(frognewtoes);
  2185.  
  2186. glPopMatrix();
  2187.  
  2188. glPushMatrix();
  2189.  
  2190. GLUquadricObj * frognewtoe2;
  2191. frognewtoe2 = gluNewQuadric();
  2192. glTranslated(0.8, 3, 0.7);
  2193. glRotated(-20, 0, 1, 0);
  2194. glBindTexture(GL_TEXTURE_2D, dskin);
  2195. gluQuadricTexture(frognewtoe2, true);
  2196. gluQuadricNormals(frognewtoe2, GL_SMOOTH);
  2197. gluCylinder(frognewtoe2, 0.075, 0.075, 0.4, 10, 10);
  2198. gluDeleteQuadric(frognewtoe2);
  2199.  
  2200. glPopMatrix();
  2201.  
  2202. glPushMatrix();
  2203.  
  2204. GLUquadricObj * frognewtoe2s;
  2205. frognewtoe2s = gluNewQuadric();
  2206. glTranslated(0.94, 3, 1.09);
  2207. glBindTexture(GL_TEXTURE_2D, dskin);
  2208. gluQuadricTexture(frognewtoe2s, true);
  2209. gluQuadricNormals(frognewtoe2s, GL_SMOOTH);
  2210. gluSphere(frognewtoe2s, 0.075, 100, 100);
  2211. gluDeleteQuadric(frognewtoe2s);
  2212.  
  2213. glPopMatrix();
  2214.  
  2215. // ------------------------
  2216.  
  2217. glPushMatrix();
  2218.  
  2219. GLUquadricObj * frognewlegleft;
  2220. frognewlegleft = gluNewQuadric();
  2221. glTranslated(-0.7, 3.3, -0.2);
  2222. glRotated(-20, 1, 0, 0);
  2223. glBindTexture(GL_TEXTURE_2D, flegs);
  2224. gluQuadricTexture(frognewlegleft, true);
  2225. gluQuadricNormals(frognewlegleft, GL_SMOOTH);
  2226. gluCylinder(frognewlegleft, 0.125, 0.125, 1, 10, 10);
  2227. gluDeleteQuadric(frognewlegleft);
  2228.  
  2229. glPopMatrix();
  2230.  
  2231. glPushMatrix();
  2232.  
  2233. GLUquadricObj * frognewleg2left;
  2234. frognewleg2left = gluNewQuadric();
  2235. glTranslated(-0.7, 3.3, -0.2);
  2236. glBindTexture(GL_TEXTURE_2D, flegs);
  2237. gluQuadricTexture(frognewleg2left, true);
  2238. gluQuadricNormals(frognewleg2left, GL_SMOOTH);
  2239. gluSphere(frognewleg2left, 0.125, 100, 100);
  2240. gluDeleteQuadric(frognewleg2left);
  2241.  
  2242. glPopMatrix();
  2243.  
  2244. glPushMatrix();
  2245.  
  2246. GLUquadricObj * frognewleg4left;
  2247. frognewleg4left = gluNewQuadric();
  2248. glTranslated(-0.7, 3.6, 0.7);
  2249. glBindTexture(GL_TEXTURE_2D, flegs);
  2250. gluQuadricTexture(frognewleg4left, true);
  2251. gluQuadricNormals(frognewleg4left, GL_SMOOTH);
  2252. gluSphere(frognewleg4left, 0.125, 100, 100);
  2253. gluDeleteQuadric(frognewleg4left);
  2254.  
  2255. glPopMatrix();
  2256.  
  2257.  
  2258. glPushMatrix();
  2259.  
  2260. GLUquadricObj * frognewleg3left;
  2261. frognewleg3left = gluNewQuadric();
  2262. glTranslated(-0.7, 3.3, -0.2);
  2263. glRotated(20, 1, 0, 0);
  2264. glBindTexture(GL_TEXTURE_2D, flegs);
  2265. gluQuadricTexture(frognewleg3left, true);
  2266. gluQuadricNormals(frognewleg3left, GL_SMOOTH);
  2267. gluCylinder(frognewleg3, 0.125, 0.125, 1, 10, 10);
  2268. gluDeleteQuadric(frognewleg3left);
  2269.  
  2270. glPopMatrix();
  2271.  
  2272. glPushMatrix();
  2273.  
  2274. GLUquadricObj * frognewleg5left;
  2275. frognewleg5left = gluNewQuadric();
  2276. glTranslated(-0.7, 3, 0.7);
  2277. glBindTexture(GL_TEXTURE_2D, flegs);
  2278. gluQuadricTexture(frognewleg5left, true);
  2279. gluQuadricNormals(frognewleg5left, GL_SMOOTH);
  2280. gluSphere(frognewleg5left, 0.125, 100, 100);
  2281. gluDeleteQuadric(frognewleg5left);
  2282.  
  2283. glPopMatrix();
  2284.  
  2285. glPushMatrix();
  2286.  
  2287. GLUquadricObj * frognewtoeleft;
  2288. frognewtoeleft = gluNewQuadric();
  2289. glTranslated(-0.7, 3, 0.7);
  2290. glRotated(20, 0, 1, 0);
  2291. glBindTexture(GL_TEXTURE_2D, dskin);
  2292. gluQuadricTexture(frognewtoeleft, true);
  2293. gluQuadricNormals(frognewtoeleft, GL_SMOOTH);
  2294. gluCylinder(frognewtoeleft, 0.075, 0.075, 0.4, 10, 10);
  2295. gluDeleteQuadric(frognewtoeleft);
  2296.  
  2297. glPopMatrix();
  2298.  
  2299. glPushMatrix();
  2300.  
  2301. GLUquadricObj * frognewtoesleft;
  2302. frognewtoesleft = gluNewQuadric();
  2303. glTranslated(-0.6, 3, 1);
  2304. glRotated(20, 0, 1, 0);
  2305. glBindTexture(GL_TEXTURE_2D, dskin);
  2306. gluQuadricTexture(frognewtoesleft, true);
  2307. gluQuadricNormals(frognewtoesleft, GL_SMOOTH);
  2308. gluSphere(frognewtoesleft, 0.075, 100, 100);
  2309. gluDeleteQuadric(frognewtoesleft);
  2310.  
  2311. glPopMatrix();
  2312.  
  2313. glPushMatrix();
  2314.  
  2315. GLUquadricObj * frognewtoe2left;
  2316. frognewtoe2left = gluNewQuadric();
  2317. glTranslated(-0.7, 3, 0.7);
  2318. glRotated(-20, 0, 1, 0);
  2319. glBindTexture(GL_TEXTURE_2D, dskin);
  2320. gluQuadricTexture(frognewtoe2left, true);
  2321. gluQuadricNormals(frognewtoe2left, GL_SMOOTH);
  2322. gluCylinder(frognewtoe2left, 0.075, 0.075, 0.4, 10, 10);
  2323. gluDeleteQuadric(frognewtoe2left);
  2324.  
  2325. glPopMatrix();
  2326.  
  2327. glPushMatrix();
  2328.  
  2329. GLUquadricObj * frognewtoe2sleft;
  2330. frognewtoe2sleft = gluNewQuadric();
  2331. glTranslated(-0.84, 3, 1.09);
  2332. glBindTexture(GL_TEXTURE_2D, dskin);
  2333. gluQuadricTexture(frognewtoe2sleft, true);
  2334. gluQuadricNormals(frognewtoe2sleft, GL_SMOOTH);
  2335. gluSphere(frognewtoe2sleft, 0.075, 100, 100);
  2336. gluDeleteQuadric(frognewtoe2sleft);
  2337.  
  2338. glPopMatrix();
  2339.  
  2340. glPopMatrix();
  2341.  
  2342. glPopMatrix();
  2343.  
  2344.  
  2345. }
  2346. void modifyModel(int direction, int model){
  2347.  
  2348.  
  2349. switch (model){
  2350. case 0:direction == 1 ? glRotated(90, 0, 1, 0) : glRotated(-90, 0, 1, 0); break;
  2351. case 1:direction == 1 ? glRotated(90, 0, 1, 0) : glRotated(-90, 0, 1, 0); break;
  2352. case 2:direction == -1 ? glRotated(-180, 0, 1, 0) : true; break;
  2353. case 3:direction == 1 ? glRotated(90, 0, 1, 0) : glRotated(-90, 0, 1, 0); glScaled(2, 2, 2); break;
  2354. case 4:direction == 1 ? glRotated(-90, 0, 1, 0) : glRotated(90, 0, 1, 0); glScaled(30, 30, 30); break;
  2355. case 5:direction == 1 ? glRotated(180, 0, 1, 0) : true; glTranslated(0, 1, 0); glScaled(1, 1, 1.5); break;
  2356. case 6:direction == 1 ? glRotated(90, 0, 1, 0) : glRotated(-90, 0, 1, 0); glTranslated(0, 1, 0); glScaled(70, 70, 70); break;
  2357. case 7:direction == 1 ? glRotated(90, 0, 1, 0) : glRotated(-90, 0, 1, 0); glScaled(0.02, 0.02, 0.02); break;
  2358. case 8:direction == 1 ? glRotated(90, 0, 1, 0) : glRotated(-90, 0, 1, 0); glScaled(70, 70, 70); break;
  2359. case 9:direction == 1 ? glRotated(180, 0, 1, 0) : true; glScaled(11, 11, 11); break;
  2360. case 10:direction == 1 ? glRotated(-90, 0, 1, 0) : glRotated(90, 0, 1, 0); glScaled(0.3, 0.3, 0.3); glTranslated(0, 1.7, 0); break;
  2361. }
  2362.  
  2363. }
  2364.  
  2365. void drawACar(int carPos){
  2366. glPushMatrix();
  2367. glTranslated(allCars[level-1][carPos].x, allCars[level-1][carPos].y, allCars[level-1][carPos].z);
  2368. modifyModel(allCars[level - 1][carPos].direction, allCars[level - 1][carPos].modelNumber);
  2369.  
  2370. glScaled(0.02, 0.03, 0.02);
  2371. models[allCars[level-1][carPos].modelNumber].Draw();
  2372. glPopMatrix();
  2373. }
  2374. /*
  2375. void drawCollisionCube(){
  2376. glPushMatrix();
  2377. glBegin(GL_QUADS);
  2378. // top
  2379. glColor3f(1.0f, 0.0f, 0.0f);
  2380. glNormal3f(0.0f, 1.0f, 0.0f);
  2381. glVertex3f(tempx + 2, tempy + 2, tempz + 1.5);
  2382. glVertex3f(tempx + 2, tempy + 2, tempz - 1.5);
  2383. glVertex3f(tempx - 2, tempy + 2, tempz - 1.5);
  2384. glVertex3f(tempx - 2, tempy + 2, tempz + 1.5);
  2385.  
  2386. glEnd();
  2387. glPopMatrix();
  2388. }*/
  2389. void myDisplay(void)
  2390. {
  2391. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2392. setupLights();
  2393.  
  2394. setupCamera();
  2395. //traceCam();
  2396. // Draw Ground
  2397.  
  2398. renderGround();
  2399.  
  2400.  
  2401. //sky box
  2402. skyBox();
  2403. //Level 1
  2404. glPushMatrix();
  2405.  
  2406. if (won){
  2407. glPushMatrix();
  2408. gluLookAt(
  2409. camera.eye.x, camera.eye.y, camera.eye.z,
  2410. camera.center.x, camera.center.y, camera.center.z,
  2411. camera.up.x, camera.up.y, camera.up.z
  2412. );
  2413. glutPostRedisplay();
  2414. char string[32];
  2415. sprintf(string, "You Win");
  2416. print(camera.eye.x, camera.eye.y, camera.eye.z, string);
  2417. glPopMatrix();
  2418. glutSwapBuffers();
  2419. return;
  2420.  
  2421. }
  2422. switch (level){
  2423. case 1:level1(); break;
  2424. case 2:level2(); break;
  2425. case 3:level3(); break;
  2426. case 4:level4(); break;
  2427. case 5:level5(); break;
  2428. }
  2429. glPopMatrix();
  2430.  
  2431. for (int i = 0; i < (sizeof(allCars[level-1]) / sizeof(*allCars[level-1])); i++){
  2432. if (allCars[level-1][i].drawable&&allCars[level-1][i].direction!=0)
  2433. drawACar(i);
  2434. }
  2435.  
  2436. awesomeFrog();
  2437.  
  2438.  
  2439. char string[32];
  2440. sprintf(string, "%d", currentLevelScore + totalScore);
  2441. if (perspective==3)
  2442. print(frogx+1, frogy + 4, frogz, string);
  2443. else
  2444. print(frogx-2, frogy+3, frogz-3, string);
  2445.  
  2446.  
  2447. glutSwapBuffers();
  2448. }
  2449.  
  2450.  
  2451.  
  2452. //=======================================================================
  2453. // Mouse Function
  2454. //=======================================================================
  2455.  
  2456.  
  2457. void devKeyboard(unsigned char key, int x, int y) {
  2458. float d = 1;
  2459.  
  2460. switch (key) {
  2461. case 'w':
  2462. camera.moveY(d);
  2463. break;
  2464. case 's':
  2465. camera.moveY(-d);
  2466. break;
  2467. case 'a':
  2468. camera.moveX(d);
  2469. break;
  2470. case 'd':
  2471. camera.moveX(-d);
  2472. break;
  2473. case 'q':
  2474. camera.moveZ(d);
  2475. break;
  2476. case 'e':
  2477. camera.moveZ(-d);
  2478. break;
  2479. case 'l': //TODO: move Later to normal keyboard function
  2480. legrotation--;
  2481. armrotation++;
  2482. break;
  2483. case 'k':
  2484. legrotation++;
  2485. armrotation--;
  2486. break;
  2487. case 'u':
  2488. movement++;
  2489. break;
  2490. /*case 'd':
  2491. movement--;
  2492. break;*/
  2493. case GLUT_KEY_ESCAPE:
  2494. exit(EXIT_SUCCESS);
  2495. }
  2496.  
  2497. glutPostRedisplay();
  2498. }
  2499. void devSpecial(int key, int x, int y) {
  2500. float a = 1.0;
  2501.  
  2502. switch (key) {
  2503. case GLUT_KEY_UP:
  2504. camera.rotateX(a);
  2505. break;
  2506. case GLUT_KEY_DOWN:
  2507. camera.rotateX(-a);
  2508. break;
  2509. case GLUT_KEY_LEFT:
  2510. camera.rotateY(a);
  2511. break;
  2512. case GLUT_KEY_RIGHT:
  2513. camera.rotateY(-a);
  2514. break;
  2515. }
  2516.  
  2517. glutPostRedisplay();
  2518. }
  2519. void mainSpecial(int key, int x, int y){
  2520.  
  2521. }
  2522.  
  2523.  
  2524. //=======================================================================
  2525. // Reshape Function
  2526. //=======================================================================
  2527. //TODO : REMOVE
  2528. void myReshape(int w, int h)
  2529. {
  2530. if (h == 0) {
  2531. h = 1;
  2532. }
  2533.  
  2534. WIDTH = w;
  2535. HEIGHT = h;
  2536.  
  2537. // set the drawable region of the window
  2538. glViewport(0, 0, w, h);
  2539.  
  2540. // set up the projection matrix
  2541. glMatrixMode(GL_PROJECTION);
  2542. glLoadIdentity();
  2543. gluPerspective(fovy, (GLdouble)WIDTH / (GLdouble)HEIGHT, zNear, zFar);
  2544.  
  2545. // go back to modelview matrix so we can move the objects about
  2546. glMatrixMode(GL_MODELVIEW);
  2547. glLoadIdentity();
  2548. //TODO:Reshape camera ?
  2549. }
  2550.  
  2551. //=======================================================================
  2552. // Assets Loading Function
  2553. //=======================================================================
  2554. void LoadAssets()
  2555. {
  2556.  
  2557.  
  2558. // Loading texture files
  2559.  
  2560. loadBMP(&tex, "Textures/sky4-jpg.bmp", true);
  2561. loadBMP(&ground, "Textures/ground.bmp", true);
  2562. loadBMP(&fskin, "Textures/fskin2.bmp", true);
  2563. loadBMP(&fneck, "Textures/frogneck.bmp", true);
  2564. loadBMP(&feyes, "Textures/frogeyes2.bmp", true);
  2565. loadBMP(&feet, "Textures/fryfoot.bmp", true);
  2566. loadBMP(&dskin, "Textures/docskin.bmp", true);
  2567. loadBMP(&flegs, "Textures/froglegs.bmp", true);
  2568.  
  2569. //Cars
  2570. model_car.Load("Models/car/Car nissan skyline gtr (bnr34) N080615.3ds");
  2571. model_truck.Load("Models/truck/Car PickUpTruck EU N260614.3ds");
  2572. model_police.Load("Models/police/NYPD.3ds");
  2573. model_batcar.Load("Models/batcar/batcar.3ds");
  2574. model_tank.Load("Models/tank/fv510.3ds");
  2575. model_gallardo.Load("Models/lamborghini/gallardo.3ds");
  2576. model_ferrari.Load("Models/ferrari/california.3ds");
  2577. model_bike.Load("Models/bike/bike.3DS");
  2578. model_Camaro.Load("Models/camaro/CAMARO.3ds");
  2579. model_trophy.Load("Models/trophy/trophy.3ds");
  2580. model_aston.Load("Models/aston/martin.3ds");
  2581.  
  2582.  
  2583.  
  2584.  
  2585. model_bushes.Load("Models/Bushes/Bushes.3ds");
  2586. model_tree2.Load("Models/tree2/mangrovetree.3ds");
  2587. model_tree.Load("Models/tree/Tree1.3ds");
  2588. models[0] = model_car;
  2589. models[1] = model_truck;
  2590. models[2] = model_police;
  2591. models[3] = model_batcar;
  2592. models[4] = model_tank;
  2593. models[5] = model_gallardo;
  2594. models[6] = model_ferrari;
  2595. models[7] = model_bike;
  2596. models[8] = model_Camaro;
  2597. models[9] = model_trophy;
  2598. models[10] = model_aston;
  2599.  
  2600. }
  2601.  
  2602. void initalizeCar(int level,int car ,float x , float y ,float z ,int direction,int timeToLive,int timeToStart,int modelNumber,float speed){
  2603. allCars[level-1][car].y = y == -1 ? 1.3: y;
  2604. allCars[level-1][car].z = z;
  2605. allCars[level-1][car].timeToLive = timeToLive == -1 ? 100 : timeToLive;
  2606. allCars[level-1][car].x = x;
  2607. allCars[level-1][car].direction = direction;
  2608. allCars[level-1][car].timeToStart = timeToStart;
  2609. allCars[level-1][car].modelNumber = modelNumber;
  2610. allCars[level - 1][car].speed = speed;
  2611.  
  2612. }
  2613. void AllCarsDisplay(){
  2614. initalizeCar(2, 0, 20, -1, -5, -1, -1, 10, 0, 1); // Car moving to right starting at Z = -3
  2615. initalizeCar(2, 1, 20, -1, -10, -1, -1, 10, 1, 1); // Car moving to right starting at Z = -5
  2616. initalizeCar(2, 2, 20, -1, -15, -1, -1, 10, 2, 1); // Car moving to right starting at Z = -5
  2617. initalizeCar(2, 3, 20, -1, -20, -1, -1, 10, 3, 1); // Car moving to right starting at Z = -5
  2618. initalizeCar(2, 4, 20, -1, -25, -1, -1, 10, 4, 1); // Car moving to right starting at Z = -5
  2619.  
  2620. initalizeCar(2, 5, 20, -1, -30, -1, -1, 10, 5, 1); // Car moving to right starting at Z = -5
  2621.  
  2622. initalizeCar(2, 6, 20, -1, -35, -1, -1, 10, 6, 1); // Car moving to right starting at Z = -5
  2623. initalizeCar(2, 7, 20, -1, -40, -1, -1, 10, 7, 1); // Car moving to right starting at Z = -5
  2624. initalizeCar(2, 8, 20, -1, -45, -1, -1, 10, 8, 1); // Car moving to right starting at Z = -5
  2625. initalizeCar(2, 9, 20, -1, -50, -1, -1, 10, 9, 1); // Car moving to right starting at Z = -5
  2626. initalizeCar(2, 10, 20, -1, -55, -1, -1, 10, 10, 1); // Car moving to right starting at Z = -5
  2627. }
  2628.  
  2629. void initalizeLevel1Cars(){
  2630. // Level , Car , X , Y , Z , Direction , TTL , TTS,Model,Speed
  2631. initalizeCar(1,0, -20, -1, -3, 1, 80, 10, 0,2); // Car moving to right starting at Z = -3
  2632. initalizeCar(1,1, 20, -1, -8, -1, 70, 20, 0,2); // Car moving to the left starting at Z = -8
  2633. initalizeCar(1,2, 20, -1, -22, -1, 70, 40, 1,2); // Car moving to the left starting at Z = -22
  2634. initalizeCar(1,3, -20, -1, -30, 1, 70, 50, 1,2); // Car moving to the right starting at Z = -30
  2635. initalizeCar(1,4, 20, -1, -39, -1, 50, 60, 1,2); // Car moving to the left starting at Z = -39
  2636.  
  2637. }
  2638. void initalizeLevel2Cars(){
  2639. initalizeCar(2, 0, -20, -1, 8, 1, 15, 5, 2, 4); // Car moving to right starting at Z = 8
  2640.  
  2641. initalizeCar(2, 1, -20, -1, -1, 1, 23, 10, 3, 3); // Car moving to the left starting at Z = -1
  2642. initalizeCar(2, 2, 20, -1, -8, -1, 23, 5, 3, 3); // Car moving to the left starting at Z = -8
  2643.  
  2644. initalizeCar(2, 3, -20, -1, -22, 1, 30, 10, 2, 2); // Car moving to the left starting at Z = -1
  2645. initalizeCar(2, 4, -20, -1, -27, 1, 30, 5, 3, 2); // Car moving to the left starting at Z = -8
  2646. initalizeCar(2, 5, 20, -1, -32.5, -1, 30, 10, 2, 2); // Car moving to the left starting at Z = -1
  2647. initalizeCar(2, 6, 20, -1, -38, -1, 30, 5, 3, 2); // Car moving to the left starting at Z = -8
  2648.  
  2649. }
  2650. void initalizeLevel3Cars(){
  2651. initalizeCar(3, 0, -20, -1, 12, 1, 15, 5, 4, 4);
  2652. initalizeCar(3, 1, 20, -1, 8, -1, 34, 5, 5, 2);
  2653. initalizeCar(3, 2, 20, -1, 3, -1, 36, 1, 4, 2.5);
  2654.  
  2655.  
  2656. initalizeCar(3, 3, 20, -1, -8, -1, 17, 3, 5, 3);
  2657. initalizeCar(3, 5,- 20, -1, -12, 1, 36, 1, 4, 2);
  2658.  
  2659. initalizeCar(3, 6, 20, -1, -27, -1, 30, 8, 4, 2.5);
  2660. initalizeCar(3, 7, -20, -1, -32, 1, 40, 1, 5, 2);
  2661. initalizeCar(3, 8, 20, -1, -37, -1, 30, 3, 4, 2.5);
  2662. initalizeCar(3, 9, 20, -1, -42, -1, 37, 2, 4, 2);
  2663. initalizeCar(3, 9, -20, -1, -47, 1, 37, 2, 5, 2);
  2664.  
  2665. }
  2666. void initalizeLevel4Cars(){
  2667.  
  2668. }
  2669. void initalizeLevel5Cars(){
  2670.  
  2671. }
  2672. void initalizeAllCars(){
  2673. initalizeLevel1Cars();
  2674. initalizeLevel2Cars();
  2675. initalizeLevel3Cars();
  2676. initalizeLevel4Cars();
  2677. initalizeLevel5Cars();
  2678.  
  2679.  
  2680. }
  2681. void initalizeFrog(){
  2682.  
  2683. frogx = 1;
  2684. frogy = 0;
  2685. frogz = 20;
  2686. frogbezier1[0] = 10; //calling random bezier curve values at start mostly helpful to set y = 0
  2687. frogbezier1[1] = 0;
  2688. frogbezier2[0] = 9;
  2689. frogbezier2[1] = 4;
  2690. frogbezier3[0] = 7;
  2691. frogbezier3[1] = 4;
  2692. frogbezier4[0] = 5;
  2693. frogbezier4[1] = 0;
  2694.  
  2695. }
  2696. void initalizeLevels(){
  2697. finalZs[0]=-45;
  2698. finalZs[1]=-41;
  2699. finalZs[2]=-52;
  2700. finalZs[3]=-77;
  2701. finalZs[4]=-106;
  2702.  
  2703. }
  2704. //=======================================================================
  2705. // Main Function
  2706. //=======================================================================
  2707. void main(int argc, char** argv)
  2708. {
  2709. glutInit(&argc, argv);
  2710.  
  2711. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  2712.  
  2713. glutInitWindowSize(WIDTH, HEIGHT);
  2714.  
  2715. glutInitWindowPosition(100, 150);
  2716.  
  2717. glutCreateWindow(title);
  2718. initalizeAllCars();
  2719. initalizeFrog();
  2720. initalizeLevels();
  2721. glutDisplayFunc(myDisplay);
  2722. legrotation = 0;
  2723.  
  2724. frogflagjump = false; // set to false so we can enter first movement command
  2725. if (developerMode){
  2726. glutKeyboardFunc(devKeyboard);
  2727. glutSpecialFunc(devSpecial);
  2728. }
  2729. else{
  2730.  
  2731. glutKeyboardFunc(FrogKeyboard);
  2732. glutSpecialFunc(mainSpecial);
  2733.  
  2734. }
  2735. Sleep(1000);
  2736.  
  2737. glutReshapeFunc(myReshape);
  2738. glutTimerFunc(0, timeF, 0);
  2739. glutIdleFunc(Anim);
  2740. myInit();
  2741.  
  2742. LoadAssets();
  2743.  
  2744.  
  2745. glEnable(GL_DEPTH_TEST);
  2746. glEnable(GL_LIGHTING);
  2747. glEnable(GL_LIGHT0);
  2748. glEnable(GL_NORMALIZE);
  2749. glEnable(GL_COLOR_MATERIAL);
  2750.  
  2751. glShadeModel(GL_SMOOTH);
  2752.  
  2753. glutMainLoop();
  2754. }
  2755.  
  2756.  
  2757. void frogbezier(int value){
  2758. if (frogtimer < 1){
  2759.  
  2760.  
  2761. int *f3 = bezier(frogtimer, frogbezier1, frogbezier2, frogbezier3, frogbezier4); //call bezier
  2762. frogcoord[0] = f3[0];
  2763. frogz = frogcoord[0]; //set z to bezier values because we are moving forwards
  2764. frogcoord[1] = f3[1];
  2765. frogy = frogcoord[1];
  2766. frogtimer = frogtimer + 0.095;//initial 0.035
  2767. if (hit){
  2768. initalizeFrog();
  2769. }
  2770. glutPostRedisplay();
  2771.  
  2772. }
  2773. else{
  2774. frogtimer = 0; //restart leg and arm timer
  2775. frogflagjump = false; // allow another movement command to be made
  2776. }
  2777. if (frogflagjump){
  2778. glutTimerFunc(0.0001, frogbezier, 0); //stop calling timer after we finish the jump
  2779. }
  2780. }
  2781. void frogbezierlft(int value){
  2782. if (frogtimer < 1){
  2783.  
  2784.  
  2785. int *f3 = bezier(frogtimer, frogbezier1, frogbezier2, frogbezier3, frogbezier4);
  2786. frogcoord[0] = f3[0];
  2787. frogx = frogcoord[0]; // set x to bezier values because we are moving left
  2788. frogcoord[1] = f3[1];
  2789. frogy = frogcoord[1];
  2790. frogtimer = frogtimer + 0.095;
  2791. if (hit){
  2792. initalizeFrog();
  2793. }
  2794. glutPostRedisplay();
  2795.  
  2796. }
  2797. else{
  2798. frogtimer = 0; //restart leg and arm timer
  2799. frogflagjump = false; // allow another movement command to be made
  2800. }
  2801. if (frogflagjump){
  2802. glutTimerFunc(0.0001, frogbezierlft, 0); //stop calling timer after we finish the jump
  2803. }
  2804. }
  2805. void frogbezierrght(int value){
  2806. if (frogtimer < 1){
  2807.  
  2808.  
  2809. int *f3 = bezier(frogtimer, frogbezier1, frogbezier2, frogbezier3, frogbezier4);
  2810. frogcoord[0] = f3[0];
  2811. frogx = frogcoord[0]; // set x to bezier values because we are moving right
  2812. frogcoord[1] = f3[1];
  2813. frogy = frogcoord[1];
  2814. frogtimer = frogtimer + 0.095;
  2815. if (hit){
  2816. initalizeFrog();
  2817. }
  2818. glutPostRedisplay();
  2819.  
  2820. }
  2821. else{
  2822. frogtimer = 0; //restart leg and arm timer
  2823. frogflagjump = false; // allow another movement command to be made
  2824. }
  2825. if (frogflagjump){
  2826. glutTimerFunc(0.0001, frogbezierrght, 0); //stop calling timer after we finish the jump
  2827. }
  2828. }
  2829. void frogbezierbck(int value){
  2830. if (frogtimer < 1){
  2831.  
  2832.  
  2833. int *f3 = bezier(frogtimer, frogbezier1, frogbezier2, frogbezier3, frogbezier4);
  2834. frogcoord[0] = f3[0];
  2835. frogz = frogcoord[0]; //set z to bezier values because we are moving backwards
  2836. frogcoord[1] = f3[1];
  2837. frogy = frogcoord[1];
  2838. frogtimer = frogtimer + 0.095;
  2839. if (hit){
  2840. initalizeFrog();
  2841. }
  2842. glutPostRedisplay();
  2843.  
  2844. }
  2845. else{
  2846. frogtimer = 0; //restart leg and arm timer
  2847. frogflagjump = false; // allow another movement command to be made
  2848. }
  2849. if (frogflagjump){
  2850. glutTimerFunc(0.0001, frogbezierbck, 0); //stop calling timer after we finish the jump
  2851. }
  2852. }
  2853. void frogTimer(int value) { // movement of arms and legs
  2854.  
  2855.  
  2856. if (enablefrog){
  2857. if (flaglegA == true && legrotation > -19){ //can be adjusted on how much we want to go back and forth
  2858. legrotation = legrotation - 1;
  2859. armrotation = armrotation - 0.5;
  2860. }
  2861. else if (legrotation != 0){
  2862. flaglegA = false;
  2863. legrotation = legrotation + 1;
  2864. armrotation = armrotation + 0.5;
  2865. }
  2866. glutPostRedisplay();
  2867. glutTimerFunc(30, frogTimer, 0);
  2868. glutPostRedisplay();
  2869. }
  2870.  
  2871. }
  2872. int* bezier(float t, int* p0, int* p1, int* p2, int* p3) // bezier curve from bezier.cpp
  2873. {
  2874. int res[2];
  2875. res[0] = pow((1 - t), 3)*p0[0] + 3 * t*pow((1 - t), 2)*p1[0] + 3 * pow(t, 2)*(1 - t)*p2[0] + pow(t, 3)*p3[0];
  2876. res[1] = pow((1 - t), 3)*p0[1] + 3 * t*pow((1 - t), 2)*p1[1] + 3 * pow(t, 2)*(1 - t)*p2[1] + pow(t, 3)*p3[1];
  2877. return res;
  2878. }
  2879. void FrogKeyboard(unsigned char button, int x, int y)
  2880. {
  2881. float d = 2;
  2882. if (won){
  2883. glutPostRedisplay();
  2884. return;
  2885. }
  2886. switch (button)
  2887. {
  2888. case 'w':
  2889. if (frogflagjump == false){ // if we are not in another movement state enter
  2890. enablefrog = true; //enter leg and arm movement
  2891. hit = false;
  2892. legrotation = 0;
  2893. armrotation = 0;
  2894. flaglegA = true;
  2895. frogflagjump = true;
  2896. frogbezier1[0] = frogz; //start from z
  2897. frogbezier2[0] = frogz - 1;
  2898. frogbezier3[0] = frogz - 3;
  2899. frogbezier4[0] = frogz - 5; //end at z-5
  2900. glutTimerFunc(1, frogTimer, 0);
  2901. glutTimerFunc(1, frogbezier, 0);
  2902. camera.look(frogx, frogy, frogz,perspective,xValue);
  2903. PlaySound("jump34.wav", NULL, SND_ASYNC | SND_FILENAME);
  2904. }
  2905.  
  2906. break;
  2907. case 's':
  2908. if (frogflagjump == false&&frogz<=21){ // if we are not in another movement state enter
  2909. enablefrog = true; //enter leg and arm movement
  2910. hit = false;
  2911. legrotation = 0;
  2912. armrotation = 0;
  2913. flaglegA = true;
  2914. frogflagjump = true;
  2915. frogbezier1[0] = frogz; //start from z
  2916. frogbezier2[0] = frogz + 5;
  2917. frogbezier3[0] = frogz + 5;
  2918. frogbezier4[0] = frogz + 5; //end at z+5
  2919. glutTimerFunc(1, frogTimer, 0);
  2920. glutTimerFunc(1, frogbezierbck, 0);
  2921. camera.look(frogx, frogy, frogz,perspective,xValue);
  2922. PlaySound("jump34.wav", NULL, SND_ASYNC | SND_FILENAME);
  2923. }
  2924.  
  2925. break;
  2926. case 'a':
  2927. if (frogflagjump == false&&frogx >= -18){ // if we are not in another movement state enter
  2928. enablefrog = true; //enter leg and arm movement
  2929. hit = false;
  2930. legrotation = 0;
  2931. armrotation = 0;
  2932. flaglegA = true;
  2933. frogflagjump = true;
  2934. frogbezier1[0] = frogx; //start from x
  2935. frogbezier2[0] = frogx - 1;
  2936. frogbezier3[0] = frogx - 3;
  2937. frogbezier4[0] = frogx - 5; //end at x-5
  2938. glutTimerFunc(1, frogbezierlft, 0);
  2939. glutTimerFunc(1, frogTimer, 0);
  2940. PlaySound("jump34.wav", NULL, SND_ASYNC | SND_FILENAME);
  2941.  
  2942. }
  2943.  
  2944. break;
  2945. case 'd':
  2946. if (frogflagjump == false && frogx <= 18){ // if we are not in another movement state enter
  2947. enablefrog = true; //enter leg and arm movement
  2948. hit = false;
  2949. legrotation = 0;
  2950. armrotation = 0;
  2951. flaglegA = true;
  2952. frogflagjump = true;
  2953. frogbezier1[0] = frogx; //start from x
  2954. frogbezier2[0] = frogx + 1;
  2955. frogbezier3[0] = frogx + 3;
  2956. frogbezier4[0] = frogx + 5; //end at x+5
  2957. glutTimerFunc(1, frogbezierrght, 0);
  2958. glutTimerFunc(1, frogTimer, 0);
  2959. PlaySound("jump34.wav", NULL, SND_ASYNC | SND_FILENAME);
  2960.  
  2961. }
  2962. break;
  2963. case 'f':
  2964. perspective = perspective == 3 ? 1 : 3; break;
  2965. case'q':
  2966. xValue -= 35; break;
  2967. case'e':
  2968. xValue += 35; break;
  2969. case 27:
  2970. exit(0);
  2971. break;
  2972. default:
  2973. break;
  2974. }
  2975.  
  2976.  
  2977. glutPostRedisplay();
  2978. }
  2979. void Anim(){
  2980. //rotating light equations
  2981. alpha += 0.03;// adjust the speed from here
  2982. angle = 90 * cos(alpha) + 7.5;
  2983. angle1 = 90 * sin(alpha) + 7.5;
  2984. glutPostRedisplay();
  2985. }
  2986. void drawBush(double x, double z){
  2987. glPushMatrix();
  2988. glTranslated(x, 1.3, z);
  2989. glScaled(0.3, 0.3, 0.3);
  2990. model_bushes.Draw();
  2991. glPopMatrix();
  2992. }
  2993. void print(int x, int y, int z, char *string)
  2994. {
  2995. glColor3f(1, 0, 0);
  2996. //set the position of the text in the window using the x and y coordinates
  2997. glRasterPos3f(x, y,z);
  2998. //get the length of the string to display
  2999. int len = (int)strlen(string);
  3000.  
  3001. //loop to display character by character
  3002. for (int i = 0; i < len; i++)
  3003. {
  3004. glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, string[i]);
  3005. }
  3006. glColor3f(1, 1, 1);
  3007. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement