So basically im trying to make some 3D2D buttons but i cant seem to understand how util.IntersectRayWithPlane() works.I wondered around facepunch forums, tried to understand 3D2D vgui derma code, googled for some help but still didnt understand it. So i figured why just sit and melt your brain when theres a community that can help you. So thats why im here. I want to ask if someone could explain to me how all of this works. Thanks in advance.
Whats an actual problem with usage of that function?
Ok i think i figured it out. I will post the visual explanation here so if people have the same problem they could understand it.
Ok first of all lets get the arguments done.
util.IntersectRayWithPlane( Vector rayOrigin, Vector rayDirection, Vector planePosition, Vector planeNormal )
Lets say we have a cone
https://files.facepunch.com/forum/upload/469093/c4e7b542-b4fd-41ed-ba93-6a227ff8dbf2/blender_9CP4HRcoBu.png
rayOrigin is the position of this cone,
rayDirection is the position at which this cone is pointing.
Now we need a plane
https://files.facepunch.com/forum/upload/469093/d4efcfbd-4b2f-4d7f-8b3c-f8bc035d7491/blender_WW9Phs4AU4.png
planePosition is the start of the green arrow,
planeNormal is the end of the green arrow(if you want to use an angle here then just use method :Up() on it).
(NOTE 1: Normal is an object such as a line or vector that is perpendicular to a given object.)
Plane is created by these two parameters.
(NOTE 2: This plane extends from one border of the map to another)
(NOTE 3: planePosition will be x=0 and y=0 on the plane)
So now if we run the current code(Which should look something like this)
https://files.facepunch.com/forum/upload/469093/86102296-4d15-4cf5-b7fc-e63141c53e59/Code_2vR5VlFidw.png
the function will return Vector releative to the planePosition if you're looking at the plane and nil if not.
Now if you will try to rotate this plane you can see that the Vector arguments can vary(Vector(2.19274, -3.10482, 0.00000), Vector(0.00000, 5.29471, 10.50212) etc.)
To convert this to xy coordinates we will first need to pass it through WorldToLocal function
WorldToLocal(IntersectVector(the one that we got earlier), Angle(0, 0, 0), planePosition, planeAngle)
https://files.facepunch.com/forum/upload/469093/25421ad2-c026-4ff2-a8cb-9f327cb04327/opera_GBoOVpVFFk.png
Remember this? planeAngle is the one we use here.
Now we get a Vector.
Vector(X position, inverted Y position, value we dont need)
So now we just need to multiply Y on -1. In other words just invert it.
(NOTE 4: You need to scale the vector so it will corresponds to your 3D2D camera scale(if your cam scale is 0.1 them multiply the vector by 10, if 2 then divide by 2))
Ok. So now we have the X and Y coordinates of the plane and can use them to determine if we are lookind at the button or not(check if X and Y are beetween your buttons position and sizes).
Congrats now you can create your own 3D2D buttons. I hope this was helpful to anyone reading this and i wish that you will make great codes in the future.
Also sorry if there were any gramatical mistakes in this post.
If you still have any questions just ask them here(maybe me or other people will answer you).
Sorry, you need to Log In to post a reply to this thread.