Jump to content
  • Advertisement
Sign in to follow this  

Dynamic grid for graph editor?

This topic is 3888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!