ENTITY/Draw

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Tried to make the function more re-usable (example 1))
(Code formatting on example 1)
 
Line 16: Line 16:
 
|Description=Draws the model and makes a rotating text over the entity
 
|Description=Draws the model and makes a rotating text over the entity
 
|Code=-- Draw some 3D text
 
|Code=-- Draw some 3D text
drawText001 = function(
+
local function Draw3DText( pos, ang, scale, text, flipView )
_pos,
+
if ( flipView ) then
_ang,
+
_scale,
+
_text,
+
_flipView
+
)
+
if _flipView then
+
 
-- Flip the angle 180 degrees around the UP axis
 
-- Flip the angle 180 degrees around the UP axis
_ang:RotateAroundAxis( Vector( 0, 0, 1 ), 180 )
+
ang:RotateAroundAxis( Vector( 0, 0, 1 ), 180 )
 
end
 
end
  
cam.Start3D2D( _pos, _ang, _scale )
+
cam.Start3D2D( pos, ang, scale )
 
-- Actually draw the text. Customize this to your liking.
 
-- Actually draw the text. Customize this to your liking.
draw.DrawText(
+
draw.DrawText( text, "Default", 0, 0, Color( 0, 255, 0, 255 ), TEXT_ALIGN_CENTER )
_text,
+
"Default",
+
0,
+
0,
+
Color( 0, 255, 0, 255 ),
+
TEXT_ALIGN_CENTER
+
)
+
 
cam.End3D2D()
 
cam.End3D2D()
 
end
 
end
Line 45: Line 32:
 
self:DrawModel()
 
self:DrawModel()
  
    -- SETTINGS --
 
    -- -
 
 
-- The text to display
 
-- The text to display
 
local text = "Example Text"
 
local text = "Example Text"
Line 57: Line 42:
 
local ang = Angle( 0, SysTime() * 100 % 360, 90 )
 
local ang = Angle( 0, SysTime() * 100 % 360, 90 )
  
    --- -- -
 
 
-- Draw front
 
-- Draw front
drawText001(pos, ang, 0.2, text, false)
+
Draw3DText( pos, ang, 0.2, text, false )
-- Draw back
+
-- DrawDraw3DTextback
drawText001(pos, ang, 0.2, text, true)
+
Draw3DText( pos, ang, 0.2, text, true )
 
end
 
end
 +
 
}}
 
}}

Latest revision as of 14:48, 15 April 2019

 ENTITY:Draw( )

Contents

Description

Called if and when the entity should be drawn opaquely, based on the Entity:GetRenderGroup of the entity.

See ENT structure and RENDERGROUP_ Enums for more information.

See also ENTITY:DrawTranslucent.

Arguments

number flags

The bit flags from STUDIO_ Enums

Examples

Example

Draws the model and makes a rotating text over the entity

-- Draw some 3D text
local function Draw3DText( pos, ang, scale, text, flipView )
	if ( flipView ) then
		-- Flip the angle 180 degrees around the UP axis
		ang:RotateAroundAxis( Vector( 0, 0, 1 ), 180 )
	end

	cam.Start3D2D( pos, ang, scale )
		-- Actually draw the text. Customize this to your liking.
		draw.DrawText( text, "Default", 0, 0, Color( 0, 255, 0, 255 ), TEXT_ALIGN_CENTER )
	cam.End3D2D()
end

function ENT:Draw()
	-- Draw the model
	self:DrawModel()

	-- The text to display
	local text = "Example Text"

	-- The position. We use model bounds to make the text appear just above the model. Customize this to your liking.
	local mins, maxs = self:GetModelBounds()
	local pos = self:GetPos() + Vector( 0, 0, maxs.z + 2 )

	-- The angle
	local ang = Angle( 0, SysTime() * 100 % 360, 90 )

	-- Draw front
	Draw3DText( pos, ang, 0.2, text, false )
	-- DrawDraw3DTextback
	Draw3DText( pos, ang, 0.2, text, true )
end


Personal tools
Navigation