x


converting from world to screen space? what is wrong?

hi, i am trying to convert two points that are used to render a line from space to screen points like this:

  Label.pStartScreen=cam.WorldToScreenPoint(Label.startPoint);
  Label.pEndScreen=cam.WorldToScreenPoint(Label.endPoint);

then i tried to render them like this:

  line.SetPosition(0,Label.pStartScreen); 
  line.SetPosition(1, Label.pEndScreen); 

but nothing happens

if i do this

  line.SetPosition(0,Label.startPoint); 
  line.SetPosition(1, Label.endPoint); 

the line renders correctly but these are initial 3d points, so the line is rendered in world space...

i am using this to render the line and rectangle that will hold the information about object line points to, so rectangle obviously needs screen space coords, these are converted the same way as above and the Rect appears where it should...so i dont know what is going on here? any ideas?

EDIT:

also i tried this:

GL.Begin(GL.LINES); 
  GL.Color(Color(1,1,1,1)); 
  GL.Vertex3(Label.pStartScreen.x,Label.pStartScreen.y,Label.pStartScreen.z);
  GL.Vertex3(Label.pEndScreen.x,Label.pEndScreen.y,Label.pEndScreen.z); 
 GL.End(); 

and it doesnt render anything when i use startPoint and endPoint, which are in world space, then it renders nice 3D line... i dont know what is happening, this should render in the screen space...

more ▼

asked Aug 26 '10 at 03:19 PM

pretender gravatar image

pretender
497 121 134 145

What is Label, what is "line", and what Rect are you referring to? It's really hard to tell from your description and your code what you are doing. To make your questions easier to understand and answer, you should present code that only uses Unity API classes whenever possible.

If you're using a LineRenderer, then yes, it renders in world space (with points defined either in world or objects space).

If you want your lines to appear in front of objects, you will have to render them closer to the camera, or using a second camera.

Aug 26 '10 at 04:00 PM Daniel Brauer
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x123
x106
x48

asked: Aug 26 '10 at 03:19 PM

Seen: 1767 times

Last Updated: Aug 26 '10 at 03:33 PM