View Full Version : 2d coordintaes along edges
11-25-2001, 05:21 PM
hi, can somebody help me out on these questions?
I am rendering an object using opengl. I understand that I can use glProject to get the actual 2d coordinates on the screen. But what if I only need the coordinates along the edges of the object(ie something like obtaining the outline of what I see on the screen)? How can I do this? I read somewhere about using scan lines to get the coordinates, is it feasible? Also, what is the precision of the coordinates? I read that it is up to 1 decimal place, is that true? Because I'll need to plot these values out on a x-y plot.
11-25-2001, 11:55 PM
Actually the corner points are enough for you to calculate all of the coordinates alogn the edges. In the good ol' times we had to do all for ourselves. No OpenGL, no DirectX, just a 320x200 display ;-)
Well, using scanlines for your calculations is correct. Basically you have to calculate you coordinates for each edge. So if you have a triangle (12,10), (17,14) and (8,24), you have to follow each edge and calculate the dx - how much the x value changes when your y value changes for 1.
Example for the first edge (12,10) - (17,14):
cout << "The x coordinate in row: " << y << " is: " << x << endl;
That's it. The precision depends on what type your "x" variable is. Make it a double and you get more precision than you'll ever need ;-)
If I wasn't clear try searching the web for "polygon drawing" or "line drawing algorithm"
11-26-2001, 04:29 PM
Thanks for your reply. I now have a better understanding of how scanlines work, and also a clearer picture of how things are. But I see that I'll need to find the coordinates of all the corner points before I can proceed. You see, I am rendering an irregular object, something like a rock made up of lots of polygons, and there are thousands of vertices to consider. Each time I rotate the rock, I get a different outline and thus a new edge to consider. How can I make sure that I only get the corner points(vertices) along the rock's edge(ie the outline edge of what I see on the screen, which can be made up of many polygons), and not the inetrior points? In the end, I am interested only in the 2D outline of the rock, and the corresponding 2D coordinates.
I'll take your advice and search for some line drawing algos.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.