calculating the way

hi, i am coding a 2d game where i click on the screen and the unit moves there.
but how can i check if theres a nonwalkable area beetween the starting and ending point ? i mean, how can i check if the line from starting to ending point crosses the polygon which marks my non walkable terrain.
i read a lot about selection but glupickmatrix only lets me define a cube not a line
how can this be done

thanks

This is not an opengl question, this is an algorithm problem.
Google for pathfinding.

read it. its an opengl question. i dont want an algorythm that calculates a way around objects. i want to know how to check if an object is in my way , in opengl.

No its not, OpenGL does rendering only.

OpenGL has no knowledge about your “non walkable” areas.

Zbuffer already pointed you in the correct direction “pathfinding”. Another thing that comes to mind are simple line->triangle intersection tests.

But none of this has anything to do with OpenGL though. Just using OpenGL for rendering doesnt mean all your questions are OpenGL related.

i read a lot about selection but glupickmatrix only lets me define a cube not a line how can this be done
actually, selection could be used for collision detection, but would require a great deal of thought and effort to make it practical (if at all possible). having never attempted it myself, i can’t say for sure, but most anything is possible. if you find a way, please post your results! :slight_smile: