use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.
the class AndroidGestureProcessor method onSingleTapConfirmed.
/* Events from onDoubleTapListener */
@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;
}
use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.
the class AndroidTouchInput method onTouch.
public boolean onTouch(MotionEvent event) {
if (!isInitialized()) {
return false;
}
boolean bWasHandled = false;
TouchEvent touch = null;
// System.out.println("native : " + event.getAction());
int action = getAction(event);
int pointerIndex = getPointerIndex(event);
int pointerId = getPointerId(event);
Vector2f lastPos = lastPositions.get(pointerId);
float jmeX;
float jmeY;
numPointers = event.getPointerCount();
//final int pointerCount = event.getPointerCount();
switch(getAction(event)) {
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_DOWN:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touch = getFreeTouchEvent();
touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
touch.setPointerId(pointerId);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(pointerIndex));
lastPos = new Vector2f(jmeX, jmeY);
lastPositions.put(pointerId, lastPos);
addEvent(touch);
addEvent(generateMouseEvent(touch));
bWasHandled = true;
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touch = getFreeTouchEvent();
touch.set(TouchEvent.Type.UP, jmeX, jmeY, 0, 0);
touch.setPointerId(pointerId);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(pointerIndex));
lastPositions.remove(pointerId);
addEvent(touch);
addEvent(generateMouseEvent(touch));
bWasHandled = true;
break;
case MotionEvent.ACTION_MOVE:
// Convert all pointers into events
for (int p = 0; p < event.getPointerCount(); p++) {
jmeX = getJmeX(event.getX(p));
jmeY = invertY(getJmeY(event.getY(p)));
lastPos = lastPositions.get(event.getPointerId(p));
if (lastPos == null) {
lastPos = new Vector2f(jmeX, jmeY);
lastPositions.put(event.getPointerId(p), lastPos);
}
float dX = jmeX - lastPos.x;
float dY = jmeY - lastPos.y;
if (dX != 0 || dY != 0) {
touch = getFreeTouchEvent();
touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
touch.setPointerId(event.getPointerId(p));
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(p));
lastPos.set(jmeX, jmeY);
addEvent(touch);
addEvent(generateMouseEvent(touch));
bWasHandled = true;
}
}
break;
case MotionEvent.ACTION_OUTSIDE:
break;
}
// Try to detect gestures
if (gestureDetector != null) {
gestureDetector.onTouchEvent(event);
}
if (scaleDetector != null) {
scaleDetector.onTouchEvent(event);
}
return bWasHandled;
}
use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.
the class AndroidTouchInput14 method onHover.
public boolean onHover(MotionEvent event) {
boolean consumed = false;
int action = getAction(event);
int pointerId = getPointerId(event);
int pointerIndex = getPointerIndex(event);
Vector2f lastPos = lastHoverPositions.get(pointerId);
float jmeX;
float jmeY;
numPointers = event.getPointerCount();
// logger.log(Level.INFO, "onHover pointerId: {0}, action: {1}, x: {2}, y: {3}, numPointers: {4}",
// new Object[]{pointerId, action, event.getX(), event.getY(), event.getPointerCount()});
TouchEvent touchEvent;
switch(action) {
case MotionEvent.ACTION_HOVER_ENTER:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touchEvent = getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.HOVER_START, jmeX, jmeY, 0, 0);
touchEvent.setPointerId(pointerId);
touchEvent.setTime(event.getEventTime());
touchEvent.setPressure(event.getPressure(pointerIndex));
lastPos = new Vector2f(jmeX, jmeY);
lastHoverPositions.put(pointerId, lastPos);
addEvent(touchEvent);
consumed = true;
break;
case MotionEvent.ACTION_HOVER_MOVE:
// Convert all pointers into events
for (int p = 0; p < event.getPointerCount(); p++) {
jmeX = getJmeX(event.getX(p));
jmeY = invertY(getJmeY(event.getY(p)));
lastPos = lastHoverPositions.get(event.getPointerId(p));
if (lastPos == null) {
lastPos = new Vector2f(jmeX, jmeY);
lastHoverPositions.put(event.getPointerId(p), lastPos);
}
float dX = jmeX - lastPos.x;
float dY = jmeY - lastPos.y;
if (dX != 0 || dY != 0) {
touchEvent = getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.HOVER_MOVE, jmeX, jmeY, dX, dY);
touchEvent.setPointerId(event.getPointerId(p));
touchEvent.setTime(event.getEventTime());
touchEvent.setPressure(event.getPressure(p));
lastPos.set(jmeX, jmeY);
addEvent(touchEvent);
}
}
consumed = true;
break;
case MotionEvent.ACTION_HOVER_EXIT:
jmeX = getJmeX(event.getX(pointerIndex));
jmeY = invertY(getJmeY(event.getY(pointerIndex)));
touchEvent = getFreeTouchEvent();
touchEvent.set(TouchEvent.Type.HOVER_END, jmeX, jmeY, 0, 0);
touchEvent.setPointerId(pointerId);
touchEvent.setTime(event.getEventTime());
touchEvent.setPressure(event.getPressure(pointerIndex));
lastHoverPositions.remove(pointerId);
addEvent(touchEvent);
consumed = true;
break;
default:
consumed = false;
break;
}
return consumed;
}
use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.
the class TestCameraMotionPath method simpleInitApp.
@Override
public void simpleInitApp() {
createScene();
cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
camNode = new CameraNode("Motion cam", cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
camNode.setEnabled(false);
path = new MotionPath();
path.setCycle(true);
path.addWayPoint(new Vector3f(20, 3, 0));
path.addWayPoint(new Vector3f(0, 3, 20));
path.addWayPoint(new Vector3f(-20, 3, 0));
path.addWayPoint(new Vector3f(0, 3, -20));
path.setCurveTension(0.83f);
path.enableDebugShape(assetManager, rootNode);
cameraMotionControl = new MotionEvent(camNode, path);
cameraMotionControl.setLoopMode(LoopMode.Loop);
//cameraMotionControl.setDuration(15f);
cameraMotionControl.setLookAt(teapot.getWorldTranslation(), Vector3f.UNIT_Y);
cameraMotionControl.setDirectionType(MotionEvent.Direction.LookAt);
rootNode.attachChild(camNode);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
final BitmapText wayPointsText = new BitmapText(guiFont, false);
wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
guiNode.attachChild(wayPointsText);
path.addListener(new MotionPathListener() {
public void onWayPointReach(MotionEvent control, int wayPointIndex) {
if (path.getNbWayPoints() == wayPointIndex + 1) {
wayPointsText.setText(control.getSpatial().getName() + " Finish!!! ");
} else {
wayPointsText.setText(control.getSpatial().getName() + " Reached way point " + wayPointIndex);
}
wayPointsText.setLocalTranslation((cam.getWidth() - wayPointsText.getLineWidth()) / 2, cam.getHeight(), 0);
}
});
flyCam.setEnabled(false);
chaser = new ChaseCamera(cam, teapot);
chaser.registerWithInput(inputManager);
chaser.setSmoothMotion(true);
chaser.setMaxDistance(50);
chaser.setDefaultDistance(50);
initInputs();
}
use of com.jme3.cinematic.events.MotionEvent in project jmonkeyengine by jMonkeyEngine.
the class TestJaime method setupCinematic.
public void setupCinematic(final Node jaime) {
cinematic = new Cinematic(rootNode, 60);
stateManager.attach(cinematic);
jaime.move(0, 0, -3);
AnimationFactory af = new AnimationFactory(0.7f, "JumpForward");
af.addTimeTranslation(0, new Vector3f(0, 0, -3));
af.addTimeTranslation(0.35f, new Vector3f(0, 1, -1.5f));
af.addTimeTranslation(0.7f, new Vector3f(0, 0, 0));
jaime.getControl(AnimControl.class).addAnim(af.buildAnimation());
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", 3, LoopMode.DontLoop));
float jumpStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpStart", LoopMode.DontLoop));
cinematic.addCinematicEvent(jumpStart + 0.2f, new AnimationEvent(jaime, "JumpForward", LoopMode.DontLoop, 1));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpEnd", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Punches", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "SideKick", LoopMode.DontLoop));
float camStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Taunt", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", 1, LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Wave", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", LoopMode.DontLoop));
CameraNode camNode = cinematic.bindCamera("cam", cam);
camNode.setLocalTranslation(new Vector3f(1.1f, 1.2f, 2.9f));
camNode.lookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
MotionPath path = new MotionPath();
path.addWayPoint(new Vector3f(1.1f, 1.2f, 2.9f));
path.addWayPoint(new Vector3f(0f, 1.2f, 3.0f));
path.addWayPoint(new Vector3f(-1.1f, 1.2f, 2.9f));
path.enableDebugShape(assetManager, rootNode);
path.setCurveTension(0.8f);
MotionEvent camMotion = new MotionEvent(camNode, path, 6);
camMotion.setDirectionType(MotionEvent.Direction.LookAt);
camMotion.setLookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
cinematic.addCinematicEvent(camStart, camMotion);
cinematic.activateCamera(0, "cam");
cinematic.fitDuration();
cinematic.setSpeed(1.2f);
cinematic.setLoopMode(LoopMode.Loop);
cinematic.play();
}
Aggregations