How to make a rotated box in lua?

Hello everyone! I just would like to know how to make a box/rectangle that is rotated x degrees. I know about surface.DrawRectBoxRotated or something like that, but if that’s what i’m supposed to use can someone explain it?

Thanks.

You pretty much just have to use this:

Plus this to “reset” the texture:

I did that and nothing showed up in my screen :frowning:

You did it wrong.


surface.DrawTexturedRectRotated(ScrW() / 2, ScrH() / 2, 100, 100, 30)

–snip–

That’s what I did

Sorry tired af

Did you do draw.NoTexture()? did you do surface.SetDrawColor()? Are you calling that function in a drawing hook?

What are you trying to draw?

just a box rotated.

Sorry, I’m fairly new to lua, but does this need it’s own function? And what do u mean by calling that function to a drawing hook?

[quote=“ExZPErience, post:11, topic:209371”]

just a box rotated.

If its a function like function MyHUD() then you’d need hook.Add(“HUDPaint”, “SomeUniqueName”, MyHUD)

And its alright man :slight_smile: We all start somewhere!

[editline]7th August 2015[/editline]



local texture = surface.GetTextureID("materials/slime.png"); -- No file types.
function DrawBox()
   surface.SetTexture(texture)
   surface.SetDrawColor(255,255,255,255) -- So it draws in normal color.
   surface.DrawTexturedRectRotated(50,50,50,50,80) -- Note: Rotation is ANTI-CLOCKWISE.
end
hook.Add("HUDPaint", "MyTexture", DrawBox)


Got that off of maurits.tv. Works perfect.

Added an example to the wiki page.

[quote=“CGHippo, post:12, topic:209371”]

Thank you sooo much!

Thank you, too!

[editline]7th August 2015[/editline]

I did what you said and noticed something with the box…

as you can see it’s very… pointyish

how do I fix it?



function draw.RotatedBox( x, y, w, h, ang, color )
	draw.NoTexture()
	surface.SetDrawColor( color or color_white )
	surface.DrawTexturedRectRotated( x, y, w, h, ang )
end

hook.Add( "HUDPaint", "my_rotated_box", function()
	draw.RotatedBox( 100, 100, 100, 100, CurTime() % 360, Color( 255, 0, 0 ) )
end )


refer to robotboys