chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 20 Dec 2015 12:18 PM |
| ey tony whats the math to convert 3d position to a 2d screenspace position? |
|
|
| Report Abuse |
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 20 Dec 2015 12:20 PM |
| 3D uses X,Y,Z and 2D uses X,Y so just don't include the Z value? Is this what you are asking? |
|
|
| Report Abuse |
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 20 Dec 2015 12:30 PM |
oh god no.
I need to map a 3d space to a 2d screen space |
|
|
| Report Abuse |
|
EgoMoose
|
  |
| Joined: 04 Feb 2009 |
| Total Posts: 2896 |
|
|
| 20 Dec 2015 12:41 PM |
Like this?
http://wiki.roblox.com/index.php?title=API:Class/Camera/WorldToScreenPoint |
|
|
| Report Abuse |
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 20 Dec 2015 01:24 PM |
local camera = workspace.CurrentCamera; do while not camera do repeat until workspace.Changed:wait() == "CurrentCamera" and workspace.CurrentCamera; camera = workspace.CurrentCamera; end workspace.Changed:connect(function(property) if property == "CurrentCamera" then camera = workspace.CurrentCamera or camera; end end) repeat until( camera.ViewportSize.magnitude > 0 or camera.Changed:wait() == "ViewportSize" ) end
function worldToScreen(vectorIn) local f = camera.ViewportSize.Y/(2*math.tan(math.rad(camera.FieldOfView*.5))) local toscreen = CFrame.new( 0, 0, 0, f, 0, 0, 0, f, 0, 0, 0, 1 )*camera.CoordinateFrame:inverse()*vectorIn*Vector3.new(1, -1, -1) local vectorOut = Vector3.new(toscreen.X, toscreen.Y, toscreen.Z^2)/toscreen.Z + Vector3.new(camera.ViewportSize.X/2,camera.ViewportSize.Y/2) return vectorOut, vectorOut.Z > 0 end print(worldToScreen(workspace.BasePlate.Position)) print(camera:WorldToScreenPoint(workspace.BasePlate.Position))
|
|
|
| Report Abuse |
|