Ray-Quad intersection

I am pretty bad at math. Just putting that out there. So, what i want to do, is have a 3D2D menu type of thing, and i can do everything but the actual placement of the cursor. What i need to know, is (because the entity wont be solid) how i can get the interect point, either globally, or locally to the entity (preferably locally) of the closest players Eye() or w/e its called, and the quad of the “screen”. Thank you very much, i hope you can help. I can do the screen, with the buttons, and checking if the users clicking a button, i can do all that easilly. i just need to know where the cursor is. If its globally, i can just WorldToLocal it. Again, thanks.

[editline]11:15AM[/editline]

Oh come ON people!

There is an example on how to do this on the wiki page for cam.Start3D2D.

**[Cam.Start3D2D

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Cam.Start3D2D)**

The example on the wiki should do the trick, but you could put an invisible entity behind the screen which collides with nothing but stays in sync with the screen (same position, angle etc), and setup a traceline. If it hits the screen, use the HitPos to determine how far from the edges of the entity the cursor is (as a decimal, so 0.5 would be half way between edges), and multiply that by the screen size to get cursor position.

(Good luck understanding that)

[lua]function LinePlaneIntersection(planePos, planeNormal, linePos, lineNormal)
local d = planePos:Dot(planeNormal)
local t = d - linePos:Dot(planeNormal) / lineNormal:Dot(planeNormal)

if t < 0 then return; end
return linePos + lineNormal * t;

end[/lua]

You can use this. Just pass the screen’s position, direction, the player’s view position, and the player’s aim vector.
Then check if the returned value is within the screen’s area.

Thank you Vicis. Thats what i needed :slight_smile: