using CurrentTouch in conjunction with translate() and scale()

I’m using translate() and scale() to change the coordinate system before I draw. However, when I get CurrentTouch.x & y, they come back in the default coordinate system.

So, I’m trying to decide whether I think that’s a bug, and that CurrentTouch should come back in the current coordinate system. Or, perhaps it is better as-is, and there should be a new function (e.g. “Transform()”) that will transform coordinates from the default to the current mappings (and another function to go in the other direction).



I ran into this today … here’s my 2øre.

I think I’d go for an “apply current transform” and that by default the touch information should be untransformed. I think it’s easier to apply a transform than unapply it (inverting matrices is yukky) and I can see that there are times when I’d want the transformed data and times when I wouldn’t.

If you update the x and y coordinate within the following condition I think it may resolve your issue.

if FcurrentTouch.State == BEGAN or currentTouch.State == MOVING then x = currentTouch.x y = currentTouch.y end

Then you can use this x and y value for translate() function.
Hope it will solve your problem.

This isn’t a bug. Touch coordinates are always given in view space, not model space. However we could look at adding some convenience functions like convertPointToWorld( vec2 ) that could return the a point in model space using the current transform matrix.

Thanks Simeon…convertPointToWorld (and convertWorldToPoint) would be helpful!

Or simply currentTouch.transformedx and currentTouch.transformedy?

Hmmm. Maybe just exposing the transform matrix? There’s a part of me that wants to get nutty and do “matrix = currenttransform * mytransform”. You want to mirror/rotate/skew/whatever? WHAM! Done…

A matrix class would make a nice addition, as well as an applyMatrix() function. I think these are features that will make it in sooner rather than later.

Incidentally, when doing something like keeping track of the current transform, I recommend keeping track both of the transform and its inverse. The reason being that inverting an arbitrary matrix is not something that’s nice to do, but inverting rotations, shears, and reflections is really easy. So each time you update the transform, you can easily update its inverse, saving you considerable time if you actually need that inverse.