Search in sources :

Example 21 with TouchEvent

use of com.jme3.input.event.TouchEvent in project jmonkeyengine by jMonkeyEngine.

the class IosTouchHandler method actionMove.

public void actionMove(int pointerId, long time, float x, float y) {
    float jmeX = iosInput.getJmeX(x);
    float jmeY = iosInput.invertY(iosInput.getJmeY(y));
    Vector2f lastPos = lastPositions.get(pointerId);
    if (lastPos == null) {
        lastPos = new Vector2f(jmeX, jmeY);
        lastPositions.put(pointerId, lastPos);
    }
    float dX = jmeX - lastPos.x;
    float dY = jmeY - lastPos.y;
    if (dX != 0 || dY != 0) {
        TouchEvent touch = iosInput.getFreeTouchEvent();
        touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
        touch.setPointerId(pointerId);
        touch.setTime(time);
        touch.setPressure(1.0f);
        //touch.setPressure(event.getPressure(p));
        lastPos.set(jmeX, jmeY);
        processEvent(touch);
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) TouchEvent(com.jme3.input.event.TouchEvent)

Example 22 with TouchEvent

use of com.jme3.input.event.TouchEvent in project jmonkeyengine by jMonkeyEngine.

the class TouchEventPool method getNextFreeEvent.

/**
     * Fetches a touch event from the reuse pool
     *
     * @return a usable TouchEvent
     */
public TouchEvent getNextFreeEvent() {
    TouchEvent evt = null;
    int curSize = eventPool.size();
    while (curSize > 0) {
        evt = (TouchEvent) eventPool.pop();
        if (evt.isConsumed()) {
            break;
        } else {
            eventPool.push(evt);
            evt = null;
        }
        curSize--;
    }
    if (evt == null) {
        logger.warning("eventPool full of unconsumed events");
        evt = new TouchEvent();
    }
    return evt;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Aggregations

TouchEvent (com.jme3.input.event.TouchEvent)20 Vector2f (com.jme3.math.Vector2f)4 InputEvent (com.jme3.input.event.InputEvent)2 KeyInputEvent (com.jme3.input.event.KeyInputEvent)2 MouseButtonEvent (com.jme3.input.event.MouseButtonEvent)2 MouseMotionEvent (com.jme3.input.event.MouseMotionEvent)2