function Example:draw()
pushMatrix()
translate(self.x, self.y )
rotate( self.angle )
for i = 0, self.width do
for a = 0, self.height do
local bx = i*self.bSize+16
local by = a*self.bSize+16
batch:sprite(self.name, bx, by)
end
end
popMatrix()
end

Is there an easy way to get the coordinates (from bx, by) after the rotation?

Not completely clear what you are asking, but it sounds like seperate from drawing you want to know the actual screen coordinates of bx,by, rather than at the moment you have translated and rotated the coordinate space and then drawn them locally to that…

It would be nice if there was a way to return the current angle and translation (and maybe there is, but I’ve never spotted it). As it stands, I find myself frequently pushing and popping the matrix to ensure that I know what my starting angle is before doing another rotation.

.@Mark You can get the current transformation matrix. local m = modelMatrix() returns that (though you might also want to get the viewMatrix() and projectionMatrix() if you truly want to get the screen coordinates). From that you can read off the translation vector and the general transformation, but it won’t necessarily be a simple rotation matrix.

If you know that all you’ve done are 2D rotations, then you could work out what the rotation angle is from the matrix by using inverse tangent of the first two values.

Thanks, Andrew, for giving me one of those head-slapping “oh boy, I’m an idiot because I knew that was there” moments.

In this case, I’m just tossing around all the little 2D actors in “Bull Puckey,” all of whom are potentially spinning, shrinking/growing, and moving around. I have to think that it’s less expensive to work from the existing rotation / translation rather than resetting the matrix between each draw. At the moment, I don’t seem to be performance bound, but as I work toward some puzzles with more elements, I don’t want to get in a position where I have to simplify the layout just to keep framecount in reason.

On the other hand, I would guess that working out the rotation from the existing matrix is more expensive than resetting it.

An alternative would be to wrap the rotate function in something that implemented its own save stack to keep track of the explicit rotation in force. But even then, I’d judge resetMatrix() to be pretty darned fast.

I’m use pushMatrix, translate and rotate draw popMatrix in my 2000 squares dropping thing, and that got poor performance, partly due to physics, but definitely to do with push/pop and drawing…

I did some workaround of putting stationary objects into a sprite which fixes it, but it does 50-100 happily, but get’s slow quick after that.

Dont know if I understand correctly,mbut I sometimes use these function to get the current translate, rotate and scale values:

function pos()
local m = modelMatrix()
return m[13], m[14]
end
function rot()
local m = modelMatrix()
return math.atan2(m[2],m[1])
end
function scl()
local m = modelMatrix()
return math.sqrt(m[1]*m[1]+m[2]*m[2]+m[3]*m[3])
end

.@tnlogy If all you are doing are 2D transformations (and your scales are homogeneous in that you only ever call scale(<number> ) and never scale(<number 1>,<number 2> )) then your scl function could be simplified to just return m[11]/m[16].

If you aren’t keeping to those rules then you can’t condense the model matrix to a single rotation, scale, and translation.