17 Mar 12, 04:49AM
(This post was last modified: 17 Mar 12, 04:50AM by Ronald_Reagan.)
Something I just quickly made for my AC_Platformer vid (probably not the "proper" way to do it). Replace cursorupdate() with this:
You probably want to change it to:
VAR(drawgrid,0,1,1);
[SELECT ALL] Code:
VAR(drawgrid,0,0,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);
sqr *s = S(0,0);
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();
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 (drawgrid==1)
{
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);
if(s->tag) linestyle(GRIDW, 0xFF, 0x40, 0x40);
else if(s->type==FHF || s->type==CHF) linestyle(GRIDW, 0x80, 0xFF, 0x80);
else linestyle(GRIDW, 0x80, 0x80, 0x80);
block b = { ix, iy, 1, 1 };
box(b, h1, h2, h3, h4);
linestyle(GRID8, 0x40, 0x40, 0xFF);
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);
}
}
if(selset)
{
linestyle(GRIDS, 0xFF, 0x40, 0x40);
box(sel, (float)selh, (float)selh, (float)selh, (float)selh);
}
if(!SOLID(s))
{
float ih = sheight(s, s, z);
linestyle(GRIDS, 0xFF, 0xFF, 0xFF);
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));
linestyle(GRIDS, 0xFF, 0x00, 0x00);
dot(cx, cy, ih);
ch = (int)ih;
}
glLineWidth(1);
}
You probably want to change it to:
VAR(drawgrid,0,1,1);