MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 05 Apr 2013 07:42 PM |
So I've typed something up here, which does some good. However, it only gets the part's screen position whenever I face the part's back left corner. Even then, it's only accurate if the part is at the center of my screen. It should be returning a value between -1 and 1.
I feel like I'm missing a factor in doing this. Anyone got an idea?
function WorldToScreen(v3, camera) local x,y,z,m11,m12,m13,m21,m22,m23,m31,m32,m33 = camera.CoordinateFrame:components() local lv = camera.CoordinateFrame.lookVector local hgf_w = -(lv:Dot(v3) + 1) return Vector2.new( ((m11 * v3.X + m21 * v3.Y + m31 * v3.Z)/hgf_w), ((m12 * v3.X + m22 * v3.Y + m32 * v3.Z)/hgf_w) ) end |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2013 12:00 AM |
I went to try this out myself. I was under the impression that the angle from center increases proportionally with distance in pixels from center. http://www.roblox.com/World-to-Screen-Coordinates-item?id=111948980
It kind of works. It's well commented if you want to take a look. However, when you click nearish to the center and position the part on the outskirts of your screen, you'll see it's about 70 pixels off. Click to read the screen's viewing angle at the point of the mouse.
I don't understand what you're doing in your code at this point: "local hgf_w = -(lv:Dot(v3) + 1)" That line makes no sense to me. Is v3 already offset by the position of the camera? Why +1? |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
|
| 06 Apr 2013 12:10 AM |
| Wow I do not understand this, I'm not that advanced with super math and CFrame yet ;( |
|
|
| Report Abuse |
|
|
zins
|
  |
| Joined: 14 Jan 2011 |
| Total Posts: 3394 |
|
| |
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
| |
|
zins
|
  |
| Joined: 14 Jan 2011 |
| Total Posts: 3394 |
|
| |
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 06 Apr 2013 06:25 AM |
@toaddonabove
print("Do you even 1+1?") |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 06 Apr 2013 10:19 AM |
@Blobbyblob
I was using a very simple method which required a 4x4 matrix. Unfortunately, ROBLOX only has a 3x4. The 4th number of the 4th row was default a 1. So I added that in there in order to emulate having the 4th matrix row and column.
The method would work much easier if I had a 4x4. |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
|
| 06 Apr 2013 11:29 AM |
@2 above the above me I smrtr den u, jus dun know cframe cuz i script, but build silly. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2013 11:31 PM |
@MrNicNac I don't know where you came up with the expression. I can't see the solution in it, so I really can't help. And I was going to throw your code into studio to experiment and it gave me some really goofy results. As I rotate the camera around the origin, the frame make a small circle, and then a large circle. I tried a bunch of different ways of wrapping your function. If I'm overlooking some important detail about the return values, let me know.
function WorldToScreenMrNicNac(v3, camera) local x,y,z,m11,m12,m13,m21,m22,m23,m31,m32,m33 = camera.CoordinateFrame:components() local lv = camera.CoordinateFrame.lookVector local hgf_w = -(lv:Dot(v3) + 1) return Vector2.new( ((m11 * v3.X + m21 * v3.Y + m31 * v3.Z)/hgf_w), ((m12 * v3.X + m22 * v3.Y + m32 * v3.Z)/hgf_w) ) end function WorldToScreen(v3, camera) v2 = WorldToScreenMrNicNac(v3 - camera.CoordinateFrame.p, camera); return Vector2.new(xScreenSize / 2 * (1 + v2.x), yScreenSize / 2 * (1 + v2.y)); end
You did say you nearly got yours working, with just a few small hitches, right? Or is the return value way off? |
|
|
| Report Abuse |
|
|