Skip to content

Instantly share code, notes, and snippets.

@ColonelThirtyTwo
Created August 11, 2012 00:03
Show Gist options
  • Save ColonelThirtyTwo/3319145 to your computer and use it in GitHub Desktop.
Save ColonelThirtyTwo/3319145 to your computer and use it in GitHub Desktop.
GMod Real Matrix Stack (if VMatrix:Copy() is implemented)
-- Usage: Apply desired transformations onto FakeMatrixStack.m then use FakeMatrixStack:push() to push those transformations
-- onto the stack. FakeMatrixStack:pop() undoes the push and reset FakeMatrixStack.m to the matrix
-- Example:
FakeMatrixStack.m:Translate(Vector(100,0,0))
FakeMatrixStack:push()
FakeMatrixStack.m:Rotate(Angle(90,90,0)) -- Matrix is conserved and applied on top of the previous
FakeMatrixStack:push()
drawSomething()
FakeMatrixStack:pop()
FakeMatrixStack:pop()
local FakeMatrixStack = {}
FakeMatrixStack.m = Matrix()
function FakeMatrixStack:push()
local m = self.m
cam.PushModelMatrix(m)
self[#self+1] = m:Copy()
end
function FakeMatrixStack:pop()
cam.PopModelMatrix()
self.m = self[#self]
self[#self] = nil
end
@tumen102
Copy link

thank you omg

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