Taking a Leap Forward With JavaFX

39
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 1
  • date post

    18-Oct-2014
  • Category

    Technology

  • view

    2.159
  • download

    3

description

This is the Leap Motion and JavaFX session I presented at JavaOne 2013

Transcript of Taking a Leap Forward With JavaFX

Page 1: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1

Page 2: Taking a Leap Forward With JavaFX

Taking A Leap Forward With JavaFXSimon Ritter, Oracle CorporationGerrit Grunwald, Canoo Engineering AGJohan Vos, LodgonJosé Pereda, Universidad de Valladolid

Page 3: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Page 4: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4

Program Agenda

The Man Machine Interface

Leap Motion Controller

JavaFX Basics and 3D

Leap Motion Java API

Demos

Page 5: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5

The Man Machine Interface

Page 6: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6

How It All Started

Page 7: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7

Progress was made…

Page 8: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8

Multi-touch has become popular

Page 9: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9

Gaming Has Driven Several Interfaces

Page 10: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10

Now It’s About Gestures

Page 11: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11

The Leap Motion Controller

Page 12: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12

The Basics

Small device (80 x 30 x 12mm) USB connection

– No external power required

Multiple OS support– Windows

– Mac OSX

– Linux

Low cost: $80

Page 13: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13

The Technology

Array of infra-red sensors– Can be susceptible to bright light

Proprietary motion detection algorithm– Tracks to 0.01mm resolution

– The secret sauce

1-2% CPU load No GPU requirement

Page 14: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14

The Details

The Leap Motion sensor detects hands, fingers and tools Data captured as frames continuously Listener handles events from frames Controller is the connection between device and application Gesture recognition must be enabled through the controller

Page 15: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15

Leap Motion Java APICo-ordinate System

Right hand Cartesian co-ordinate system

Page 16: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16

60cm range 150° view angle (left/right) 120° view angle (front/back)

Field Of View

Page 17: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17

Gestures

Predefined gestures– Circle

– Swipe

– Key tap (downward movement: y-axis)

– Screen tap (forward movement: z-axis)

Turn, twist, tilt, make a fist– Use motion factors from frame

Translation, rotation axis, rotation angle, scale factor

Page 18: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18

JavaFX Basics and 3D

Page 19: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19

JavaFX: The New Way To Build Java UIs

Page 20: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20

Scene Graph

Directed Acyclic Graph Parents and children Representation of the GUI components

Page 21: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21

Binding

Creates a dependency between a property and a changeable value

High level API– Easy to use

– Covers most common situations

Low level API– Allows for more complex interactions

– Optimised for fast execution and small footprint

Page 22: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22

Properties

Basis for high level binding API Concrete types for all primitives, String and Object

– DoubleProperty, StringProperty, etc

Simple API– bind / unbind– bindBidirectional / unbindBidirectional– isBound

Page 23: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23

Timeline Based Animations

Timeline– Modifies values of variables specified in KeyFrames

KeyFrame: specifies that a variable should have– A particular value at a particular time

KeyValue: Value to be interpolated for an interval

Page 24: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24

Animated Transitions

Pre-defined, single-purpose animations– Fade, Path, Pause, Rotate, Scale, Translate

– Can specify to, from and by values

Container transitions– Parallel, sequential

– Can be nested arbitarily

Transitions and Timelines share ancestary– A Timeline can be added to a Parallel / Sequential transition

Page 25: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25

JavaFX And The Third Dimension

Basic collection of 3D shapes– Box

– Cylinder

– Sphere

– MeshView (everything else)

javafx.scene.shape

Shapes

Page 26: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26

JavaFX And The Third Dimension

PhongMaterial– Way to cover a 3D object in a colour or image

– Uses interpolation to smooth polygon effects

Surfaces

Page 27: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27

JavaFX And The Third Dimension

How to illuminate the scene javafx.scene.effect.LightBase AmbientLight

– A light source that seems to come from all directions

PointLight– An attenuated light source that has a fixed point in space and radiates light

equally away from itself in all directions

Lighting

Page 28: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28

JavaFX And The Third Dimension

Where the scene is viewed from PerspectiveCamera

– Field of view is configurable (default is 30°)

ParallelCamera– Renders a scene without perspective correction

Cameras

Page 29: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29

Leap Motion Java API

Page 30: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30

Interaction Principles

Frame

Application Code

Listener

GUI Node

GUI Node

GUI Node

Controller

LeapMotion

Page 31: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31

Basic Approach

Create Controller Register Listener

– Subclass to implement specific functionality

onFrame callback method in Listener called by Controller Or you can use polling Frame contains all data

– Hand position, orientation

– Fingers

– Pointer position, orientation

Page 32: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32

Frame By Frame

Set of hand and finger tracking data detected at a point in time Hand provides:

– Direction of palm

– List of visible Fingers

Finger (which is a subclass of Pointable) provides:– Direction

– Tip position and velocity

– Length, width

– Time visible

Page 33: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33

Handling Gestures

Enable the gestures you want to use Recognised gesture data is added to the Frame

GestureList gl = frame.gestures();

for (int i = 0; i < gl.count(); i++) { Gesture g = gl.get(i); if (g.type == TYPE_SWIPE) SwipeGesture sw = new SwipeGesture(g);

...

Page 34: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34

Conclusions and More Information

Page 35: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35

Conclusions

Leap Motion adds a great new way to interact with applications Java support makes integration with existing applications simple

– Clean, straightforward API

– Simple gesture recognition

Use your imagination!

Page 36: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36

Further Information

www.leapmotion.com www.oracle.com/javafx jperedadnr.blogspot.co.uk blogs.oracle.com/speakjava

Page 37: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37

Demos

Page 38: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38

Graphic Section Divider

Page 39: Taking a Leap Forward With JavaFX

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39