Author Topic: how to get viewport coords of the element in the draggablepanel  (Read 4017 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Hi!  Great package, i am using it for a while.
I have a problem and i am not sure how to resolve it.

I have draggable panel with grid inside that holds gui elements dynamically added.
i need to draw 2d line (with another package) and i need to get viewport coords of
elements inside the draggable panel (under grid).

i am not sure what i need to be using (position,localPosition, WorldToViewport or WorldToScreen and what camera for converting coords)

here is what i have tried:

  1.                
  2.                 GameObject s = NGUITools.AddChild(grid,microlabel2DPrefab);
  3.                
  4.                 s.GetComponentInChildren<UILabel>().text = ml.GetName();
  5.                 grid.GetComponent<UIGrid>().Reposition();
  6.                
  7.                 Vector3 mPos = GameCam.WorldToViewportPoint(ml.GetStartPos());
  8.                 Vector3 gPos = GameCam.WorldToViewportPoint(s.transform.position);
  9.                 VectorLine l = VectorLine.SetLine(lineColor,gPos,ml.GetStartPos());
  10.  

ml is just GameObject with Transform
and s i prefab that is put in grid inside draggable label

i want to draw 2d line from element in the grid to projected 2d position of gameobject.

any help appreciated!

[EDIT]: just to add that gui element is visible only by Ngui cam and object in the scene with gamecam. the usual setup.
« Last Edit: April 14, 2013, 06:54:22 AM by pretender »

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: how to get viewport coords of the element in the draggablepanel
« Reply #1 on: April 14, 2013, 02:22:37 PM »
tried to work it out but i just can't get to project position of element from draggable panel to viewport and then use it to render a line from that position to another projected position in viewport coords.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: how to get viewport coords of the element in the draggablepanel
« Reply #2 on: April 15, 2013, 09:47:45 AM »
Uh... so you take the label's world space position... convert it to viewport point... so far so good. Then you do something called VectorLine.SetLine which I don't know anything about. Are you sure it expects viewport coordinates? Are you sure it doesn't expect screen coordinates instead?