Jump to content

  • Log In with Google      Sign In   
  • Create Account


riens

Member Since 23 Apr 2012
Offline Last Active May 17 2012 02:17 AM

Topics I've Started

Zooming and swiping with OpenGL ES

23 April 2012 - 05:10 AM

Hello!
I am making a 2D puzzle for iOS and currently I`m trying to implement zooming and scrolling with UIPinchGestureRecognizer.
Zooming is done this way: I have a target 2D vector which is a "zooming point". The code is:
glTranslatef(target.x, target.y, 0);
glScalef(scale, scale, 0);
glTranslatef(-target.x, -target.y, 0);

Target is being selected with gesture recognizer this way:
-(void)handlePinchGesture:(UIPinchGestureRecognizer*)recognizer
{
	if (UIGestureRecognizerStateBegan == [recognizer state])
	{
		view->setTarget([recognizer locationInView:self]);
	}
	// Rest of the code omitted
}

Everything works just fine.
Initially the game was designed for iPAD, but I want it to work on iPhone and iPOD too. But iPhone and iPOD have different aspect ratio. To keep initial picture proportions I decided to make initial Y scale a bit bigger. Also this made possible to swipe the game field up and down with initial zoom factor. The code is:
glTranslatef(target.x, target.y, 0);
glScalef(scale, scale * aspectRatio, 0);
glTranslatef(-target.x, -target.y, 0);

This works just fine IF the game field is "centered" at the screen(e.g. when there are equal space in bot swipe directions(up and down)). But if we swipe the field up or down and begin pinch gesture, the game field jumps to the centre again.
I understand that I need to translate the gesture position by some offset, but I cannot figure how exactly for 3 days.

PARTNERS