Search in sources :

Example 1 with MotionEvent

use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.

the class MotionPath method interpolatePath.

/**
     * interpolate the path giving the time since the beginning and the motionControl     
     * this methods sets the new localTranslation to the spatial of the MotionEvent control.
     * @param time the time since the animation started
     * @param control the control over the moving spatial
     */
public float interpolatePath(float time, MotionEvent control, float tpf) {
    float traveledDistance = 0;
    TempVars vars = TempVars.get();
    Vector3f temp = vars.vect1;
    Vector3f tmpVector = vars.vect2;
    Vector2f v = vars.vect2d;
    //computing traveled distance according to new time
    traveledDistance = time * (getLength() / control.getInitialDuration());
    //getting waypoint index and current value from new traveled distance
    v = getWayPointIndexForDistance(traveledDistance, v);
    //setting values
    control.setCurrentWayPoint((int) v.x);
    control.setCurrentValue(v.y);
    //interpolating new position
    getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
    if (control.needsDirection()) {
        tmpVector.set(temp);
        control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
    }
    checkWayPoint(control, tpf);
    control.getSpatial().setLocalTranslation(temp);
    vars.release();
    return traveledDistance;
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 2 with MotionEvent

use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.

the class AndroidGestureProcessor method onShowPress.

@Override
public void onShowPress(MotionEvent event) {
    //        logger.log(Level.INFO, "onShowPress 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.SHOWPRESS, jmeX, jmeY, 0, 0);
    touchEvent.setPointerId(touchInput.getPointerId(event));
    touchEvent.setTime(event.getEventTime());
    touchEvent.setPressure(event.getPressure());
    touchInput.addEvent(touchEvent);
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 3 with MotionEvent

use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.

the class AndroidGestureProcessor method onDoubleTap.

@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;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 4 with MotionEvent

use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.

the class AndroidJoystickJoyInput14 method onGenericMotion.

public boolean onGenericMotion(MotionEvent event) {
    boolean consumed = false;
    //        logger.log(Level.INFO, "onGenericMotion event: {0}", event);
    event.getDeviceId();
    event.getSource();
    //        logger.log(Level.INFO, "deviceId: {0}, source: {1}", new Object[]{event.getDeviceId(), event.getSource()});
    AndroidJoystick joystick = joystickIndex.get(event.getDeviceId());
    if (joystick != null) {
        for (int androidAxis : joystick.getAndroidAxes()) {
            String axisName = MotionEvent.axisToString(androidAxis);
            float value = event.getAxisValue(androidAxis);
            int action = event.getAction();
            if (action == MotionEvent.ACTION_MOVE) {
                //                    logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}",
                //                            new Object[]{androidAxis, axisName, value});
                JoystickAxis axis = joystick.getAxis(androidAxis);
                if (axis != null) {
                    //                        logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}, deadzone: {3}",
                    //                                new Object[]{androidAxis, axisName, value, axis.getDeadZone()});
                    JoyAxisEvent axisEvent = new JoyAxisEvent(axis, value);
                    joyInput.addEvent(axisEvent);
                    consumed = true;
                } else {
                //                        logger.log(Level.INFO, "axis was null for axisName: {0}", axisName);
                }
            } else {
            //                    logger.log(Level.INFO, "action: {0}", action);
            }
        }
    }
    return consumed;
}
Also used : JoyAxisEvent(com.jme3.input.event.JoyAxisEvent) JoystickAxis(com.jme3.input.JoystickAxis) DefaultJoystickAxis(com.jme3.input.DefaultJoystickAxis)

Example 5 with MotionEvent

use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.

the class AndroidGestureProcessor method onFling.

@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;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Aggregations

TouchEvent (com.jme3.input.event.TouchEvent)9 Vector3f (com.jme3.math.Vector3f)5 MotionPath (com.jme3.cinematic.MotionPath)4 MotionEvent (com.jme3.cinematic.events.MotionEvent)3 Vector2f (com.jme3.math.Vector2f)3 CameraNode (com.jme3.scene.CameraNode)3 MotionPathListener (com.jme3.cinematic.MotionPathListener)2 BitmapText (com.jme3.font.BitmapText)2 ChaseCamera (com.jme3.input.ChaseCamera)2 AnimControl (com.jme3.animation.AnimControl)1 AnimationFactory (com.jme3.animation.AnimationFactory)1 Cinematic (com.jme3.cinematic.Cinematic)1 AnimationEvent (com.jme3.cinematic.events.AnimationEvent)1 DefaultJoystickAxis (com.jme3.input.DefaultJoystickAxis)1 JoystickAxis (com.jme3.input.JoystickAxis)1 JoyAxisEvent (com.jme3.input.event.JoyAxisEvent)1 Quaternion (com.jme3.math.Quaternion)1 TempVars (com.jme3.util.TempVars)1