surface/DrawTexturedRectRotated

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
 
Line 9: Line 9:
 
|type=number
 
|type=number
 
|name=x
 
|name=x
|desc=The X co-ordinate, representing the center of the rectangle.
+
|desc=The X integer co-ordinate, representing the center of the rectangle.
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=number
 
|type=number
 
|name=y
 
|name=y
|desc=The Y co-ordinate, representing the center of the rectangle.
+
|desc=The Y integer co-ordinate, representing the center of the rectangle.
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=number
 
|type=number
 
|name=width
 
|name=width
|desc=The width of the rectangle.
+
|desc=The integer width of the rectangle.
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=number
 
|type=number
 
|name=height
 
|name=height
|desc=The height of the rectangle.
+
|desc=The integer height of the rectangle.
 
}}
 
}}
 
{{Arg
 
{{Arg

Latest revision as of 13:21, 3 April 2018

 surface.DrawTexturedRectRotated( )

Contents

Description

Draw a textured rotated rectangle with the given position and dimensions and angle on the screen, using the current active texture.

NOTE

This is a rendering function that requires a 2D rendering context.
This means that it will only work in hooks with a 2D rendering context.

Arguments

number x

The X integer co-ordinate, representing the center of the rectangle.

Arguments

number y

The Y integer co-ordinate, representing the center of the rectangle.

Arguments

number width

The integer width of the rectangle.

Arguments

number height

The integer height of the rectangle.

Arguments

number rotation

The rotation of the rectangle, in degrees.

Examples

Example

A function that allows you to override the origin of rotation.

x0 and y0 are relative to the center of the rectangle.

function surface.DrawTexturedRectRotatedPoint( x, y, w, h, rot, x0, y0 )
	
	local c = math.cos( math.rad( rot ) )
	local s = math.sin( math.rad( rot ) )
	
	local newx = y0 * s - x0 * c
	local newy = y0 * c + x0 * s
	
	surface.DrawTexturedRectRotated( x + newx, y + newy, w, h, rot )
	
end


Examples

Example

Draws a simple red forever rotating box.

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 )


Personal tools
Navigation