Hi guys, i made a 3D2D menu. Pic: [IMG]http://dl.dropbox.com/u/5270951/gm_construct0009.jpg[/IMG]
[IMG]http://dl.dropbox.com/u/5270951/gm_construct0013.jpg[/IMG]
The cursor uses ray-quad intersection given to me by Lutin. Thanks :)
Anyway, my problem. It has buttons. These buttons are suposed to register that the cursor is over them, and if your clicking, click the button. It works perfectly, except for the fact that, when it gets more than half way down the menu, buttons dont work. They dont register at all. The cursor is in the right place and everything, it just doesnt register. It used to sort of invert the Y axis, but i just re-inverted it. Can y'all help maby? Ill post some of the code here:
[lua]
PlanePos = self.Entity:GetPos()
Normal = self.Entity:GetUp()
ShootPos = LocalPlayer():EyePos()
Eye = LocalPlayer():GetEyeTraceNoCursor().Normal
Inter =--Ray-Quad intersect code --:3 Lutin thanks a bunch for this part
Inter = self.Entity:WorldToLocal(Inter)
Inter.x = math.Clamp(Inter.x, -(275/2),(275/2)) -- clamp it to the confines
Inter.y = math.Clamp(Inter.y, -200,0) -- of the menu
surface.SetDrawColor(152,251,152,255)
surface.DrawRect(Inter.x-1,-Inter.y-1,2,2) -- draw the cursor
for k,v in pairs(Buttons) do -- loop through all the buttons
local A = (Vector(v["Pos"]["x"],v["Pos"]["y"],0)+(Vector(v["Size"]["w"],v["Size"]["h"],0))) -- get the "obbsmax" for the vector inrange function to use
A.x = A.x-2 -- make the
A.y = A.y-2 -- cursor centered
local B = Vector(v["Pos"]["x"],v["Pos"]["y"],0) -- "obbsmin" for my inrange
// print(A,B,Inter)
--surface.SetDrawColor(152,251,152,255)
surface.SetDrawColor(255,0,0,255) -- draw the
surface.DrawRect(A.x,A.y,2,2) -- max and
surface.SetDrawColor(0,255,0,255) -- min for debugging and
surface.DrawRect(B.x,B.y,2,2) -- because it looks cool
InterSub = Inter
InterSub.y = -InterSub.y -- invert the y axis
if(InterSub:IsInRange(B,A)) then
if(LocalPlayer():KeyDown( IN_ATTACK )) then -- if their clicking
v["BackColor"] = ClickCol -- set the color to clicked
Clicked(k) -- call the clicked function with the id of the button
else
v["BackColor"] = MouseOverCol -- guess
end
else
v["BackColor"] = Color(0,0,255,255) -- guess
end
end
[/lua]
Hope you can help me! Btw, the IsInRange function:
[lua]
function _R.Vector:IsInRange(v1, v2)
return self.x >= v1.x and self.x <= v2.x and self.y >= v1.y and self.y <= v2.y and self.z >= v1.z and self.z <= v2.z; -- Thanks MakeR
end
[/lua]
[editline]01:01PM[/editline]
Just say if you need diffrent parts of the code
[editline]01:05PM[/editline]
Also, if your more than a certain distance away from it the buttons dont work. Also, maby someone could help me with the fact that it seems to have a low(high?) rendering priority, which means that props render over it. How could i fix this. Its all being run in the cl_init.lua of an entity
[editline]01:22PM[/editline]
Ok, so i had it debug. When i was in sub-menu, and my cursor was over Action2, here is the debug: (The cursor was almost exactly in the middle)
[code]
Button Text: Action 2 A: -29.5000 168.0000 0.0000 B: -127.5000 150.0000 0.0000 Inter: -103.0713 144.4963 0.0000
[/code]as you see, -103 is inbetween -29 and -127, but 144 is not inbetween 168 and 150. Wtf? Im confuseddd :(
No one?
Snap, broke my automerge
Try using Lua tags, I'm not in the mood to decipher your code when its in plain text :/
[QUOTE=Kopimi;20881816]Try using Lua tags, I'm not in the mood to decipher your code when its in plain text :/[/QUOTE]
Then you're pretty bad at reading.
Inter =--Ray-Quad intersect code --:3 Lutin thanks a bunch for this part
Show us this part, please.
[QUOTE=Bletotum;20883860]Then you're pretty bad at reading.[/QUOTE]
Its not that I cant, its that if hes going to ask for help, he may as well have the courtesy to put in some simple tags so its easier and more convenient for us.
And instead of being a hypocrite, why dont you go code for a few hours in Microsoft's Notepad, then come back and whine at me for wanting some syntax highlighting.
The fuck, I DID! Why does it keep on edditing them out!
[editline]09:55PM[/editline]
There... fixed.
[editline]09:56PM[/editline]
[lua]
Inter = ShootPos-(Normal:DotProduct(ShootPos-PlanePos))/(Normal:DotProduct(Eye))*Eye
[/lua]
Why're you inverting the y axis?
Because if i don't, it moves in the oposite direction. Its inverted if i don't invert it if you catch my drift.
But you invert the y axis once per button and after you've drawn the cursor. The y part of the mouse will be in 2 different places for each button depending on what order they came out of the loop.
Remember that objects (including tables) are passed by reference, not value. InterSub == Inter and anything you to do InterSub you do to to Inter.
Oh. Duh. Lol!
Sorry, you need to Log In to post a reply to this thread.