Zoom in/out state management
<p>I am new in Android. I am working on opengl for 2 weeks and now stucked at one point. I am able to drag the 3d image at single finger touch and zoom in/out with 2 finger touch. But  after one touch, when Second time start to zoom then it is not rendering the image from the previous state but it is first zooming the 3d object and then start zoom in/out.</p>

<p>Here is my code. Plz have a look on it..</p>

<pre><code>public class AnimateActivity extends RendererActivity 
{
Object3dContainer objModel;




// touch events
    private final int NONE = 0;
    private final int DRAG = 0;
    private final int ZOOM = 0;

    // pinch to zoom
    float oldDist = 100.0f;
    float newDist;

    int mode = 0;

    private float mPreviousX;
    private float mPreviousY;
    private final float TOUCH_SCALE_FACTOR = 180.0f / 320;

    private GLSurfaceView mGLSurfaceView;

    Renderer renderer;
@Override
public void initScene() {

    scene.lights().add(new Light());

    IParser parser = Parser.createParser(Parser.Type.OBJ,
            getResources(),"com.example.magic3d:raw/camaro_obj", true);
    parser.parse();

    //mGLSurfaceView=new GLSurfaceView(this);
    objModel = parser.getParsedObject();
//  objModel.scale().x = objModel.scale().y = objModel.scale().z = .8f;
    objModel.scale().x = objModel.scale().y = objModel.scale().z = .8f;
    scene.addChild(objModel);
    scene.backgroundColor().setAll(Color.WHITE);
    renderer=new Renderer(scene);
}

@Override
public void updateScene() {
    /*objModel.rotation().x++;
    objModel.rotation().z++;*/

}

public void onCreate(Bundle savedInstanceState)
{
        super.onCreate(savedInstanceState);
        mGLSurfaceView=new GLSurfaceView(this);
}

@Override public boolean onTouchEvent(MotionEvent e) {

    float x = e.getX();
    float y = e.getY();
    switch (e.getAction()) {
    case MotionEvent.ACTION_DOWN:           // one touch: drag
        Log.d("ShaderActivity", "mode=DRAG" );
        System.out.println("Action Down");
        mode = DRAG;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:   // two touches: zoom
        Log.d("ShaderActivity", "mode=ZOOM" );
        System.out.println("Action zoom");
        oldDist = spacing(e);
        if (oldDist &gt; 10.0f) {
            mode = ZOOM; // zoom
        }
        break;
    case MotionEvent.ACTION_UP:     // no mode
        mode = NONE;
        System.out.println("Action up");
        Log.d("ShaderActivity", "mode=NONE" );
        oldDist = 100.0f;
        break;
    case MotionEvent.ACTION_POINTER_UP:     // no mode
        mode = NONE;
        Log.d("ShaderActivity", "mode=NONE" );
        oldDist = 100.0f;
        break;
    case MotionEvent.ACTION_MOVE:   
        System.out.println("Action Move");
        // rotation
        if (e.getPointerCount() &gt; 1 &amp;&amp; mode == ZOOM) {
            newDist = spacing(e);
            Log.d("SPACING: ", "OldDist: " + oldDist + ", NewDist: " + newDist);
            if (newDist &gt; 15.0f) {
                float scale = newDist/oldDist; // scale
                // scale in the renderer
                renderer.changeScale(scale);
                objModel.scale().x =renderer.scaleX; 
                        objModel.scale().y = renderer.scaleY ;
                                objModel.scale().z =renderer.scaleZ;

                oldDist = newDist;
            }
        }
        else if (mode == DRAG){
     float dx = x - mPreviousX;
     float dy = y - mPreviousY;
     renderer.mAngleX += dx * TOUCH_SCALE_FACTOR;
      renderer.mAngleY += dy * TOUCH_SCALE_FACTOR;
                //mGLSurfaceView.requestRender();
    updateScene();
                objModel.rotation().x=renderer.mAngleY;
                objModel.rotation().y=renderer.mAngleX;
    //            objModel.rotation().z=
           //Toast.makeText(getApplicationContext(), "action move downl", Toast.LENGTH_SHORT).show();
       //   updateScene();
        }
    }
    mPreviousX = x;
    mPreviousY = y;
    return true;
}
    // finds spacing
    private float spacing(MotionEvent event) {
        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        return FloatMath.sqrt(x * x + y * y);
    }
</code></pre>

<p>}</p>

<p>Thanks....</p>
