Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

adildacoolset

macrumors 65816
Original poster
Hello all,

I'm having a bit of trouble with a pan gesture recognizer. I'm making an OpenGL ES app and I intend t use the pan gestures recognizer for swiveling the 3D camera.

So far, I have this code:
Code:
- (IBAction)handlePans:(UIPanGestureRecognizer *)recogniser {
    
    CGPoint translation = [recogniser translationInView:self.view];
    //self.xRotation is a float which will represent the angle.
    self.xRotation = translation.x

    if (recogniser.state == UIGestureRecognizerStateChanged) {
        
        _xFinalCameraPoint = //This the the X value of the camera
        (4 *  sin(GLKMathDegreesToRadians(self.xRotation)));
        
        _zFinalCameraPoint = //This is the Z value of the camera
        (4 * cos(GLKMathDegreesToRadians(self.xRotation)));
        
        
    }
  
}

The issue is that the translation variable always resets, as it's declared within the method. So the position of the camera always resets whenever the user lets go and pans again. So how can I use the same translation, but with the new translation added on?
 
You just need the pull your stored value from self.xRotation and add it to the translation.x value before you set the camera angle.

You can use the += modifier.
 
You just need the pull your stored value from self.xRotation and add it to the translation.x value before you set the camera angle.

You can use the += modifier.

So to expand that you basically want to set self.xRotation = self.xRotation + translation.x

this can be shortened to

Code:
self.xRotation += translation.x;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.