Sign in to follow this  
EndIsForever

Dynamic grid for graph editor?

Recommended Posts

EndIsForever    122
Hi everyone, I am trying to recreate the graph editor from Maya in openGl for a little application I am developing. I have something similar working at the moment. There is just this little problem that I am sure there is a simple solution too and that I'm just to much of a dope to come up with / see it. Basically I have a system where by when the user zooms out of the grid when a certain value is reached the grid units increase so that the screen is prevented from filling up with hundreds of grid lines. Just like in maya... However the thing is I am just doing this with "else if" statements, like this: if(fabs(gLeft - gRight) > 10000) gUnits = 1000; else if(fabs(gLeft - gRight) > 5000) gUnits = 500; else if(fabs(gLeft - gRight) > 2000) gUnits = 200; else if(fabs(gLeft - gRight) > 1000) gUnits = 100; else if (fabs(gLeft - gRight) >500) gUnits = 50; else if (fabs(gLeft - gRight) >100) gUnits = 10; Where gLeft and gRight are the left and right attributes of the viewing volume and gUnits are the grid units. Which means once the upper level has been reached the gird no longer resizes itself. This doesn't happen in maya to my knowledge. Was just wondering if there is a nice way of making it infinitely resize-able? Also... on another topic if anyone knows of any good documentation / tutorials on implementing hermite curves in openGL I'd be grateful for any links. There is loads on beizers in openGL but nothing on hermite. Thanks for any suggestions, Dave.

Share this post


Link to post
Share on other sites
Zahlman    1682
Not tested:


gUnits = 1;

int distance = abs(gLeft - gRight);

while (distance >= 100) {
distance /= 10;
gUnits *= 10;
}

if (distance >= 50) { gUnits *= 5; }
else if (distance >= 20) { gUnits *= 2; }

Share this post


Link to post
Share on other sites
yahastu    154
I didn't really look at Zahlman's code but a very simple way to do this is as follows:

float dist = fabs(gLeft - gRight);
gUnits = pow(BASE, floor(log(dist)));

where BASE should be the base of the logarithm used.
ie, if you are using natural logarithm BASE = e, if using
log2 base = 2, log10 base = 10.

Note: you can calculate the log of any arbitrary base using the following simple formula from the log of any other base
logB(x) = logN(x)/logN(B)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this