- Home /
how to render line between gui element and mouse position
i am trying to use OpenGL to render line between gui element and mouse position.
i am using this:
GL.Begin(GL.LINES);
GL.Color(Color(1,1,1,1));
//GL.Vertex3(10,10,1);
GL.Vertex3(Input.mousePosition.x,Screen.height-Input.mousePosition.y,1);
GL.Vertex3(100,100,1);
GL.End();
and it does nothing, if i use the commented line instead the line with mousposition i get the line but in 3d space, this isnt what i want and i guess that it has to be something with screen space... can somebody help me how to do it?
ok i managed to do it like this:
GL.Begin(GL.LINES);
GL.Color(Color(1,1,1,1));
//GL.Vertex(cam.ScreenToWorldPoint(Vector3(10,10,nearClip)));
GL.Vertex(cam.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,nearClip)));
GL.Vertex(cam.ScreenToWorldPoint(Vector3(100,Screen.height-100,nearClip)));
GL.End();
Glad to see you fixed it. I posted 2 links right after you typed that. :)
Answer by Peter G · Oct 23, 2010 at 06:28 PM
There are several scripts on the wiki that might help fix yours, or you can use their's.
http://www.unifycommunity.com/wiki/index.php?title=VectorLine
Requires Unity Pro
yes, the idea came from the script from your first link, ScreenToWorldPoint seems to does the trick, thanks!
And if you like the idea of drawing 2D lines in your GUI, please vote for my DrawLine feature request ... http://feedback.unity3d.com/forums/15792-unity/suggestions/1451375-gui-drawline