UIGestureRecogniser– I need help with an issue

Discussion in 'iOS Programming' started by adildacoolset, Mar 12, 2013.

  1. adildacoolset macrumors 65816

    Joined:
    Sep 5, 2011
    Location:
    Lusaka, Zambia(If you know where it is)
    #1
    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?
     
  2. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    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.
     
  3. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #3
    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;
    
     
  4. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
  5. adildacoolset thread starter macrumors 65816

    Joined:
    Sep 5, 2011
    Location:
    Lusaka, Zambia(If you know where it is)
    #5
    Ok thanks you guys. I tried it and it solves the issue.
     

Share This Page