Three.js provides several control classes in order to interact with your 3D world.
They are located under
three.js/examples/js/controls in your Three.js directory.
With threeleapcontrols you can use your leap motion controller to rotate, zoom/scale and pan
any camera or object in your 3D scene.
Check out the example file
example.html and/or see it in action here.
You create a
camera and a
renderer with Three.js.
Then connect your
camera of your
scene with leap camera controls by setting
cameraControls = camera;
Leap.loop you need to call the
update method on
frame. After that it is necessary to
In order to
pan an arbitrary object in your scene, load the leap object controls
and then connect the
camera and your object, e.g. a
cubeControls = camera cube;
Leap.loop looks like
Note: Rotating objects with
LeapObjectControls is work in progress and not yet finished!
There are several options for your camera actions
Here, we are setting the
pan options (you can set the same attributes for rotating and panning):
controlspanEnabled = true;controlspanSpeed = 10;controlspanHands = 2;controlspanFingers = 6 12;controlspanRightHanded = true; // right-handedcontrolspanHandPosition = true; // palm position usedcontrolspanStabilized = true; // stabilized palm position used
You can disable panning by setting
false. Increase or decrease the speed of panning by adjusting
panSpeed. You can set the number of hands with option
panHands, i.e. the gesture is only triggered if the number of hands over your leap is equal to
panHands. It is possible to use a range of numbers (array of length 2 with integers), e.g. if
[1, 2] is given, panning will be done, if one or two hands
are used. The same goes for
panFingers. If you set
panHands to 2, then you can specify via
panRightHanded, which hand will be used for controlling the camera. If you set
panFingers to 1 or
[1, 1] and
false, then the position of your finger tip will be used (instead of the position of your palm). If you set
panStabilized to true the stabilized palm or finger tip position is used.
By default vertical rotating is bounded to a range of π, meaning the angle between the camera-to-target vector and the y-axis is greater than 0 and less than π. You can modify the range by setting
rotateMax. Horizontal rotating is not limited.
You can set the minimum and maximum distances for zooming with
The default values are
// rotationthisrotateEnabled = true;thisrotateSpeed = 10;thisrotateHands = 1;thisrotateFingers = 2 3;thisrotateRightHanded = true;thisrotateHandPosition = true;thisrotateStabilized = false;thisrotateMin = 0;thisrotateMax = MathPI;// zoomthiszoomEnabled = true;thiszoomSpeed = 10;thiszoomHands = 1;thiszoomFingers = 4 5;thiszoomRightHanded = true;thiszoomHandPosition = true;thiszoomStabilized = false;thiszoomMin = _thiscameranear;thiszoomMax = _thiscamerafar;// panthispanEnabled = true;thispanSpeed = 10;thispanHands = 2;thispanFingers = 6 12;thispanRightHanded = true;thispanHandPosition = true;thispanStabilized = false;
In your leap object controls the zoom options are scale options, i.e.
zoomEnabled will be