Java Code Examples for com.jme3.input.event.TouchEvent#setPointerId()

The following examples show how to use com.jme3.input.event.TouchEvent#setPointerId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public boolean onScroll(MotionEvent startEvent, MotionEvent endEvent, float distX, float distY) {
        // if not scaleInProgess, send scroll events.  This is to avoid sending
        // scroll events when one of the fingers is lifted just before the other one.
        // Avoids sending the scroll for that brief period of time.
        // Return true so that the next event doesn't accumulate the distX and distY values.
        // Apparantly, both distX and distY are negative.
        // Negate distX to get the real value, but leave distY negative to compensate
        // for the fact that jME has y=0 at bottom where Android has y=0 at top.
        if (!touchInput.getScaleDetector().isInProgress()) {
//            logger.log(Level.INFO, "onScroll pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, dx: {7}, dy: {8}",
//                    new Object[]{touchInput.getPointerId(startEvent), touchInput.getAction(startEvent), startEvent.getX(), startEvent.getY(), touchInput.getAction(endEvent), endEvent.getX(), endEvent.getY(), distX, distY});

            float jmeX = touchInput.getJmeX(endEvent.getX());
            float jmeY = touchInput.invertY(touchInput.getJmeY(endEvent.getY()));
            TouchEvent touchEvent = touchInput.getFreeTouchEvent();
            touchEvent.set(TouchEvent.Type.SCROLL, jmeX, jmeY, touchInput.getJmeX(-distX), touchInput.getJmeY(distY));
            touchEvent.setPointerId(touchInput.getPointerId(endEvent));
            touchEvent.setTime(endEvent.getEventTime());
            touchEvent.setPressure(endEvent.getPressure());
            touchInput.addEvent(touchEvent);
        }
        return true;
    }
 
Example 2
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public boolean onFling(MotionEvent startEvent, MotionEvent endEvent, float velocityX, float velocityY) {
        // Fling happens only once at the end of the gesture (all fingers up).
        // Fling returns the velocity of the finger movement in pixels/sec.
        // Therefore, the dX and dY values are actually velocity instead of distance values
        // Since this does not track the movement, use the start position and velocity values.

//        logger.log(Level.INFO, "onFling pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, velocityX: {7}, velocityY: {8}",
//                new Object[]{touchInput.getPointerId(startEvent), touchInput.getAction(startEvent), startEvent.getX(), startEvent.getY(), touchInput.getAction(endEvent), endEvent.getX(), endEvent.getY(), velocityX, velocityY});

        float jmeX = touchInput.getJmeX(startEvent.getX());
        float jmeY = touchInput.invertY(touchInput.getJmeY(startEvent.getY()));
        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
        touchEvent.set(TouchEvent.Type.FLING, jmeX, jmeY, velocityX, velocityY);
        touchEvent.setPointerId(touchInput.getPointerId(endEvent));
        touchEvent.setTime(endEvent.getEventTime());
        touchEvent.setPressure(endEvent.getPressure());
        touchInput.addEvent(touchEvent);
        return true;
    }
 
Example 3
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public boolean onDoubleTap(MotionEvent event) {
        //The down motion event of the first tap of the double-tap
        // We could use this event to fire off a double tap event, or use
        // DoubleTapEvent with a check for the UP action
//        logger.log(Level.INFO, "onDoubleTap pointerId: {0}, action: {1}, x: {2}, y: {3}",
//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
        float jmeX = touchInput.getJmeX(event.getX());
        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
        touchEvent.set(TouchEvent.Type.DOUBLETAP, jmeX, jmeY, 0, 0);
        touchEvent.setPointerId(touchInput.getPointerId(event));
        touchEvent.setTime(event.getEventTime());
        touchEvent.setPressure(event.getPressure());
        touchInput.addEvent(touchEvent);
        return true;
    }
 
Example 4
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public boolean onDoubleTapEvent(MotionEvent event) {
        //Notified when an event within a double-tap gesture occurs, including the down, move(s), and up events.
        // this means it will get called multiple times for a single double tap
//        logger.log(Level.INFO, "onDoubleTapEvent pointerId: {0}, action: {1}, x: {2}, y: {3}",
//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
        if (touchInput.getAction(event) == MotionEvent.ACTION_UP) {
            TouchEvent touchEvent = touchInput.getFreeTouchEvent();
            touchEvent.set(TouchEvent.Type.DOUBLETAP, event.getX(), touchInput.invertY(event.getY()), 0, 0);
            touchEvent.setPointerId(touchInput.getPointerId(event));
            touchEvent.setTime(event.getEventTime());
            touchEvent.setPressure(event.getPressure());
            touchInput.addEvent(touchEvent);
        }
        return true;
    }
 
Example 5
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
        // Scale uses a focusX and focusY instead of x and y.  Focus is the middle
        // of the fingers.  Therefore, use the x and y values from the Down event
        // so that the x and y values don't jump to the middle position.
        // return true or all gestures for this beginning event will be discarded
//        logger.log(Level.INFO, "onScaleBegin");
        scaleStartX = gestureDownX;
        scaleStartY = gestureDownY;
        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
        touchEvent.set(TouchEvent.Type.SCALE_START, scaleStartX, scaleStartY, 0f, 0f);
        touchEvent.setPointerId(0);
        touchEvent.setTime(scaleGestureDetector.getEventTime());
        touchEvent.setScaleSpan(scaleGestureDetector.getCurrentSpan());
        touchEvent.setDeltaScaleSpan(0f);
        touchEvent.setScaleFactor(scaleGestureDetector.getScaleFactor());
        touchEvent.setScaleSpanInProgress(touchInput.getScaleDetector().isInProgress());
        touchInput.addEvent(touchEvent);

        return true;
    }
 
Example 6
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
    public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
        // return true or all gestures for this event will be accumulated
//        logger.log(Level.INFO, "onScale");
        scaleStartX = gestureDownX;
        scaleStartY = gestureDownY;
        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
        touchEvent.set(TouchEvent.Type.SCALE_MOVE, scaleStartX, scaleStartY, 0f, 0f);
        touchEvent.setPointerId(0);
        touchEvent.setTime(scaleGestureDetector.getEventTime());
        touchEvent.setScaleSpan(scaleGestureDetector.getCurrentSpan());
        touchEvent.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
        touchEvent.setScaleFactor(scaleGestureDetector.getScaleFactor());
        touchEvent.setScaleSpanInProgress(touchInput.getScaleDetector().isInProgress());
        touchInput.addEvent(touchEvent);
        return true;
    }
 
Example 7
Source File: IosTouchHandler.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void actionDown(int pointerId, long time, float x, float y) {
    logger.log(Level.FINE, "Inject input pointer: {0}, time: {1}, x: {2}, y: {3}", 
            new Object[]{pointerId, time, x, y});
    float jmeX = iosInput.getJmeX(x);
    float jmeY = iosInput.invertY(iosInput.getJmeY(y));
    TouchEvent touch = iosInput.getFreeTouchEvent();
    touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
    touch.setPointerId(pointerId);//TODO: pointer ID
    touch.setTime(time);
    touch.setPressure(1.0f);
    //touch.setPressure(event.getPressure(pointerIndex)); //TODO: preassure

    lastPositions.put(pointerId, new Vector2f(jmeX, jmeY));

    processEvent(touch);
}
 
Example 8
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean onScale(ScaleGestureDetector scaleGestureDetector)
{        
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.SCALE_MOVE, scaleGestureDetector.getFocusX(), this.getHeight() - scaleGestureDetector.getFocusY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(scaleGestureDetector.getEventTime());
    touch.setScaleSpan(scaleGestureDetector.getCurrentSpan()); 
    touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
    processEvent(touch); 
         
    return false;
}
 
Example 9
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean onSingleTapUp(MotionEvent event) 
{       
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.TAP, event.getX(), this.getHeight() - event.getY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(event.getEventTime());
    processEvent(touch);
    return true;
}
 
Example 10
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector)
{     
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.SCALE_START, scaleGestureDetector.getFocusX(), scaleGestureDetector.getFocusY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(scaleGestureDetector.getEventTime());
    touch.setScaleSpan(scaleGestureDetector.getCurrentSpan()); 
    touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
    processEvent(touch); 
    
    return true;
}
 
Example 11
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean onDoubleTap(MotionEvent event)
{
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.DOUBLETAP, event.getX(), this.getHeight() - event.getY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(event.getEventTime());
    processEvent(touch);        
    return true;
}
 
Example 12
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onShowPress(MotionEvent event) 
{
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.SHOWPRESS, event.getX(), this.getHeight() - event.getY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(event.getEventTime());
    processEvent(touch);
}
 
Example 13
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) 
{
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.SCROLL, e1.getX(), this.getHeight() - e1.getY(), distanceX, distanceY*(-1));
    touch.setPointerId(0);
    touch.setTime(e1.getEventTime());
    processEvent(touch);
    return false;
}
 
Example 14
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onLongPress(MotionEvent event)
{        
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.LONGPRESSED, event.getX(), this.getHeight() - event.getY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(event.getEventTime());
    processEvent(touch);
}
 
Example 15
Source File: GdxInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean zoom(float initialDistance, float distance) {
    System.err.println("zoom "+initialDistance+" "+distance);
    TouchEvent event = getNextFreeTouchEvent();
    event.set(TouchEvent.Type.SCALE_MOVE, initialDistance, distance, 0, 0);
    event.setPointerId(0);
    event.setTime(System.nanoTime());
    processEvent(event);
    return false;
}
 
Example 16
Source File: GdxInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    TouchEvent event = getNextFreeTouchEvent();
    event.set(TouchEvent.Type.UP, screenX, Gdx.graphics.getHeight() - screenY, 0, 0);
    event.setPointerId(pointer);
    event.setTime(System.nanoTime());
    processEvent(event);
    System.err.println("touchUp x = " + screenX + " y = " + screenY);
    return false;
}
 
Example 17
Source File: IosTouchHandler.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void actionUp(int pointerId, long time, float x, float y) {
    float jmeX = iosInput.getJmeX(x);
    float jmeY = iosInput.invertY(iosInput.getJmeY(y));
    TouchEvent touch = iosInput.getFreeTouchEvent();
    touch.set(TouchEvent.Type.UP, jmeX, jmeY, 0, 0);
    touch.setPointerId(pointerId);//TODO: pointer ID
    touch.setTime(time);
    touch.setPressure(1.0f);
    //touch.setPressure(event.getPressure(pointerIndex)); //TODO: preassure
    lastPositions.remove(pointerId);

    processEvent(touch);
}
 
Example 18
Source File: AndroidInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onScaleEnd(ScaleGestureDetector scaleGestureDetector)
{        
    TouchEvent touch = getNextFreeTouchEvent(); 
    touch.set(Type.SCALE_END, scaleGestureDetector.getFocusX(), this.getHeight() - scaleGestureDetector.getFocusY(), 0f, 0f);
    touch.setPointerId(0);
    touch.setTime(scaleGestureDetector.getEventTime());
    touch.setScaleSpan(scaleGestureDetector.getCurrentSpan()); 
    touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
    processEvent(touch);      
}
 
Example 19
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public boolean onSingleTapConfirmed(MotionEvent event) {
        // Up of single tap when no double tap followed.
//        logger.log(Level.INFO, "onSingleTapConfirmed pointerId: {0}, action: {1}, x: {2}, y: {3}",
//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
        float jmeX = touchInput.getJmeX(event.getX());
        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
        touchEvent.set(TouchEvent.Type.TAP, jmeX, jmeY, 0, 0);
        touchEvent.setPointerId(touchInput.getPointerId(event));
        touchEvent.setTime(event.getEventTime());
        touchEvent.setPressure(event.getPressure());
        touchInput.addEvent(touchEvent);
        return true;
    }
 
Example 20
Source File: AndroidGestureProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void onLongPress(MotionEvent event) {
//        logger.log(Level.INFO, "onLongPress pointerId: {0}, action: {1}, x: {2}, y: {3}",
//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
        float jmeX = touchInput.getJmeX(event.getX());
        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
        touchEvent.set(TouchEvent.Type.LONGPRESSED, jmeX, jmeY, 0, 0);
        touchEvent.setPointerId(touchInput.getPointerId(event));
        touchEvent.setTime(event.getEventTime());
        touchEvent.setPressure(event.getPressure());
        touchInput.addEvent(touchEvent);
    }