View Full Version : drawing an adaptive 2D "grapheditor-like" grid
fasteez 06-01-2005, 04:53 PM id like to draw a 2D grid which only draws some of the real space grid, like all adaptive grid in maya graph editor or shake curve editor you know.
i really cant figure out how they do it :scream::sad::shrug:( except its function of x,y and "zoom" of the view and its a modulo thing... lol )
if someone has an idea.. iwould really help me
thx in advance
|
|
fasteez
06-02-2005, 08:35 PM
someone gave me this (from flipcode.com forum)
i post it here if someone is looking for
same kind of code
int layerspace = 8; // 8 lines form a mayor grid
int layermax = someconst; // How many layers you would like
float gridsize = 8; // Default grid size
float zoom = 1; // Zoom from your ortho camera
// See that more than minlinecount lines are onscreen
if (gridsize * zoom / screensize > minlinecount)
{
while (gridsize * zoom / screensize > minlinecount)
{
gridsize /= layerspace;
// Abort if gridsize < some epsilon
}
}
else
{
// See that less than maxlinecount lines are onscreen
while (gridsize * zoom / screensize < maxlinecount)
{
gridsize *= layerspace;
// Abort if gridsize > some delta
}
}
glBegin(GL_LINES);
// Render each grid layer
for (int layer = 0;
layer <= layermax;
++layer)
{
// Find on-grid position nearest to camera
int camgridx = (int)_fmodf(camposx, gridsize);
int camgridy = (int)_fmodf(camposy, gridsize);
// Build gridextents
int gridextents = screensize / gridsize + 1;
glColor3fv(layercols[layer]);
// Transform to camgrid lock position
glTranslatei(camgridx, camgridy, 0);
for (int i = -gridextents;
i <= gridextents;
++i)
{
// Render all grid lines not on nexthigher layer
if (layer == layermax ||
abs(i + camgridx) % layerspace != 0)
{
glLine2i(-gridextents, i);
glLine2i(gridextents, i);
}
if (layer == layermax ||
abs(i + camgridy) % layerspace != 0)
{
glLine2i(i, -gridextents);
glLine2i(i, gridextents);
}
}
// Move on to next grid size
gridsize *= layerspace;
}
glEnd();
CGTalk Moderation
06-02-2005, 08:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.