Created
August 11, 2012 00:03
-
-
Save ColonelThirtyTwo/3319145 to your computer and use it in GitHub Desktop.
GMod Real Matrix Stack (if VMatrix:Copy() is implemented)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you omg