Welcome,
Guest
. Please
login
or
register
.
May 05, 2026, 11:36:30 AM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
How to convert the world position to a position on the screen?
« previous
next »
Print
Pages: [
1
]
Author
Topic: How to convert the world position to a position on the screen? (Read 11699 times)
Syberex
Guest
How to convert the world position to a position on the screen?
«
on:
May 03, 2012, 08:18:36 PM »
I'm working on gunsight. Did
Vector3 viewpos
=
gameCamera
.
WorldToViewportPoint
(
target
.
position
)
;
Vector3 screenpos
=
UICamera
.
currentCamera
.
ViewportToScreenPoint
(
viewpos
)
;
gunSightPanel
.
localPosition
=
new
Vector3
(
screenpos
.
x
, screenpos
.
y
,
0
)
;
... at 800*480 works, and by 480*320 is not correctly positioned sight.
(UIRoot is not automatic, manual height = 480. UICamera is ortho, size =1.)
How to fix this?
Sorry for bad english
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: How to convert the world position to a position on the screen?
«
Reply #1 on:
May 03, 2012, 08:23:33 PM »
UICamera.currentCamera only works in the event callbacks such as OnDrag, OnClick, etc. Outside of those callbacks you need to explicitly specify which camera to use.
Logged
Syberex
Guest
Re: How to convert the world position to a position on the screen?
«
Reply #2 on:
May 03, 2012, 08:45:12 PM »
This is not fixed bag
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: How to convert the world position to a position on the screen?
«
Reply #3 on:
May 03, 2012, 08:57:50 PM »
Since you mentioned your UIRoot is not automatic, you need to take your size into account:
float
multiplier
=
uiroot
.
manualHeight
/
Screen
.
height
;
gunSightPanel
.
localPosition
=
new
Vector3
(
screenpos
.
x
*
multiplier, screenpos
.
y
*
multiplier,
0
)
;
Logged
Syberex
Guest
Re: How to convert the world position to a position on the screen?
«
Reply #4 on:
May 04, 2012, 10:19:44 AM »
float
multiplier
=
(
float
)
uiroot
.
manualHeight
/
(
float
)
Screen
.
height
;
gunSightPanel
.
localPosition
=
new
Vector3
(
screenpos
.
x
*
multiplier, screenpos
.
y
*
multiplier,
0
)
;
Thanks ArenMook!
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
How to convert the world position to a position on the screen?