🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to Zoom in a Selected Rectangle ?

Started by
0 comments, last by Roger Samaan 23 years, 12 months ago
Hello to all, I have wireframe scene (glOrtho projection, WINNT). A rubberbanding rectangle is drawn in WINDOW Coordinates by the user. How do I zoom that rectangle (from window coord) to fill the view port? Thank you frustrated, Roger S
Advertisement
Hi,

I don''t really know how to explain so i''ll give you an example.

    // Position and size of the viewport in window coords#define VIEWPORT_X 10#define VIEWPORT_Y 10#define VIEWPORT_WIDTH 400#define VIEWPORT_HEIGHT 300// Somewhere during initialization  glOrtho (g_x1, g_x2, g_y2, g_y1);  ...// g_x1,... are doubles// The function that zooms in the rectangle// Warning: There is no error checking to see if//          the rectangle is entirely within the //          viewportvoid ZoomRectangle (int top, int left, int bottom, int right){  double x1, x2, y1, y2;  // Normalize the coordinate between 0.0 and 1.0  x1 = (double)(left - VIEWPORT_X) / (double)VIEWPORT_WIDTH;  x2 = (double)(right - VIEWPORT_X) / (double)VIEWPORT_WIDTH;  y1 = (double)(top - VIEWPORT_Y) / (double)VIEWPORT_HEIGHT;  y2 = (double)(bottom - VIEWPORT_Y) / (double)VIEWPORT_HEIGHT;  // Convert the coordinates to virtual space  x1 = x1 * (g_x2 - g_x1) + g_x1;  x2 = x2 * (g_x2 - g_x1) + g_x1;  y1 = y1 * (g_y2 - g_y1) + g_y1;  y2 = y2 * (g_y2 - g_y1) + g_y1;  // Set the global virtual coordinates  g_x1 = x1;  g_x2 = x2;  g_y1 = y1;  g_y2 = y2;  // Apply the new rectangle  glOrtho (g_x1, g_x2, g_y2, g_y1);  // You need to redraw the screen after this}    


I havent tried to compile it but at least you''ll have the basis.. I hope so . If you want more explanation, email me or reply to this thread. Sorry, my english may not be too good

Aldenar

This topic is closed to new replies.

Advertisement