xtal256 Posted August 7, 2007 Share Posted August 7, 2007 I am thinking of making a 2D game in OpenGL and i want to make an easy sort of 'lighting' by setting the vertex colour. I am going to have a number of polygons and when the player is in the polygon, they are coloured whatever colour the 'light' is. But regardless of the reason, i want to know an efficient way to find when 2 lines intersect as is illustrated in the image below. The player moves into the red 'light' (from a to b) but there are closer vertices that it doesn't go into. So it will have to search all vertices to find the one it wants. Is there a better way? Link to comment Share on other sites More sharing options...
K^2 Posted August 7, 2007 Share Posted August 7, 2007 You might as well check every edge. The line intersection algorithm is extremely easy. All you do is convert each edge into a parametric vector form, and then solve the system of two such equations to find a point of intersections between two lines. All you have to do after is check to make sure that the intersection point is within boundaries of each edge. Would this be easier to understand if I put it in code? Edit: I assume you mean in 2D. Odds of two edges intersecting in 3D are slim. In 3D you'll have to use triangle intersection algorithms which are slightly more advanced. Prior to filing a bug against any of my code, please consider this response to common concerns. Link to comment Share on other sites More sharing options...
xtal256 Posted August 8, 2007 Author Share Posted August 8, 2007 I am thinking of making a 2D game in OpenGL Yes, it is 2D. And no, it wouldn't be too hard to search every point, i only plan to have about 20-30 points anyway. You can put the code in if you like but i think i will probably just do it when i get around to it. thanx Link to comment Share on other sites More sharing options...
K^2 Posted August 8, 2007 Share Posted August 8, 2007 I'll let you give it a shot, then, and if you'll have any trouble, let me know. Prior to filing a bug against any of my code, please consider this response to common concerns. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now