Advertisement
Guest User

cursorupdate() - modified by Felix-The-Ghost

a guest
Mar 17th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. ...
  2.  
  3. VARP(showgrid,0,1,1);
  4. VARP(showselborders,0,1,1);
  5.  
  6. ...
  7.  
  8. void cursorupdate()                                     // called every frame from hud
  9. {
  10.     flrceil = ((int)(camera1->pitch>=0))*2;
  11.     int cyaw = ((int) camera1->yaw) % 180;
  12.     editaxis = editmode ? (fabs(camera1->pitch) > 65 ? 13 : (cyaw < 45 || cyaw > 135 ? 12 : 11)) : 0;
  13.  
  14.     volatile float x = worldpos.x;                      // volatile needed to prevent msvc7 optimizer bug?
  15.     volatile float y = worldpos.y;
  16.     volatile float z = worldpos.z;
  17.  
  18.     cx = (int)x;
  19.     cy = (int)y;
  20.  
  21.     if (OUTBORD(cx, cy)) return;
  22.     sqr *s = S(cx,cy);
  23.  
  24.     if(fabs(sheight(s,s,z)-z)>1)                        // selected wall
  25.     {
  26.         x += x>camera1->o.x ? 0.5f : -0.5f;             // find right wall cube
  27.         y += y>camera1->o.y ? 0.5f : -0.5f;
  28.  
  29.         cx = (int)x;
  30.         cy = (int)y;
  31.  
  32.         if(OUTBORD(cx, cy)) return;
  33.     }
  34.  
  35.     if(dragging) { makesel(false); };
  36.  
  37.     const int GRIDSIZE = 5;
  38.     const float GRIDW = 0.5f;
  39.     const float GRID8 = 2.0f;
  40.     const float GRIDS = 2.0f;
  41.     const int GRIDM = 0x7;
  42.  
  43.     // render editing grid
  44.  
  45.     if(showgrid)
  46.     {
  47.         for(int ix = cx-GRIDSIZE; ix<=cx+GRIDSIZE; ix++) for(int iy = cy-GRIDSIZE; iy<=cy+GRIDSIZE; iy++)
  48.         {
  49.  
  50.             if(OUTBORD(ix, iy)) continue;
  51.             sqr *s = S(ix,iy);
  52.  
  53.             //if(SOLID(s)) continue;
  54.  
  55.             float h1 = sheight(s, s, z);
  56.             float h2 = sheight(s, SWS(s,1,0,sfactor), z);
  57.             float h3 = sheight(s, SWS(s,1,1,sfactor), z);
  58.             float h4 = sheight(s, SWS(s,0,1,sfactor), z);
  59.  
  60.             /** The color of "inside" a cube? **/
  61.  
  62.             if(s->tag)
  63.             linestyle(GRIDW, 0xFF, 0x40, 0x40); //Editing values sometimes has no effect
  64.  
  65.             /** Heightfield Style **/
  66.  
  67.             else if(s->type==FHF || s->type==CHF)
  68.             linestyle(GRIDW, 0x80, 0xFF, 0x80); //green
  69.  
  70.             /** Solid cube style **/
  71.  
  72.             else if(SOLID(s))
  73.             linestyle(GRID8, 0xAB, 0x40, 0xFE); //purple
  74.  
  75.             /** Normal cube style **/
  76.  
  77.             else linestyle(GRIDW, 0x80, 0x80, 0x80); //grey
  78.  
  79.             /** Actually drawing the grid **/
  80.  
  81.             block b = { ix, iy, 1, 1 }; //set destination coordinates to draw to
  82.             box(b, h1, h2, h3, h4); //draw
  83.  
  84.             /** The repeating 8 x 8 grid **/
  85.  
  86.             /* Choosing color **/
  87.  
  88.             linestyle(GRID8, 0x40, 0x40, 0xFF); //blue
  89.  
  90.             /* Drawing lines on this grid */
  91.  
  92.             if(!(ix&GRIDM))
  93.             line(ix, iy, h1, ix, iy+1, h4);
  94.  
  95.             if(!((ix+1)&GRIDM))
  96.             line(ix+1, iy, h2, ix+1, iy+1, h3);
  97.  
  98.             if(!(iy&GRIDM))
  99.             line(ix, iy, h1, ix+1, iy, h2);
  100.  
  101.             if(!((iy+1)&GRIDM))
  102.             line(ix, iy+1, h4, ix+1, iy+1, h3);
  103.         }
  104.  
  105.         /** Draw white square around cube cursor is over **/
  106.  
  107.         float ih = sheight(s, s, z);
  108.  
  109.         linestyle(GRIDS, 0xFF, 0xFF, 0xFF); //white
  110.  
  111.         block b = { cx, cy, 1, 1 };
  112.         box(b, ih, sheight(s, SWS(s,1,0,sfactor), z), sheight(s, SWS(s,1,1,sfactor), z), sheight(s, SWS(s,0,1,sfactor), z));
  113.  
  114.         /** And the orienting little square in the corner **/
  115.  
  116.         linestyle(GRIDS, 0xFF, 0x00, 0x00); //red
  117.         dot(cx, cy, ih);
  118.  
  119.         ch = (int)ih; //updates height of selection box (the red boxes) to the correct height
  120.     }
  121.  
  122.     /** Draw selection(s) **/
  123.  
  124.     if(selset() && showselborders)
  125.     {
  126.         /* Choosing color */
  127.  
  128.         linestyle(GRIDS, 0xFF, 0x40, 0x40); //red
  129.  
  130.         /* Drawing */
  131.  
  132.         loopv(sels) //for each selection
  133.         box(sels[i], (float)sels[i].h, (float)sels[i].h, (float)sels[i].h, (float)sels[i].h);
  134.     }
  135.  
  136.     glLineWidth(1);
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement