j-rewerts / min3d

Automatically exported from code.google.com/p/min3d
0 stars 0 forks source link

Adding OnTouchListener to detect ACTION_MOVE #48

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
if I create a OnTouchListener inside my activity extending RendererActivity 
like this:

OnTouchListener myTouchListener = new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    // my code...
  }
};

and I set it on _glSurfaceView inside onCreate method like this:
_glSurfaceView.setOnTouchListener(myTouchListener);

I receive the touch event but not the move, e.g.:
if(event.getAction() == MotionEvent.ACTION_MOVE) {
  // do something....
}

how's that?
is there a better place to listen for touch events?
should I set something on min3d itself?

Thanks for your help.

Original issue reported on code.google.com by castigli...@altasis.it on 7 Jun 2011 at 3:44

GoogleCodeExporter commented 9 years ago
Hello dude I solve that question chek:

@Override
    public boolean onTouchEvent(MotionEvent event){ 

        if (event.getAction() == MotionEvent.ACTION_DOWN)
        {

            touchedX = event.getX();
            touchedY = event.getY();

        } else if (event.getAction() == MotionEvent.ACTION_MOVE)
        {
            objModel.rotation().z -= (touchedX - event.getX())/2f;
            objModel.rotation().x -= (touchedY - event.getY())/2f;

            try {

                float ok=spacing(event);                
                planePosition += (event.getY() - touchedY) * 0.01f;

                if(planePosition <= maxScal){
                objModel.scale().x = objModel.scale().y = objModel.scale().z = planePosition;
                }else{
                    objModel.scale().x = objModel.scale().y = objModel.scale().z = 1f;
                }

                if(planePosition >= minScal){
                objModel.scale().x = objModel.scale().y = objModel.scale().z = planePosition;
                }else{                  
                    System.out.println("Se ha salido del rango");
                    objModel.scale().x = objModel.scale().y = objModel.scale().z = .1f;
                }               
            } catch (Exception e) {

            }

            touchedX = event.getX();
            touchedY = event.getY();

        }           
        return true;    
    }

    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);
        }

In other class where you call RenderActivity.java you need to put this code and 
it works for me very well.

Original comment by Armando....@gmail.com on 1 May 2013 at 6:11