Edited to better explain my problem
I am trying to perform a zoom operation using my custom view (not UIView). The view has translation, scale, rotate values. I use these as follows, between calls to glPushMatrix() and glPopMatrix().
- (void)transform
{
glTranslatef(translation.x + anchor.x, translation.y + anchor.y, 0.0f);
//glRotatef(-rotation * 57.2957795f, 0.0f, 0.0f, 1.0f);
glScalef(scale.x, scale.y, 1.0f);
glTranslatef(-anchor.x, -anchor.y, 0.0f);
}
I am trying to figure out how I should modify the anchor and/or translation values so that the zoom operation is relative to what appears on screen. At 1:1 scale I can simply use the raw screen coordinates as the anchor and perform the above transform. But when the view is already at some arbitrary scale/position, the anchor and/or translation needs to account for that.
So far this is what I've figured out:
1) Get the displacement from the center of scale to the view origin, in screen coordinates.
2) Scale this value so it's in the view's local coordinate system.
3) Now I have the new anchor for scaling. I set the view's anchor to this value.
This alone is not enough it seems. I think I am missing a translation component, or another variable that goes into the new anchor point. What am I missing?