LCOV - code coverage report
Current view: top level - src - TerrainEditor.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 10 0
Test Date: 2026-04-03 02:26:39 Functions: 0.0 % 5 0

            Line data    Source code
       1              : #include "TerrainEditor.h"
       2              : 
       3              : #if EDIT
       4              : //------------------------------------------------------------------------------
       5              : void TerrainEditor::displayPalette(Engine *engine) {
       6              :   int count = 0;
       7              :   int xpos, zpos, type;
       8              :   float height, red, green, blue;
       9              :   char m[120];
      10              :   glClear(GL_COLOR_BUFFER_BIT);
      11              : 
      12              :   engine->getTerrainInfo(xpos, zpos, height, type, red, green, blue);
      13              : 
      14              :   glClear(GL_COLOR_BUFFER_BIT);
      15              :   glColor3f(0.0f, 0.0f, 0.0f);
      16              : 
      17              :   sprintf(m, "Red Attribute: %f", red);
      18              :   printString(m, 10, 10);
      19              : 
      20              :   glColor3f(0.0f, 0.0f, 0.0f);
      21              : 
      22              :   sprintf(m, "Green Attribute: %f", green);
      23              :   printString(m, 10, 50);
      24              : 
      25              :   glColor3f(0.0f, 0.0f, 0.0f);
      26              : 
      27              :   sprintf(m, "Blue Attribute: %f", blue);
      28              :   printString(m, 10, 90);
      29              : 
      30              :   sprintf(m, "Vertex: %d, %d height: %f", xpos, zpos, height);
      31              :   printString(m, 10, 130);
      32              : 
      33              :   sprintf(m, "Type: %d", type);
      34              :   printString(m, 10, 285);
      35              : 
      36              :   glBegin(GL_QUADS);
      37              :   // RED //
      38              :   glColor3f(0.0f, 0.0f, 0.0f);
      39              :   glVertex2f(0.0f,15.0f);
      40              : 
      41              :   glColor3f(0.0f, 0.0f, 0.0f);
      42              :   glVertex2f(0.0f,35.0f);
      43              : 
      44              :   glColor3f(1.0f, 0.0f, 0.0f);
      45              :   glVertex2f(127.0f,35.0f);
      46              : 
      47              :   glColor3f(1.0f, 0.0f, 0.0f);
      48              :   glVertex2f(127.0f,15.0f);
      49              : 
      50              :   glColor3f(1.0f, 0.0f, 0.0f);
      51              :   glVertex2f(127.0f,15.0f);
      52              : 
      53              :   glColor3f(1.0f, 0.0f, 0.0f);
      54              :   glVertex2f(127.0f,35.0f);
      55              : 
      56              :   glColor3f(1.0f, 1.0f, 1.0f);
      57              :   glVertex2f(255.0f,35.0f);
      58              : 
      59              :   glColor3f(1.0f, 1.0f, 1.0f);
      60              :   glVertex2f(255.0f,15.0f);
      61              : 
      62              :   // GREEN //
      63              :   glColor3f(0.0f, 0.0f, 0.0f);
      64              :   glVertex2f(0.0f,55.0f);
      65              : 
      66              :   glColor3f(0.0f, 0.0f, 0.0f);
      67              :   glVertex2f(0.0f,75.0f);
      68              : 
      69              :   glColor3f(0.0f, 1.0f, 0.0f);
      70              :   glVertex2f(127.0f,75.0f);
      71              : 
      72              :   glColor3f(0.0f, 1.0f, 0.0f);
      73              :   glVertex2f(127.0f,55.0f);
      74              : 
      75              :   glColor3f(0.0f, 1.0f, 0.0f);
      76              :   glVertex2f(127.0f,55.0f);
      77              : 
      78              :   glColor3f(0.0f, 1.0f, 0.0f);
      79              :   glVertex2f(127.0f,75.0f);
      80              : 
      81              :   glColor3f(1.0f, 1.0f, 1.0f);
      82              :   glVertex2f(255.0f,75.0f);
      83              : 
      84              :   glColor3f(1.0f, 1.0f, 1.0f);
      85              :   glVertex2f(255.0f,55.0f);
      86              : 
      87              :   // BLUE //
      88              :   glColor3f(0.0f, 0.0f, 0.0f);
      89              :   glVertex2f(0.0f,95.0f);
      90              : 
      91              :   glColor3f(0.0f, 0.0f, 0.0f);
      92              :   glVertex2f(0.0f,115.0f);
      93              : 
      94              :   glColor3f(0.0f, 0.0f, 1.0f);
      95              :   glVertex2f(127.0f,115.0f);
      96              : 
      97              :   glColor3f(0.0f, 0.0f, 1.0f);
      98              :   glVertex2f(127.0f,95.0f);
      99              : 
     100              :   glColor3f(0.0f, 0.0f, 1.0f);
     101              :   glVertex2f(127.0f,95.0f);
     102              : 
     103              :   glColor3f(0.0f, 0.0f, 1.0f);
     104              :   glVertex2f(127.0f,115.0f);
     105              : 
     106              :   glColor3f(1.0f, 1.0f, 1.0f);
     107              :   glVertex2f(255.0f,115.0f);
     108              : 
     109              :   glColor3f(1.0f, 1.0f, 1.0f);
     110              :   glVertex2f(255.0f,95.0f);
     111              :   glEnd();
     112              : 
     113              :   glBegin(GL_LINES);
     114              :   glColor3f(1.0f, 0.0f, 0.0f);
     115              :   glVertex2f(0.0f, 135.0f);
     116              :   glVertex2f(240.0f, 135.0f);
     117              : 
     118              :   for (int i = 0; i <= 240; i += 24) {
     119              :     glVertex2f(i, 135.0f);
     120              :     glVertex2f(i, 155.0f);
     121              :   }
     122              : 
     123              :   for (int i = 0; i < 240; i += 12) {
     124              :     glVertex2f(i, 135.0f);
     125              :     glVertex2f(i, 145.0f);
     126              :   }
     127              : 
     128              :   glColor3f(1.0f, 0.0f, 0.0f);
     129              :   glVertex2f(0.0f, 185.0f);
     130              :   glVertex2f(240.0f, 185.0f);
     131              : 
     132              :   for (int i = 0; i <= 240; i += 24) {
     133              :     glVertex2f(i, 185.0f);
     134              :     glVertex2f(i, 205.0f);
     135              :   }
     136              : 
     137              :   for (int i = 0; i < 240; i += 12) {
     138              :     glVertex2f(i, 185.0f);
     139              :     glVertex2f(i, 195.0f);
     140              :   }
     141              : 
     142              :   glColor3f(1.0f, 0.0f, 0.0f);
     143              :   glVertex2f(0.0f, 235.0f);
     144              :   glVertex2f(240.0f, 235.0f);
     145              : 
     146              :   for (int i = 0; i <= 240; i += 24) {
     147              :     glVertex2f(i, 235.0f);
     148              :     glVertex2f(i, 255.0f);
     149              :   }
     150              : 
     151              :   for (int i = 0; i < 240; i += 12) {
     152              :     glVertex2f(i, 235.0f);
     153              :     glVertex2f(i, 245.0f);
     154              :   }
     155              :   glEnd();
     156              : 
     157              :   glBegin(GL_QUADS);
     158              :   glColor3f(1.0f, 0.0f, 0.0f);
     159              :   glVertex2f(0.0f,325.0f);
     160              :   glVertex2f(0.0f,345.0f);
     161              :   glVertex2f(27.0f,345.0f);
     162              :   glVertex2f(27.0f,325.0f);
     163              : 
     164              :   glColor3f(red, green, blue);
     165              :   glVertex2f(1.0f,326.0f);
     166              :   glVertex2f(1.0f,344.0f);
     167              :   glVertex2f(26.0f,344.0f);
     168              :   glVertex2f(26.0f,326.0f);
     169              :   glEnd();
     170              : 
     171              :   glColor3f(0.0f, 0.0f, 0.0f);
     172              :   sprintf(m, "00                           05                           10");
     173              :   printString(m, 0, 165);
     174              : 
     175              :   sprintf(m, "10                           15                           20");
     176              :   printString(m, 0, 215);
     177              : 
     178              :   sprintf(m, "20                           25                           30");
     179              :   printString(m, 0, 265);
     180              : 
     181              :   sprintf(m, "land(0)    water(1)");
     182              :   printString(m, 0, 305);
     183              : }
     184              : 
     185              : //------------------------------------------------------------------------------
     186              : void TerrainEditor::initPalette() {
     187              :   glClearColor(1.0, 1.0, 1.0, 0.0);
     188              : 
     189              :   glMatrixMode(GL_PROJECTION);
     190              :   glLoadIdentity();
     191              :   gluOrtho2D(0.0, 255, 350, 0.0);
     192              : 
     193              :   glMatrixMode(GL_MODELVIEW);
     194              : }
     195              : 
     196              : //------------------------------------------------------------------------------
     197              : void TerrainEditor::reshapePalette(const int &w, const int &h) {
     198              :   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
     199              :   glMatrixMode(GL_PROJECTION);
     200              :   glLoadIdentity();
     201              :   gluOrtho2D(0.0f, 255.0f, 350.0f, 0.0f);
     202              : }
     203              : 
     204              : //------------------------------------------------------------------------------
     205              : void TerrainEditor::mousePalette(Engine *engine, const int &btn, const int &state, const int &x, const int &y) {
     206              :   int skip = 0;
     207              :   int xpos, zpos, type;
     208              :   float height, red, green, blue;
     209              : 
     210              :   if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
     211              :     engine->getTerrainInfo(xpos, zpos, height, type, red, green, blue);
     212              : 
     213              :     if (y >=15 && y <= 35) {
     214              :       // modify red
     215              :       red = (float)(x / 259.0f);
     216              :     }
     217              :     else if (y >=55 && y <= 75) {
     218              :       // modify green
     219              :       green = (float)(x / 259.0f);
     220              :     }
     221              :     else if (y >=95 && y <= 115) {
     222              :       // modify blue
     223              :       blue = (float)(x / 259.0f);
     224              :     }
     225              : 
     226              :     else if (y >=135 && y <= 155) {
     227              :       // modify height
     228              :       height = (float)(x / 244.0f * 10.0f);
     229              :     }
     230              :     else if (y >=185 && y <= 205) {
     231              :       // modify height
     232              :       height = (float)(x / 244.0f * 10.0f) + 10.0f;
     233              :     }
     234              :     else if (y >=235 && y <= 255) {
     235              :       // modify height
     236              :       height = (float)(x / 244.0f * 10.0f) + 20.0f;
     237              :     }
     238              : 
     239              :     else if (y >=185 && y <= 205) {
     240              :       // modify height
     241              :       height = (float)(x / 244.0f * 10.0f) + 10.0f;
     242              :     }
     243              :     else if (y >=295 && y <= 320 && x >= 0 && x <= 30) {
     244              :       type = 0;
     245              :     }
     246              : 
     247              :     else if (y >=295 && y <= 320 && x >= 70 && x <= 120) {
     248              :       type = 1;
     249              :     }
     250              :     else {
     251              :       skip = 1;
     252              :     }
     253              : 
     254              :     if (skip == 0)
     255              :       engine->updateTerrain(xpos, zpos, height, type, red, green, blue);
     256              :   }
     257              :   if(btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {}
     258              : 
     259              :   glutPostRedisplay();
     260              : }
     261              : #else
     262              : //------------------------------------------------------------------------------
     263            0 : void TerrainEditor::displayPalette(Engine *engine) {}
     264              : 
     265              : //------------------------------------------------------------------------------
     266            0 : void TerrainEditor::initPalette(void) {}
     267              : 
     268              : //------------------------------------------------------------------------------
     269            0 : void TerrainEditor::reshapePalette(const int &w, const int &h) {}
     270              : 
     271              : //------------------------------------------------------------------------------
     272            0 : void TerrainEditor::mousePalette(Engine *engine, const int &btn, const int &state, const int &x, const int &y) {}
     273              : #endif
     274              : 
     275              : //------------------------------------------------------------------------------
     276            0 : void TerrainEditor::printString(char* str, const float &x, const float &y) {
     277            0 :   glRasterPos2d(x, y);
     278              : 
     279            0 :   int i = 0;
     280            0 :   while (str[i] != '\0')
     281            0 :     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i++]);
     282            0 : }
        

Generated by: LCOV version 2.4-0