Reading current transformation stack

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
mode7
Prole
Posts: 35
Joined: Tue Aug 21, 2012 5:45 pm
Contact:

Reading current transformation stack

Post by mode7 » Tue Sep 25, 2012 2:11 pm

I'm trying to implement a simple mip-mapping support for my engine. Though I rely heavily on graphic.push() and graphics.pop() function to do my camera and object drawing it is hard for me to determine which is the current scale. I was searching the wiki but didn't find any function about how to read the currently used coordinate system.
Any ideas?

User avatar
Lafolie
Inner party member
Posts: 805
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Reading current transformation stack

Post by Lafolie » Tue Sep 25, 2012 3:51 pm

It can't be that hard to manually track it could it? You could even wrap it in a function that does this for you, enabling you to actually write a love.graphics.getScale. I'm not sure why it doesn't exist, but maybe you could ask on the http://bitbucket.org/rude/love/issues page.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.

mode7
Prole
Posts: 35
Joined: Tue Aug 21, 2012 5:45 pm
Contact:

Re: Reading current transformation stack

Post by mode7 » Tue Sep 25, 2012 8:37 pm

Thanks for the answer.
Well I added the missing functionality,maybe someone will find it useful:

Code: Select all

local _scaleX, _scaleY, _dx, _dy, _angle = 1,1,0,0,0
local stack = {}
local old_scale = love.graphics.scale
local old_translate = love.graphics.translate
local old_rotate = love.graphics.rotate
local old_push = love.graphics.push
local old_pop = love.graphics.pop

function love.graphics.push()
	local v = {_scaleX=_scaleX, _scaleY=_scaleY, _dx=_dx, _dy=_dy, _angle=_angle}
	table.insert(stack, 1, v)
	old_push()
end

function love.graphics.pop()
	local v = stack[1]
	_scaleX, _scaleY, _dx, _dy, _angle = v._scaleX, v._scaleY, v._dx, v._dy, v._angle 
	table.remove(stack, 1)
	old_pop()
end

function love.graphics.getScale()
	return _scaleX, _scaleY
end

function love.graphics.getTranslation()
	return _dx,_dy
end

function love.graphics.getRotation()
	return _angle
end

function love.graphics.scale(scaleX, scaleY)
	scaleY = scaleY or scaleX
	_scaleX, _scaleY = _scaleX+scaleX, _scaleY+scaleY 
	old_scale(scaleX, scaleY)
end

function love.graphics.rotate(angle)
	_angle = _angle+angle
	old_rotate(angle)
end

function love.graphics.translate(dx,dy)
	_dx, _dy = _dx+dx, _dy+dy
	old_translate(dx,dy)
end

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests