• Checking if player is aiming inside draw.RoundedBox
    15 replies, posted
I need to check if a player is aiming within a 3D2D box. [lua]if _hitentity:GetClass() == "treasury" then draw.RoundedBox(0, 0, 0, 60, 20, Color(255,255,255,255)) if _hitpos == Vector(self:LocalToWorld(Vector(33, -6, 30)), self:LocalToWorldAngles(Angle(0,90,90))) then draw.RoundedBox(0, 0, 60, 20, 20, Color(0,0,0,255)) end end[/lua] Thats all i could think of. Now it doesnt show a black box, PRESUMABLY because its too hard to hit the exact vector. Atleast thats my thought anyways. Anyways how can i check if the hitpos is within the 3d2d draw.roundedbox. I really need this as soon as possible but cant work it out. Thanks in advance!
[url=https://code.google.com/p/bluekirbygmod/source/browse/trunk/Blue+Bot/mein.lua]BlueBot[/url] used to do something similar in their aimbot. If you locked on to the head it would draw a red box (which isn't what you're looking for but it is a step in what you need) but I'm at work and can't get the code for you. I'm sure that would assist you a bit.
[QUOTE=Zedd;46536809][url=https://code.google.com/p/bluekirbygmod/source/browse/trunk/Blue+Bot/mein.lua]BlueBot[/url] used to do something similar in their aimbot. If you locked on to the head it would draw a red box (which isn't what you're looking for but it is a step in what you need) but I'm at work and can't get the code for you. I'm sure that would assist you a bit.[/QUOTE] Ahh ok. I had a look cant really see much to do with what im looking for, But i also cant see the other files because i dont know how to use SVN lol. Anyways does anyone else possibly know how?
Does 3d2d actually stop a trace?
[QUOTE=Exho;46538237]Does 3d2d actually stop a trace?[/QUOTE] Not sure. I've seen it on some servers. They have like buttons on printers that are 3D2D and are used to upgrade printers etc
[url]http://wiki.garrysmod.com/page/Vector/ToScreen[/url] + < and > checks
[QUOTE=nettsam;46538366][url]http://wiki.garrysmod.com/page/Vector/ToScreen[/url] + < and > checks[/QUOTE] Cheers for that, Ill look into it. Could i get an examaple of how i would apply this into my addon? I dont see what use 2d co ords would have since the player will always be moving around, So will the entity possibly. Sorry if its obvious or whatever, Im still a bit new to all this.
[QUOTE=Exho;46538237]Does 3d2d actually stop a trace?[/QUOTE] It does not to my knowledge. [QUOTE=nettsam;46538366][url]http://wiki.garrysmod.com/page/Vector/ToScreen[/url] + < and > checks[/QUOTE] That wont work with 3D2D cams. You can calculate the line / plane intersect and convert it to local coordinates. This code should work at any angle. I am using an AABB method of detecting, so the rounded corners are ignored. [LUA] hook.Add("PostDrawOpaqueRenderables", "example", function() local _origin = Vector(10, 20, 80) -- the 3d2d pos local _angle = Angle(10, 25, 80) -- the 3d2d angle local _n = Vector(0, 0, 10) -- calculating the normal of the plane _n:Rotate(_angle) local _eye0 = LocalPlayer():GetShootPos() -- self explanitory local _eye = LocalPlayer():GetAimVector() local _d = (_origin - _eye0):Dot(_n) / _eye:Dot(_n) -- calculate on the line intersects the plane local _intersect = _eye0 + (_eye*_d) -- calculate where the intesection is in 3d space local _local = WorldToLocal(_intersect, Angle(), _origin, _angle-Angle(0, 0, 180)) -- convert the world vector to local render.DrawLine(_intersect, _intersect + _n, Color(117, 73, 50, 255), true) -- the is the line showing the intersect point cam.Start3D2D(_origin, _angle, 0.1) -- create 3d2d at 1/10 th scale to shrink the text local x, y, w, h = 0, 0, 8, 8 -- box 2 pos and size local color = Color(150, 150, 150, 255) -- box 2 color if (x < _local.x) and (_local.x < x+w) and (x < _local.y) and (_local.y < y+h) then color = Color(50, 50, 50, 255) end -- testing pos draw.RoundedBox(16, x*10, y*10, w*10, h*10, color) -- scaled up to draw x, y, w, h = 8, 8, 24, 24 -- box 2 pos and size color = Color(150, 150, 150, 255) -- box 2 color if (x < _local.x) and (_local.x < x+w) and (x < _local.y) and (_local.y < y+h) then color = Color(50, 50, 50, 255) end draw.RoundedBox(16, x*10, y*10, w*10, h*10, color) surface.DrawCircle(_local.x*10, _local.y*10, 5, Color(255, 255, 255, 255)) -- simple cursor draw.SimpleText(tostring(_local), "DermaDefault", 90, 90, Color(100, 100, 100, 255), 0, 0) -- debug data cam.End3D2D() end) [/LUA] EDIT: This code does NOT take into account objects between you and the cam and will still work at range.
I think I have the solution. Let me perform the necessary calculations and I'll post it here. [editline] ninja [/editline] Son of a ninja... [editline]ses[/editline] [QUOTE=darkwolf0101;46538388]It does not to my knowledge. [/QUOTE] Yeah. 3D2D is just an 2D plane rendered in 3D space. It's not solid.
[QUOTE=darkwolf0101;46538388] [CODE] hook.Add("PostDrawOpaqueRenderables", "example", function() local _origin = Vector(10, 20, 80) -- the 3d2d pos local _angle = Angle(10, 25, 80) -- the 3d2d angle local _n = Vector(0, 0, 10) -- calculating the normal of the plane _n:Rotate(_angle) local _eye0 = LocalPlayer():GetShootPos() -- self explanitory local _eye = LocalPlayer():GetAimVector() local _d = (_origin - _eye0):Dot(_n) / _eye:Dot(_n) -- calculate on the line intersects the plane local _intersect = _eye0 + (_eye*_d) -- calculate where the intesection is in 3d space local _local = WorldToLocal(_intersect, Angle(), _origin, _angle-Angle(0, 0, 180)) -- convert the world vector to local render.DrawLine(_intersect, _intersect + _n, Color(117, 73, 50, 255), true) -- the is the line showing the intersect point cam.Start3D2D(_origin, _angle, 0.1) -- create 3d2d at 1/10 th scale to shrink the text local x, y, w, h = 0, 0, 8, 8 -- box 2 pos and size local color = Color(150, 150, 150, 255) -- box 2 color if (x < _local.x) and (_local.x < x+w) and (x < _local.y) and (_local.y < y+h) then color = Color(50, 50, 50, 255) end -- testing pos draw.RoundedBox(16, x*10, y*10, w*10, h*10, color) -- scaled up to draw x, y, w, h = 8, 8, 24, 24 -- box 2 pos and size color = Color(150, 150, 150, 255) -- box 2 color if (x < _local.x) and (_local.x < x+w) and (x < _local.y) and (_local.y < y+h) then color = Color(50, 50, 50, 255) end draw.RoundedBox(16, x*10, y*10, w*10, h*10, color) surface.DrawCircle(_local.x*10, _local.y*10, 5, Color(255, 255, 255, 255)) -- simple cursor draw.SimpleText(tostring(_local), "DermaDefault", 90, 90, Color(100, 100, 100, 255), 0, 0) -- debug data cam.End3D2D() end) [/CODE] unacecoolify your code and yeah it should i've seen the src to a printer that does 3d buttons hovered in 2d space and that's how they did it
[QUOTE=nettsam;46538406] unacecoolify your code and yeah it should i've seen the src to a printer that does 3d buttons hovered in 2d space and that's how they did it[/QUOTE] Please explain "unacecoolify" because I have no clue what you mean by that.
[QUOTE=darkwolf0101;46538421]Please explain "unacecoolify" because I have no clue what you mean by that.[/QUOTE] Underscores before your local variables. Its something Acecool is known for doing
[QUOTE=nettsam;46538406] unacecoolify your code [/QUOTE] Don't worry.. [URL="https://bitbucket.org/Acecool/acecooldev_base/src/ce117bb1376e3ad1648cec91985fe67e96051719/?at=gmod_standards"]I'm an expert[/URL]. [lua] hook.Add("PostDrawOpaqueRenderables", "example", function() local origin = Vector(10, 20, 80) -- the 3d2d pos local ang = Angle(10, 25, 80) -- the 3d2d angle local n = Vector(0, 0, 10) -- calculating the normal of the plane n:Rotate(ang) local eye0 = LocalPlayer():GetShootPos() -- self explanitory local eye = LocalPlayer():GetAimVector() local d = (origin - eye0):Dot(n) / eye:Dot(n) -- calculate on the line intersects the plane local intersect = eye0 + (eye*d) -- calculate where the intesection is in 3d space local lcl = WorldToLocal(intersect, Angle(), origin, ang-Angle(0, 0, 180)) -- convert the world vector to local render.DrawLine(intersect, intersect + n, Color(117, 73, 50, 255), true) -- the is the line showing the intersect point cam.Start3D2D(origin, ang, 0.1) -- create 3d2d at 1/10 th scale to shrink the text local x, y, w, h = 0, 0, 8, 8 -- box 2 pos and size local color = Color(150, 150, 150, 255) -- box 2 color if (x < lcl.x) and (lcl.x < x+w) and (x < lcl.y) and (lcl.y < y+h) then color = Color(50, 50, 50, 255) end -- testing pos draw.RoundedBox(16, x*10, y*10, w*10, h*10, color) -- scaled up to draw x, y, w, h = 8, 8, 24, 24 -- box 2 pos and size color = Color(150, 150, 150, 255) -- box 2 color if (x < lcl.x) and (lcl.x < x+w) and (x < lcl.y) and (lcl.y < y+h) then color = Color(50, 50, 50, 255) end draw.RoundedBox(16, x*10, y*10, w*10, h*10, color) surface.DrawCircle(lcl.x*10, lcl.y*10, 5, Color(255, 255, 255, 255)) -- simple cursor draw.SimpleText(tostring(lcl), "DermaDefault", 90, 90, Color(100, 100, 100, 255), 0, 0) -- debug data cam.End3D2D() end) [/lua]
[QUOTE=Exho;46538460]Underscores before your local variables. Its something Acecool is known for doing[/QUOTE] Lol I do that to avoid messing things up if I forget to localize a variable.
[QUOTE=nettsam;46538406] unacecoolify your code and yeah it should i've seen the src to a printer that does 3d buttons hovered in 2d space and that's how they did it[/QUOTE] Ctrl+F. Find and Replace. find: _ Replace: Replace all.
This code will work for determining if a player is looking directly at any arbitrary 3d2d rectangle. [CODE] local isec = IntersectRayWithPlane( EyePos( ply ), Forward( EyeAngles( ply ) ), pos, trace.HitNormal ) if isec then local ap = pos - isec local ab = pos - tr local ad = pos - bl local ap_ab = Dot( ap, ab ) local ab_ab = Dot( ab, ab ) local ap_ad = Dot( ap, ad ) local ad_ad = Dot( ad, ad ) if 0 < ap_ab and ap_ab < ab_ab and 0 < ap_ad and ap_ad < ad_ad and IsLineOfSightClear( ply, isec ) then --and if they have line of sight of the panel --Do whatever you'd like, they're looking directly at the panel end end [/CODE] where trace.HitNormal is the vector of the direction your panel is facing. You could also use ang:Up() if you're not using a trace to determine the position of your panel. pos is the vector of the top left of the rectangle, isec is the intersection of the players view with the plane of the panel, tr is the vector of the top right of the rectangle, and bl is the vector of the bottom left of the rectangle. I name my variables in accordance with the line that the resulting vector represents. With a given point 'P', and a rectangle defined by the points A(top left), B(top right), C(bottom right), and D(bottom left), a the resulting line from vector P to vector A would be called 'ap'. Fairly simple. When getting the dot-product of two vectors, I name the result vector1_vector2 so the dot product of AP and AD gives you 'ap_ad' again, fairly simple. Finally, when evaluating, you just do the comparison that I did. (My brother helped me with this part). Check that the dot product of AP and AB is between 0 and the dot product of AB and AB. Then check that the dot product of AP and AD is between 0 and the dot product of AD and AD. If that statement evaluates to true, then your plane intersection vector is inside the rectangle! I also added a check to make sure that the player has view of the intersection point, so that you can't 'look' at a panel that is behind a wall or some such.
Sorry, you need to Log In to post a reply to this thread.