Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- VARP(showgrid,0,1,1);
- VARP(showselborders,0,1,1);
- ...
- void cursorupdate() // called every frame from hud
- {
- flrceil = ((int)(camera1->pitch>=0))*2;
- int cyaw = ((int) camera1->yaw) % 180;
- editaxis = editmode ? (fabs(camera1->pitch) > 65 ? 13 : (cyaw < 45 || cyaw > 135 ? 12 : 11)) : 0;
- volatile float x = worldpos.x; // volatile needed to prevent msvc7 optimizer bug?
- volatile float y = worldpos.y;
- volatile float z = worldpos.z;
- cx = (int)x;
- cy = (int)y;
- if (OUTBORD(cx, cy)) return;
- sqr *s = S(cx,cy);
- if(fabs(sheight(s,s,z)-z)>1) // selected wall
- {
- x += x>camera1->o.x ? 0.5f : -0.5f; // find right wall cube
- y += y>camera1->o.y ? 0.5f : -0.5f;
- cx = (int)x;
- cy = (int)y;
- if(OUTBORD(cx, cy)) return;
- }
- if(dragging) { makesel(false); };
- const int GRIDSIZE = 5;
- const float GRIDW = 0.5f;
- const float GRID8 = 2.0f;
- const float GRIDS = 2.0f;
- const int GRIDM = 0x7;
- // render editing grid
- if(showgrid)
- {
- for(int ix = cx-GRIDSIZE; ix<=cx+GRIDSIZE; ix++) for(int iy = cy-GRIDSIZE; iy<=cy+GRIDSIZE; iy++)
- {
- if(OUTBORD(ix, iy)) continue;
- sqr *s = S(ix,iy);
- //if(SOLID(s)) continue;
- float h1 = sheight(s, s, z);
- float h2 = sheight(s, SWS(s,1,0,sfactor), z);
- float h3 = sheight(s, SWS(s,1,1,sfactor), z);
- float h4 = sheight(s, SWS(s,0,1,sfactor), z);
- /** The color of "inside" a cube? **/
- if(s->tag)
- linestyle(GRIDW, 0xFF, 0x40, 0x40); //Editing values sometimes has no effect
- /** Heightfield Style **/
- else if(s->type==FHF || s->type==CHF)
- linestyle(GRIDW, 0x80, 0xFF, 0x80); //green
- /** Solid cube style **/
- else if(SOLID(s))
- linestyle(GRID8, 0xAB, 0x40, 0xFE); //purple
- /** Normal cube style **/
- else linestyle(GRIDW, 0x80, 0x80, 0x80); //grey
- /** Actually drawing the grid **/
- block b = { ix, iy, 1, 1 }; //set destination coordinates to draw to
- box(b, h1, h2, h3, h4); //draw
- /** The repeating 8 x 8 grid **/
- /* Choosing color **/
- linestyle(GRID8, 0x40, 0x40, 0xFF); //blue
- /* Drawing lines on this grid */
- if(!(ix&GRIDM))
- line(ix, iy, h1, ix, iy+1, h4);
- if(!((ix+1)&GRIDM))
- line(ix+1, iy, h2, ix+1, iy+1, h3);
- if(!(iy&GRIDM))
- line(ix, iy, h1, ix+1, iy, h2);
- if(!((iy+1)&GRIDM))
- line(ix, iy+1, h4, ix+1, iy+1, h3);
- }
- /** Draw white square around cube cursor is over **/
- float ih = sheight(s, s, z);
- linestyle(GRIDS, 0xFF, 0xFF, 0xFF); //white
- block b = { cx, cy, 1, 1 };
- 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));
- /** And the orienting little square in the corner **/
- linestyle(GRIDS, 0xFF, 0x00, 0x00); //red
- dot(cx, cy, ih);
- ch = (int)ih; //updates height of selection box (the red boxes) to the correct height
- }
- /** Draw selection(s) **/
- if(selset() && showselborders)
- {
- /* Choosing color */
- linestyle(GRIDS, 0xFF, 0x40, 0x40); //red
- /* Drawing */
- loopv(sels) //for each selection
- box(sels[i], (float)sels[i].h, (float)sels[i].h, (float)sels[i].h, (float)sels[i].h);
- }
- glLineWidth(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement