Revision Difference
cam.PushModelMatrix#529289
<function name="PushModelMatrix" parent="cam" type="libraryfunc">
<description>
Pushes the specified matrix onto the render matrix stack. Unlike opengl, this will replace the current model matrix.
<note>This does not work with <page>cam.Start3D2D</page> if `multiply` is false.</note>
</description>
<realm>Client</realm>
<args>
<arg name="matrix" type="VMatrix">The matrix to push.</arg>
<arg name="multiply" type="boolean" default="false">If set, multiplies given matrix with currently active matrix (<page>cam.GetModelMatrix</page>) before pushing.</arg>
</args>
</function>
<example>
<description>Rotates and scales text in the center of the screen.</description>
<code>
hook.Add("HUDPaint", "2d rotation test", function()
local custom_vector = Vector( 1, 1, 1 )
⤶
hook.Add("HUDPaint", "2d rotation test", function()⤶
local w, h = ScrW(), ScrH()
local t = RealTime()*50⤶
local t = RealTime() * 50⤶
local mat = Matrix()
⤶
mat:Translate(Vector(w/2, h/2))
mat:Rotate(Angle(0,t,0))
mat:Scale(Vector(1,1,1) * math.sin(t/100) *10)
mat:Translate(-Vector(w/2, h/2))
⤶
cam.PushModelMatrix(mat)
surface.SetFont("DermaDefault")
surface.SetTextColor(255, 255, 255, 255)
surface.SetTextPos(w/2, h/2)
surface.DrawText("LOLLOLOLOL")
local m = Matrix()
local center = Vector( w / 2, h / 2 )
⤶
m:Translate( center )
m:Rotate( Angle( 0, t, 0 ) )
m:Scale( custom_vector * math.sin( t / 100 ) * 10 )
m:Translate( -center )
⤶
cam.PushModelMatrix( m )
surface.SetFont( "DermaDefault" )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( w / 2, h / 2 )
surface.DrawText( "LOLLOLOLOL" )⤶
cam.PopModelMatrix()
end)
</code>
⤶
</example>⤶
⤶
⤶
<example>⤶
<description>Simple function to draw rotated text</description>⤶
</example>⤶
⤶
<example>⤶
<description>Simple function to draw rotated text.</description>⤶
<code>
function draw.RotatedText(text,x,y,font,color,ang)
render.PushFilterMag(TEXFILTER.ANISOTROPIC)
render.PushFilterMin(TEXFILTER.ANISOTROPIC)
local m = Matrix()
m:Translate(Vector(x,y,0))
m:Rotate(Angle(0,ang,0))
surface.SetFont(font)
local sX,sY = surface.GetTextSize(text)
m:Translate(-Vector(sX/2,sY/2,0))
cam.PushModelMatrix(m)
draw.DrawText(text, font, 0,0, color)
cam.PopModelMatrix()
function draw.RotatedText( text, x, y, font, color, ang)
render.PushFilterMag( TEXFILTER.ANISOTROPIC )
render.PushFilterMin( TEXFILTER.ANISOTROPIC )
local m = Matrix()
m:Translate( Vector( x, y, 0 ) )
m:Rotate( Angle( 0, ang, 0 ) )
surface.SetFont( font )
local w, h = surface.GetTextSize( text )
m:Translate( -Vector( w / 2, h / 2, 0 ) )
cam.PushModelMatrix( m )
draw.DrawText( text, font, 0, 0, color )
cam.PopModelMatrix()
render.PopFilterMag()
render.PopFilterMin()
⤶
end⤶
end⤶
</code>
⤶
</example></example>