Skip to content

Instantly share code, notes, and snippets.

@Lexicality
Created May 25, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lexicality/c8dbd599c9810fdbc2ca to your computer and use it in GitHub Desktop.
Save Lexicality/c8dbd599c9810fdbc2ca to your computer and use it in GitHub Desktop.
portal pair
AddCSLuaFile()
MsgN("Portal Loaded")
DEFINE_BASECLASS( "base_anim" )
ENT.PrintName = "Portal"
ENT.Author = "Lex Robinson"
ENT.Information = "Are you still there?"
ENT.Category = "Lex's Dev Stuff"
ENT.Editable = false
ENT.Spawnable = true
ENT.AdminOnly = false
ENT.RenderGroup = RENDERGROUP_TRANSALPHA
function ENT:SetupDataTables()
self:NetworkVar( "Entity", 0, "other" )
end
function ENT:Initialize()
if ( SERVER ) then
self:SetModel("models/hunter/plates/plate2x2.mdl");
self:PhysicsInit(SOLID_VPHYSICS);
self:SetMoveType(MOVETYPE_VPHYSICS);
self:SetSolid(SOLID_VPHYSICS);
self:GetPhysicsObject():Wake();
self:TryPair();
end
end
g_PortalPairWaiting = nil
function ENT:TryPair()
if ( IsValid(g_PortalPairWaiting) ) then
self:OnPair(g_PortalPairWaiting);
g_PortalPairWaiting:OnPair(self);
g_PortalPairWaiting = nil
else
g_PortalPairWaiting = self
end
end
function ENT:OnPair(other)
self.dt.other = other;
other:CallOnRemove("Portal pairage", function()
if IsValid(self) then
self:TryPair()
end
end);
end
if SERVER then return end
local rt = GetRenderTarget( "portalus", 1024, 1024, true );
local rtm = Material("portalus");
local camData = {
-- drawhud = false;
-- drawviewmodel = false;
-- x = 0;
-- y = 0;
-- w = 1024;
-- h = 1024;
};
local isRendering;
function ENT:DrawPortal( wx, wy, voffset )
if isRendering then return end
local other = self.dt.other;
if not IsValid(other) then return; end
camData.origin = other:GetPos();-- + other:GetUp() * 20;
camData.angles = other:GetUp():Angle();
isRendering = true;
local oldrt = render.GetRenderTarget();
render.SetRenderTarget(rt);
render.Clear(0, 0, 0, 0, true, true);
render.RenderView(camData);
render.SetRenderTarget(oldrt);
isRendering = false
cam.Start3D2D(self:GetPos() + self:GetUp() * 2, self:GetAngles(), 1)
surface.SetDrawColor(255,255,255,255)
rtm:SetTexture( "$basetexture", rt )
surface.SetMaterial(rtm);
surface.DrawTexturedRect(-50, -50, 100, 100)
cam.End3D2D()
end
function ENT:Draw()
self:DrawModel();
self:DrawPortal();
end
@Lexicality
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment