cam/PushModelMatrix

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Bug)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=PushModelMatrix
 
|Parent=cam
 
 
|Description=Pushes the specified matrix onto the render matrix stack. Unlike opengl, this will replace the current model matrix.
 
|Description=Pushes the specified matrix onto the render matrix stack. Unlike opengl, this will replace the current model matrix.
  
{{Bug|Issue=1663|This does not work with {{LibraryFunction|cam|Start3D2D}} in certain hooks.}}
+
{{Bug|Issue=1663|Fixed=|This does not work with {{LibraryFunction|cam|Start3D2D}} in certain hooks.}}
 
|Realm=Client
 
|Realm=Client
 
|IsClass=No
 
|IsClass=No
Line 12: Line 10:
 
|name=matrix
 
|name=matrix
 
|desc=The matrix to push.
 
|desc=The matrix to push.
 +
}}
 +
{{Arg
 +
|type=boolean
 +
|name=multiply
 +
|desc={{NextUpdate}}If set, multiplies given matrix with currently active matrix ({{LibraryFunction|cam|GetModelMatrix}}) before pushing.
 +
|default=false
 
}}
 
}}
 
{{Example
 
{{Example

Revision as of 17:43, 6 January 2020

 cam.PushModelMatrix( )

Contents

Description

Pushes the specified matrix onto the render matrix stack. Unlike opengl, this will replace the current model matrix.

BUG

This does not work with cam.Start3D2D in certain hooks.

Issue Tracker: #1663

This bug will be fixed in the next update.

Arguments

VMatrix matrix

The matrix to push.

Arguments

boolean multiply=false

Next Update Change

This feature is only available in the next update.
If set, multiplies given matrix with currently active matrix (cam.GetModelMatrix) before pushing.

Examples

Example

Rotates and scales text in the center of the screen.

hook.Add("HUDPaint", "2d rotation test", function()
	local w, h = ScrW(), ScrH()
	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")
	cam.PopModelMatrix()	
end)


Examples

Example

Simple function to draw rotated text

function draw.TextRotated(text, x, y, color, font, ang)
	render.PushFilterMag(TEXFILTER.ANISOTROPIC)
	render.PushFilterMin(TEXFILTER.ANISOTROPIC)
	surface.SetFont(font)
	surface.SetTextColor(color)
	surface.SetTextPos(0, 0)
	local textWidth, textHeight = surface.GetTextSize( text )
	local rad = -math.rad( ang )
	x = x - ( math.cos( rad ) * textWidth / 2 + math.sin( rad ) * textHeight / 2 )
	y = y + ( math.sin( rad ) * textWidth / 2 + math.cos( rad ) * textHeight / 2 )
	local m = Matrix()
	m:SetAngles(Angle(0, ang, 0))
	m:SetTranslation(Vector(x, y, 0))
	cam.PushModelMatrix(m)
		surface.DrawText(text)
	cam.PopModelMatrix()
	render.PopFilterMag()
	render.PopFilterMin()
end


Personal tools
Navigation