├── .DS_Store
├── .gitignore
├── Assembly-CSharp.pidb
├── Assets
├── .DS_Store
├── GesturesDebug.unity
├── GesturesDebug.unity.meta
├── Materials.meta
├── Materials
│ ├── .DS_Store
│ ├── BaseTexture.mat
│ ├── BaseTexture.mat.meta
│ ├── gesture_lightning.mat
│ ├── gesture_lightning.mat.meta
│ ├── gesture_rain.mat
│ ├── gesture_rain.mat.meta
│ ├── gesture_snow.mat
│ └── gesture_snow.mat.meta
├── Plugins.meta
├── Plugins
│ ├── .DS_Store
│ ├── LeapCSharp.NET3.5.dll
│ ├── LeapCSharp.NET3.5.dll.meta
│ ├── LeapCSharp.bundle.meta
│ ├── LeapCSharp.bundle
│ │ ├── Contents.meta
│ │ └── Contents
│ │ │ ├── Info.plist
│ │ │ ├── Info.plist.meta
│ │ │ ├── MacOS.meta
│ │ │ └── MacOS
│ │ │ ├── libLeap.dylib
│ │ │ ├── libLeap.dylib.meta
│ │ │ ├── libLeapCSharp.dylib
│ │ │ └── libLeapCSharp.dylib.meta
│ ├── _LeapCSharp.bundle.meta
│ └── _LeapCSharp.bundle
│ │ ├── Contents.meta
│ │ └── Contents
│ │ ├── Info.plist
│ │ ├── Info.plist.meta
│ │ ├── MacOS.meta
│ │ └── MacOS
│ │ ├── libLeap.dylib
│ │ ├── libLeap.dylib.meta
│ │ ├── lib_LeapCSharp.dylib
│ │ └── lib_LeapCSharp.dylib.meta
├── Scripts.meta
├── Scripts
│ ├── .DS_Store
│ ├── GestureData.cs
│ ├── GestureData.cs.meta
│ ├── GestureFrame.cs
│ ├── GestureFrame.cs.meta
│ ├── GestureInterpreter.cs
│ ├── GestureInterpreter.cs.meta
│ ├── GestureUtils.cs
│ ├── GestureUtils.cs.meta
│ ├── LeapController.cs
│ ├── LeapController.cs.meta
│ ├── PointSimplifier.cs
│ └── PointSimplifier.cs.meta
├── Textures.meta
└── Textures
│ ├── .DS_Store
│ ├── BaseTexture.png
│ ├── BaseTexture.png.meta
│ ├── gesture_downzig.jpg
│ ├── gesture_downzig.jpg.meta
│ ├── gesture_rightzig.jpg
│ ├── gesture_rightzig.jpg.meta
│ ├── gesture_square.jpg
│ └── gesture_square.jpg.meta
├── ProjectSettings
├── AudioManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── InputManager.asset
├── NavMeshLayers.asset
├── NetworkManager.asset
├── ProjectSettings.asset
├── QualitySettings.asset
├── TagManager.asset
└── TimeManager.asset
├── README.md
├── Screenshots
├── .DS_Store
├── gesture_downzig.jpg
├── gesture_rightzig.jpg
└── gesture_square.jpg
└── leap_patterns.userprefs
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 |
5 | # Autogenerated VS/MD solution and project files
6 | *.csproj
7 | *.unityproj
8 | *.sln
9 |
--------------------------------------------------------------------------------
/Assembly-CSharp.pidb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assembly-CSharp.pidb
--------------------------------------------------------------------------------
/Assets/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/.DS_Store
--------------------------------------------------------------------------------
/Assets/GesturesDebug.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/GesturesDebug.unity
--------------------------------------------------------------------------------
/Assets/GesturesDebug.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0532349fd257047bea348a341ed7b7ee
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d374ccbfba78a46679121ab55309a009
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Materials/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Materials/.DS_Store
--------------------------------------------------------------------------------
/Assets/Materials/BaseTexture.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Materials/BaseTexture.mat
--------------------------------------------------------------------------------
/Assets/Materials/BaseTexture.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 04b60bce9aa6141baa221a6d9400ca09
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Materials/gesture_lightning.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Materials/gesture_lightning.mat
--------------------------------------------------------------------------------
/Assets/Materials/gesture_lightning.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6f03e491e766846409ca378773dd96d0
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Materials/gesture_rain.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Materials/gesture_rain.mat
--------------------------------------------------------------------------------
/Assets/Materials/gesture_rain.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f1cb5f26e2d3949efa173d45ec9ac2df
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Materials/gesture_snow.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Materials/gesture_snow.mat
--------------------------------------------------------------------------------
/Assets/Materials/gesture_snow.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 04a36a9de713a435c9eaed270de08b86
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4e3e6528e04834adb9e571ba990f98da
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Plugins/.DS_Store
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.NET3.5.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Plugins/LeapCSharp.NET3.5.dll
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.NET3.5.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 15c6240eac5b94e768e640844b69cd2e
3 | MonoAssemblyImporter:
4 | serializedVersion: 1
5 | iconMap: {}
6 | executionOrder: {}
7 | userData:
8 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d79f852a69c9c4807bc4946fe82873d7
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c3ece10d7f1874b8281353fae0ddc426
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | libLeapCSharp.dylib
9 | CFBundleIdentifier
10 | com.leapmotion.LeapCSharp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFPlugInDynamicRegisterFunction
20 |
21 | CFPlugInDynamicRegistration
22 | NO
23 | CFPlugInFactories
24 |
25 | 00000000-0000-0000-0000-000000000000
26 | MyFactoryFunction
27 |
28 | CFPlugInTypes
29 |
30 | 00000000-0000-0000-0000-000000000000
31 |
32 | 00000000-0000-0000-0000-000000000000
33 |
34 |
35 | CFPlugInUnloadFunction
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/Info.plist.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: eea2e6cc67bcf47999a2afeb33c06004
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5a551cdc512e8448bbf74ae32af8d0c8
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS/libLeap.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS/libLeap.dylib
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS/libLeap.dylib.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 03aa87ab9d0944b0db6d7899a9e8859b
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS/libLeapCSharp.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS/libLeapCSharp.dylib
--------------------------------------------------------------------------------
/Assets/Plugins/LeapCSharp.bundle/Contents/MacOS/libLeapCSharp.dylib.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3c87b3e8bb7064a0dbf0afccb711857e
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ca77f17e6e9d54f23b1a74a004f9554a
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 746e7b9fec3214d2295e3fa3956cf2b6
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | lib_LeapCSharp.dylib
9 | CFBundleIdentifier
10 | com.leapmotion._LeapCSharp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFPlugInDynamicRegisterFunction
20 |
21 | CFPlugInDynamicRegistration
22 | NO
23 | CFPlugInFactories
24 |
25 | 00000000-0000-0000-0000-000000000000
26 | MyFactoryFunction
27 |
28 | CFPlugInTypes
29 |
30 | 00000000-0000-0000-0000-000000000000
31 |
32 | 00000000-0000-0000-0000-000000000000
33 |
34 |
35 | CFPlugInUnloadFunction
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/Info.plist.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f3cb3adae7821446a969b09913c1991a
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 74471c4ee9fd745ca882affacaa1f3ba
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS/libLeap.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS/libLeap.dylib
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS/libLeap.dylib.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0dabc3dcaefcd4cd891914ece40d6c7b
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS/lib_LeapCSharp.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS/lib_LeapCSharp.dylib
--------------------------------------------------------------------------------
/Assets/Plugins/_LeapCSharp.bundle/Contents/MacOS/lib_LeapCSharp.dylib.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 827f6a9c80ed24dc9ba611bf6d6252b7
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4ad4cb01559a24688850d1f7e0b9fc77
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Scripts/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Scripts/.DS_Store
--------------------------------------------------------------------------------
/Assets/Scripts/GestureData.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | * Copyright (c) 2013 Danilo Gaby Andersen Trindade
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | * and to permit persons to whom the Software is furnished to do so, subject to the
10 | * following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18 | * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | using UnityEngine;
23 | using System.Collections;
24 | using Leap;
25 |
26 | public class GestureData : Object {
27 |
28 | public float maximumX = -1000000000.0f;
29 | public float maximumY = -1000000000.0f;
30 | public float maximumZ = -1000000000.0f;
31 | public float minimumX = 1000000000.0f;
32 | public float minimumY = 1000000000.0f;
33 | public float minimumZ = 1000000000.0f;
34 |
35 | public ArrayList frames = null;
36 |
37 | public GestureData() {
38 | frames = new ArrayList();
39 | }
40 |
41 | public void appendFrame(GestureFrame frame) {
42 | if (frame.position.x < this.minimumX) {
43 | this.minimumX = frame.position.x;
44 | }
45 |
46 | if (frame.position.y < this.minimumY) {
47 | this.minimumY = frame.position.y;
48 | }
49 |
50 | if (frame.position.z < this.minimumZ) {
51 | this.minimumZ = frame.position.z;
52 | }
53 |
54 | if (frame.position.x > this.maximumX) {
55 | this.maximumX = frame.position.x;
56 | }
57 |
58 | if (frame.position.y > this.maximumY) {
59 | this.maximumY = frame.position.y;
60 | }
61 |
62 | if (frame.position.z > this.maximumZ) {
63 | this.maximumZ = frame.position.z;
64 | }
65 |
66 | this.frames.Add(frame);
67 | }
68 |
69 | ///
70 | /// Gets the normalized gesture data.
71 | ///
72 | ///
73 | /// The normalized gesture data.
74 | ///
75 | ///
76 | /// Resolution to normalize to.
77 | ///
78 | public GestureData getNormalizedGestureData(float resolution) {
79 | var dx = (this.maximumX - this.minimumX) * 1.0f;
80 | var dy = (this.maximumY - this.minimumY) * 1.0f;
81 |
82 | if (dx > dy)
83 | dy = dx;
84 | else
85 | dx = dy;
86 |
87 | GestureData normalizedData = new GestureData();
88 |
89 | for (var i = 0; i < this.frames.Count; i++) {
90 | GestureFrame frame = (GestureFrame)this.frames[i];
91 |
92 | float x = (frame.position.x * 1.0f - this.minimumX) / dx * resolution;
93 | float y = resolution - (frame.position.y * 1.0f - this.minimumY) / dy * resolution;
94 |
95 | GestureFrame normalizedFrame = new GestureFrame(new Vector(x, y, 0.0f), frame.velocity, frame.timestamp);
96 | normalizedData.appendFrame(normalizedFrame);
97 | }
98 |
99 | return normalizedData;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureData.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e7153e99f14dd4fb1ae61918c81a0ade
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureFrame.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | * Copyright (c) 2013 Danilo Gaby Andersen Trindade
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | * and to permit persons to whom the Software is furnished to do so, subject to the
10 | * following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18 | * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | using UnityEngine;
23 | using System.Collections;
24 | using Leap;
25 |
26 | ///
27 | /// Gesture frame object with all relevant frame information.
28 | ///
29 | public class GestureFrame : Object {
30 |
31 | public Vector position;
32 | public Vector velocity;
33 | public float timestamp;
34 |
35 | ///
36 | /// Initializes a new instance of the class.
37 | ///
38 | ///
39 | /// Position.
40 | ///
41 | ///
42 | /// Velocity.
43 | ///
44 | ///
45 | /// Timestamp.
46 | ///
47 | public GestureFrame(Vector position, Vector velocity, float timestamp) {
48 | this.position = position;
49 | this.velocity = velocity;
50 | this.timestamp = timestamp;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureFrame.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 32f36d652dbe345249842f906c8b802c
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureInterpreter.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | * Copyright (c) 2013 Danilo Gaby Andersen Trindade
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | * and to permit persons to whom the Software is furnished to do so, subject to the
10 | * following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18 | * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | using UnityEngine;
23 | using System.Collections;
24 | using Leap;
25 |
26 | public class GestureInterpreter : Object {
27 |
28 | ArrayList detectionHeap = null;
29 | int maximumHeapSize = 2;
30 |
31 | float lastEndMovementTime = 0.0f;
32 | float lastStoppedTime = 0.0f;
33 |
34 | GestureData gestureData = null;
35 |
36 | bool performingMovement = false;
37 | bool performingGesture = false;
38 |
39 | Vector3 movementDirection = Vector3.zero;
40 | Vector3 movementTotalWork = Vector3.zero;
41 |
42 | float minimumRelevantWorkThreshold = 0.000002f;
43 | float minimumStartMovementTotalWork = 0.02f;
44 | float minimumEndMovementKinectEnergy = 2.0e-3f;
45 |
46 | public LeapController callbackInstance;
47 |
48 | public GestureInterpreter()
49 | {
50 | detectionHeap = new ArrayList();
51 | detectionHeap.Capacity = this.maximumHeapSize;
52 | }
53 |
54 | ///
55 | /// Detects the movement and builds the frame list when movement is detected.
56 | ///
57 | ///
58 | /// Leap frame.
59 | ///
60 | public void DetectMovement(Frame frame)
61 | {
62 | GestureFrame gestureFrame = new GestureFrame(frame.Pointables[0].TipPosition, frame.Pointables[0].TipVelocity, frame.Timestamp);
63 | this.detectionHeap.Add(gestureFrame);
64 |
65 | Vector3 acceleration = Vector3.zero;
66 | Vector3 delta = Vector3.zero;
67 | Vector3 movementWork = Vector3.zero;
68 | Vector3 kinecticEnergy = Vector3.zero;
69 |
70 | float movementTotalWork;
71 | float kinecticEnergyTotal;
72 |
73 | if (this.detectionHeap.Count > this.maximumHeapSize) {
74 | this.detectionHeap.RemoveAt(0);
75 |
76 | GestureFrame firstFrame = (GestureFrame)this.detectionHeap[0];
77 | GestureFrame lastFrame = (GestureFrame)this.detectionHeap[this.maximumHeapSize - 1];
78 |
79 | float deltaTime = lastFrame.timestamp - firstFrame.timestamp;
80 |
81 | acceleration.x = (lastFrame.velocity.x - firstFrame.velocity.x) / deltaTime;
82 | acceleration.y = (lastFrame.velocity.y - firstFrame.velocity.y) / deltaTime;
83 | acceleration.z = (lastFrame.velocity.z - firstFrame.velocity.z) / deltaTime;
84 |
85 | this.movementDirection.x = acceleration.x > 0 ? 1 : -1;
86 | this.movementDirection.y = acceleration.y > 0 ? 1 : -1;
87 | this.movementDirection.z = acceleration.z > 0 ? 1 : -1;
88 |
89 | delta.x = (lastFrame.position.x - firstFrame.position.x);
90 | delta.y = (lastFrame.position.y - firstFrame.position.y);
91 | delta.z = (lastFrame.position.z - firstFrame.position.z);
92 |
93 | /*
94 | * http://en.wikipedia.org/wiki/Work_(physics)
95 | * Work calculation, using the acceleration previously calculated as the force to move the finger from one point to another
96 | */
97 |
98 | movementWork.x = delta.x * acceleration.x;
99 | movementWork.y = delta.y * acceleration.y;
100 | movementWork.z = delta.z * acceleration.z;
101 |
102 | /*
103 | * http://en.wikipedia.org/wiki/Kinetic_energy
104 | * Measures the pointable kinectic energy to detect when gesture have ended.
105 | */
106 |
107 | kinecticEnergy.x = Mathf.Pow(lastFrame.velocity.x, 2) * 0.5f * 1.0e-6f;
108 | kinecticEnergy.y = Mathf.Pow(lastFrame.velocity.y, 2) * 0.5f * 1.0e-6f;
109 | kinecticEnergy.z = Mathf.Pow(lastFrame.velocity.z, 2) * 0.5f * 1.0e-6f;
110 |
111 | kinecticEnergyTotal = kinecticEnergy.x + kinecticEnergy.y;
112 |
113 | if (Mathf.Abs(movementWork.x) > this.minimumRelevantWorkThreshold) {
114 | this.movementTotalWork.x += movementWork.x;
115 | }
116 |
117 | if (Mathf.Abs(movementWork.y) > this.minimumRelevantWorkThreshold) {
118 | this.movementTotalWork.y += movementWork.y;
119 | }
120 |
121 | if (Mathf.Abs(movementWork.z) > this.minimumRelevantWorkThreshold) {
122 | this.movementTotalWork.z += movementWork.z;
123 | }
124 |
125 | if (!this.performingMovement && lastFrame.timestamp - this.lastStoppedTime > 50000.0f) {
126 | this.movementTotalWork.x = 0.0f;
127 | this.movementTotalWork.y = 0.0f;
128 | this.movementTotalWork.z = 0.0f;
129 | this.lastStoppedTime = lastFrame.timestamp;
130 | }
131 |
132 | movementTotalWork = this.movementTotalWork.x + this.movementTotalWork.y;
133 |
134 | if (movementTotalWork > this.minimumStartMovementTotalWork && !this.performingMovement) {
135 | this.movementTotalWork.x = 0;
136 | this.movementTotalWork.y = 0;
137 | this.movementTotalWork.z = 0;
138 |
139 | this.performingMovement = true;
140 |
141 | if (!this.performingGesture) {
142 | this.performingGesture = true;
143 | this.gestureData = new GestureData();
144 |
145 | if (this.callbackInstance != null)
146 | {
147 | this.callbackInstance.beginOfGestureCallback();
148 | }
149 | }
150 |
151 | } else if (this.performingMovement && kinecticEnergyTotal < this.minimumEndMovementKinectEnergy) {
152 |
153 | this.movementTotalWork.x = 0.0f;
154 | this.movementTotalWork.y = 0.0f;
155 | this.movementTotalWork.z = 0.0f;
156 |
157 | this.performingMovement = false;
158 | this.lastStoppedTime = this.lastEndMovementTime = lastFrame.timestamp;
159 | }
160 |
161 | if (this.performingGesture) {
162 | this.gestureData.appendFrame(gestureFrame);
163 | }
164 |
165 | float timeSinceEndMovement = lastFrame.timestamp - this.lastEndMovementTime;
166 |
167 | if (!this.performingMovement && this.performingGesture && timeSinceEndMovement > 500000) {
168 | if (this.callbackInstance != null) {
169 | this.callbackInstance.endOfGestureCallback(this.gestureData);
170 | }
171 |
172 | this.performingGesture = false;
173 | }
174 | }
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureInterpreter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: feaf4bc0c8788492d977234695f56eec
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureUtils.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | * Copyright (c) 2013 Danilo Gaby Andersen Trindade
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | * and to permit persons to whom the Software is furnished to do so, subject to the
10 | * following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18 | * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | using UnityEngine;
23 | using System;
24 | using System.Collections;
25 | using System.Collections.Generic;
26 | using Leap;
27 |
28 | ///
29 | /// Class with utilities to detect patterns drawed
30 | ///
31 | public class GestureUtils : UnityEngine.Object {
32 |
33 | ///
34 | /// Enum for directions.
35 | ///
36 | private enum EnumVectorDirection {None = 0, Up, Down, Left, Right, UpRight, UpLeft, DownRight, DownLeft};
37 | ///
38 | /// Enum for patterns possible.
39 | ///
40 | public enum EnumGestures {Nothing = 0, DownZigZag, RightZigZag, Square};
41 |
42 | Texture2D canvas = null;
43 |
44 | float canvasSize = 0.0f;
45 |
46 | float precisionLineAprox;
47 | float precisionSquareAlignment;
48 |
49 | ///
50 | /// Initializes a new instance of the class
51 | /// with the precisions passed, if any. Otherwise uses the defaults.
52 | ///
53 | ///
54 | /// Precision to use in line straightening algorithm.
55 | ///
56 | ///
57 | /// Precision to use when checking alignment of the points in square gesture.
58 | ///
59 | public GestureUtils(float precisionLineAprox = 30.0f,
60 | float precisionSquareAlignment = 170.0f) {
61 | this.precisionLineAprox = precisionLineAprox;
62 | this.precisionSquareAlignment = precisionSquareAlignment;
63 | }
64 |
65 | ///
66 | /// Returns which gesture was made from a list of frames. If a canvas
67 | /// and it's size is passed, draw the points considered for gesture
68 | /// detection on the canvas.
69 | ///
70 | ///
71 | /// Gesture from EnumGestures detected or EnumGestures.Nothing (== 0) if no gesture is detected.
72 | ///
73 | ///
74 | /// List of frames to use in gesture detection
75 | ///
76 | ///
77 | /// Canvas to draw the points on.
78 | ///
79 | ///
80 | /// Size of the canvas to draw on.
81 | ///
82 | public EnumGestures GestureChecker(List frameList, Texture2D canvas, float canvasSize) {
83 | this.canvas = canvas;
84 | this.canvasSize = canvasSize;
85 | return GestureChecker(frameList);
86 | }
87 |
88 | ///
89 | /// Returns which gesture was made from a list of frames.
90 | ///
91 | ///
92 | /// Gesture from EnumGestures detected, or EnumGestures.Nothing (== 0) if no gesture is detected.
93 | ///
94 | ///
95 | /// List of frames to use in gesture detection
96 | ///
97 | public EnumGestures GestureChecker(List frameList) {
98 | List keyPointsList = null;
99 | EnumGestures result = EnumGestures.Nothing;
100 |
101 | const int strokeSize = 5;
102 |
103 | keyPointsList = PointSimplifier.RamerDouglasPeucker(frameList, precisionLineAprox);
104 | GC.Collect();
105 |
106 | if (canvas != null) {
107 | for (int i = 0; i < keyPointsList.Count; i++) {
108 | Vector2 currentFrame = keyPointsList[i];
109 |
110 | for (int j = -strokeSize; j <= strokeSize; j++) {
111 | for (int k = -strokeSize; k <= strokeSize; k++) {
112 | if ((((j+(int)currentFrame.x) > 0) &&
113 | ((k+canvas.height-(int)currentFrame.y) > 0)) &&
114 | (((j+currentFrame.x) < canvasSize) &&
115 | ((k+canvas.height-(int)currentFrame.y) < canvasSize))) {
116 |
117 | canvas.SetPixel(j+(int)currentFrame.x, k+canvas.height-(int)currentFrame.y, Color.black);
118 |
119 | }
120 | }
121 | }
122 | }
123 |
124 | canvas.Apply();
125 | }
126 |
127 | result = OpenPass(keyPointsList);
128 | if (result == EnumGestures.Nothing) {
129 |
130 | keyPointsList = PointSimplifier.RamerDouglasPeucker(keyPointsList, precisionLineAprox*4);
131 | GC.Collect();
132 |
133 | if (canvas != null) {
134 | for (int i = 0; i < keyPointsList.Count; i++) {
135 | Vector2 currentFrame = keyPointsList[i];
136 |
137 | for (int j = -strokeSize*2; j <= strokeSize*2; j++) {
138 | for (int k = -strokeSize*2; k <= strokeSize*2; k++) {
139 | if ((((j+(int)currentFrame.x) > 0) &&
140 | ((k+canvas.height-(int)currentFrame.y) > 0)) &&
141 | (((j+currentFrame.x) < canvasSize) &&
142 | ((k+canvas.height-(int)currentFrame.y) < canvasSize))) {
143 |
144 | canvas.SetPixel(j+(int)currentFrame.x, k+canvas.height-(int)currentFrame.y, Color.black);
145 |
146 | }
147 | }
148 | }
149 | }
150 |
151 | canvas.Apply();
152 | }
153 |
154 | result = ClosedPass(keyPointsList);
155 | }
156 |
157 | return result;
158 | }
159 |
160 | ///
161 | /// Returns if one of the open gestures was made, either lightning or rain.
162 | ///
163 | ///
164 | /// EnumGestures.DownZigZag or EnumGestures.RightZigZag if detected, or EnumGestures.Nothing (== 0) if no gesture is detected.
165 | ///
166 | ///
167 | /// List of frames to use in gesture detection, must only contain the edges of the gesture made.
168 | ///
169 | private EnumGestures OpenPass(List keyPointsList) {
170 |
171 | const int downZigEdgesTotal = 4;
172 | const int rightZigEdgesTotal = 4;
173 |
174 | int i = 0;
175 | int j = 0;
176 |
177 | bool hasFound = false;
178 |
179 | bool isDownZig = true;
180 | bool isRightZig = true;
181 |
182 | while ((!hasFound) && (i < keyPointsList.Count)) {
183 |
184 | int totalPoints = keyPointsList.Count - i;
185 | EnumVectorDirection currentDirection;
186 |
187 | Vector2 previousFrame = keyPointsList[i];
188 |
189 | isDownZig = true;
190 | isRightZig = true;
191 |
192 | if (totalPoints < downZigEdgesTotal) {
193 | isDownZig = false;
194 | }
195 |
196 | if (totalPoints < rightZigEdgesTotal) {
197 | isRightZig = false;
198 | }
199 |
200 | j = i+1;
201 |
202 | currentDirection = EnumVectorDirection.None;
203 |
204 | while ((!hasFound) && (isDownZig || isRightZig) && (j < keyPointsList.Count)) {
205 | Vector2 currentFrame = keyPointsList[j];
206 | float difX = currentFrame.x - previousFrame.x;
207 | float difY = currentFrame.y - previousFrame.y;
208 |
209 | if ((difX < 0) && (difY > 0)) {
210 | currentDirection = EnumVectorDirection.DownLeft;
211 | } else if ((difX > 0) && (difY > 0)) {
212 | currentDirection = EnumVectorDirection.DownRight;
213 | } else if ((difX < 0) && (difY < 0)) {
214 | currentDirection = EnumVectorDirection.UpLeft;
215 | } else if ((difX > 0) && (difY < 0)) {
216 | currentDirection = EnumVectorDirection.UpRight;
217 | } else if ((difX < 0) && (difY == 0)) {
218 | currentDirection = EnumVectorDirection.Left;
219 | } else if ((difX > 0) && (difY == 0)) {
220 | currentDirection = EnumVectorDirection.Right;
221 | } else if ((difX == 0) && (difY < 0)) {
222 | currentDirection = EnumVectorDirection.Up;
223 | } else {
224 | currentDirection = EnumVectorDirection.Down;
225 | }
226 |
227 | j++;
228 |
229 | if (isDownZig) {
230 | if (j - i > downZigEdgesTotal+1) {
231 | isDownZig = false;
232 | } else {
233 | if ((j - i) % 2 == 0) {
234 | if (currentDirection == EnumVectorDirection.DownLeft) {
235 | if (!(j < i+downZigEdgesTotal)) {
236 | hasFound = true;
237 |
238 | isRightZig = false;
239 | }
240 | } else {
241 | isDownZig = false;
242 | }
243 | } else {
244 | if (!((currentDirection == EnumVectorDirection.DownRight) ||
245 | (currentDirection == EnumVectorDirection.UpRight) ||
246 | (currentDirection == EnumVectorDirection.Right))) {
247 | isDownZig = false;
248 | }
249 | }
250 | }
251 | }
252 |
253 | if (isRightZig) {
254 | if (j - i > rightZigEdgesTotal+1) {
255 | isRightZig = false;
256 | } else {
257 | if ((j - i) % 2 == 0) {
258 | if ((currentDirection == EnumVectorDirection.DownRight) ||
259 | (currentDirection == EnumVectorDirection.Down)) {
260 | if (!(j < i+rightZigEdgesTotal)) {
261 | hasFound = true;
262 |
263 | isDownZig = false;
264 | }
265 | } else {
266 | isRightZig = false;
267 | }
268 | } else {
269 | if (!((currentDirection == EnumVectorDirection.Up) ||
270 | (currentDirection == EnumVectorDirection.UpRight))) {
271 | isRightZig = false;
272 | }
273 | }
274 | }
275 | }
276 |
277 | previousFrame = currentFrame;
278 | }
279 |
280 | i++;
281 | }
282 |
283 | if (hasFound) {
284 | if (isDownZig) {
285 | return EnumGestures.DownZigZag;
286 | } else {
287 | return EnumGestures.RightZigZag;
288 | }
289 | }
290 |
291 | return EnumGestures.Nothing;
292 | }
293 |
294 | ///
295 | /// Returns if the square closed form was made.
296 | ///
297 | ///
298 | /// EnumGestures.Square if detected, or EnumGestures.Nothing (== 0) if no gesture is detected.
299 | ///
300 | ///
301 | /// List of frames to use in gesture detection, must only contain the edges of the gesture made.
302 | ///
303 | private EnumGestures ClosedPass(List keyPointsList) {
304 |
305 | const int squareEdgesTotal = 4;
306 |
307 | int i = 0;
308 | int j = 0;
309 |
310 | bool hasFound = false;
311 |
312 | bool isSquare = true;
313 |
314 | i = 0;
315 | while ((!hasFound) && (i < keyPointsList.Count)) {
316 |
317 | int totalPoints = keyPointsList.Count - i;
318 | List directionList = new List();
319 | EnumVectorDirection currentDirection;
320 |
321 | Vector2 startingFrame = keyPointsList[i];
322 | Vector2 previousFrame = startingFrame;
323 |
324 | isSquare = true;
325 |
326 | if (totalPoints < squareEdgesTotal) {
327 | isSquare = false;
328 | }
329 |
330 | j = i+1;
331 |
332 | currentDirection = EnumVectorDirection.None;
333 |
334 | directionList.Add(currentDirection);
335 |
336 | while ((!hasFound) && (isSquare) && (j < keyPointsList.Count)) {
337 | Vector2 currentFrame = keyPointsList[j];
338 | float difX = currentFrame.x - previousFrame.x;
339 | float difY = currentFrame.y - previousFrame.y;
340 |
341 | if ((difX < 0) && (difY > 0)) {
342 | currentDirection = EnumVectorDirection.DownLeft;
343 | } else if ((difX > 0) && (difY > 0)) {
344 | currentDirection = EnumVectorDirection.DownRight;
345 | } else if ((difX < 0) && (difY < 0)) {
346 | currentDirection = EnumVectorDirection.UpLeft;
347 | } else if ((difX > 0) && (difY < 0)) {
348 | currentDirection = EnumVectorDirection.UpRight;
349 | } else if ((difX < 0) && (difY == 0)) {
350 | currentDirection = EnumVectorDirection.Left;
351 | } else if ((difX > 0) && (difY == 0)) {
352 | currentDirection = EnumVectorDirection.Right;
353 | } else if ((difX == 0) && (difY < 0)) {
354 | currentDirection = EnumVectorDirection.Up;
355 | } else {
356 | currentDirection = EnumVectorDirection.Down;
357 | }
358 |
359 | directionList.Add(currentDirection);
360 |
361 | j++;
362 |
363 | if (isSquare) {
364 | if (j - i > squareEdgesTotal+1) {
365 | isSquare = false;
366 | } else {
367 | if (j - i == 5) {
368 | float difStartX = Math.Abs(currentFrame.x - startingFrame.x);
369 | float difStartY = Math.Abs(currentFrame.y - startingFrame.y);
370 |
371 | if ((difStartX < precisionSquareAlignment) && (difStartY < precisionSquareAlignment)) {
372 | if ((((directionList[1] == EnumVectorDirection.Right) || (directionList[1] == EnumVectorDirection.DownRight) || (directionList[1] == EnumVectorDirection.UpRight)) &&
373 | ((directionList[2] == EnumVectorDirection.Up) || (directionList[2] == EnumVectorDirection.UpLeft) || (directionList[2] == EnumVectorDirection.UpRight)) &&
374 | ((directionList[3] == EnumVectorDirection.Left) || (directionList[3] == EnumVectorDirection.DownLeft) || (directionList[3] == EnumVectorDirection.UpLeft)) &&
375 | ((directionList[4] == EnumVectorDirection.Down) || (directionList[4] == EnumVectorDirection.DownLeft) || (directionList[4] == EnumVectorDirection.DownRight))) ||
376 |
377 | (((directionList[1] == EnumVectorDirection.Right) || (directionList[1] == EnumVectorDirection.DownRight) || (directionList[1] == EnumVectorDirection.UpRight)) &&
378 | ((directionList[2] == EnumVectorDirection.Down) || (directionList[2] == EnumVectorDirection.DownLeft) || (directionList[2] == EnumVectorDirection.DownRight)) &&
379 | ((directionList[3] == EnumVectorDirection.Left) || (directionList[3] == EnumVectorDirection.DownLeft) || (directionList[3] == EnumVectorDirection.UpLeft)) &&
380 | ((directionList[4] == EnumVectorDirection.Up) || (directionList[4] == EnumVectorDirection.UpLeft) || (directionList[4] == EnumVectorDirection.UpRight))) ||
381 |
382 | (((directionList[1] == EnumVectorDirection.Left) || (directionList[1] == EnumVectorDirection.DownLeft) || (directionList[1] == EnumVectorDirection.UpLeft)) &&
383 | ((directionList[2] == EnumVectorDirection.Up) || (directionList[2] == EnumVectorDirection.UpLeft) || (directionList[2] == EnumVectorDirection.UpRight)) &&
384 | ((directionList[3] == EnumVectorDirection.Right) || (directionList[3] == EnumVectorDirection.DownRight) || (directionList[3] == EnumVectorDirection.UpRight)) &&
385 | ((directionList[4] == EnumVectorDirection.Down) || (directionList[4] == EnumVectorDirection.DownLeft) || (directionList[4] == EnumVectorDirection.DownRight))) ||
386 |
387 | (((directionList[1] == EnumVectorDirection.Left) || (directionList[1] == EnumVectorDirection.DownLeft) || (directionList[1] == EnumVectorDirection.UpLeft)) &&
388 | ((directionList[2] == EnumVectorDirection.Down) || (directionList[2] == EnumVectorDirection.DownLeft) || (directionList[2] == EnumVectorDirection.DownRight)) &&
389 | ((directionList[3] == EnumVectorDirection.Right) || (directionList[3] == EnumVectorDirection.DownRight) || (directionList[3] == EnumVectorDirection.UpRight)) &&
390 | ((directionList[4] == EnumVectorDirection.Up) || (directionList[4] == EnumVectorDirection.UpLeft) || (directionList[4] == EnumVectorDirection.UpRight)))) {
391 |
392 | float horLineInclination1 = Math.Abs(keyPointsList[j-5].y - keyPointsList[j-4].y);
393 | float horLineInclination2 = Math.Abs(keyPointsList[j-3].y - keyPointsList[j-2].y);
394 | float verLineInclination1 = Math.Abs(keyPointsList[j-4].x - keyPointsList[j-3].x);
395 | float verLineInclination2 = Math.Abs(keyPointsList[j-2].x - keyPointsList[j-5].x);
396 |
397 | if ((horLineInclination1 < precisionSquareAlignment*4) &&
398 | (horLineInclination2 < precisionSquareAlignment*4) &&
399 | (verLineInclination1 < precisionSquareAlignment*4) &&
400 | (verLineInclination2 < precisionSquareAlignment*4)) {
401 |
402 | hasFound = true;
403 | }
404 |
405 | } else if ((((directionList[1] == EnumVectorDirection.Up) || (directionList[1] == EnumVectorDirection.UpLeft) || (directionList[1] == EnumVectorDirection.UpRight)) &&
406 | ((directionList[2] == EnumVectorDirection.Left) || (directionList[2] == EnumVectorDirection.DownLeft) || (directionList[2] == EnumVectorDirection.UpLeft)) &&
407 | ((directionList[3] == EnumVectorDirection.Down) || (directionList[3] == EnumVectorDirection.DownLeft) || (directionList[3] == EnumVectorDirection.DownRight)) &&
408 | ((directionList[4] == EnumVectorDirection.Right) || (directionList[4] == EnumVectorDirection.DownRight) || (directionList[4] == EnumVectorDirection.UpRight))) ||
409 |
410 | (((directionList[1] == EnumVectorDirection.Up) || (directionList[1] == EnumVectorDirection.UpLeft) || (directionList[1] == EnumVectorDirection.UpRight)) &&
411 | ((directionList[2] == EnumVectorDirection.Right) || (directionList[2] == EnumVectorDirection.DownRight) || (directionList[2] == EnumVectorDirection.UpRight)) &&
412 | ((directionList[3] == EnumVectorDirection.Down) || (directionList[3] == EnumVectorDirection.DownLeft) || (directionList[3] == EnumVectorDirection.DownRight)) &&
413 | ((directionList[4] == EnumVectorDirection.Left) || (directionList[4] == EnumVectorDirection.DownLeft) || (directionList[4] == EnumVectorDirection.UpLeft))) ||
414 |
415 | (((directionList[1] == EnumVectorDirection.Down) || (directionList[1] == EnumVectorDirection.DownLeft) || (directionList[1] == EnumVectorDirection.DownRight)) &&
416 | ((directionList[2] == EnumVectorDirection.Left) || (directionList[2] == EnumVectorDirection.DownLeft) || (directionList[2] == EnumVectorDirection.UpLeft)) &&
417 | ((directionList[3] == EnumVectorDirection.Up) || (directionList[3] == EnumVectorDirection.UpLeft) || (directionList[3] == EnumVectorDirection.UpRight)) &&
418 | ((directionList[4] == EnumVectorDirection.Right) || (directionList[4] == EnumVectorDirection.DownRight) || (directionList[4] == EnumVectorDirection.UpRight))) ||
419 |
420 | (((directionList[1] == EnumVectorDirection.Down) || (directionList[1] == EnumVectorDirection.DownLeft) || (directionList[1] == EnumVectorDirection.DownRight)) &&
421 | ((directionList[2] == EnumVectorDirection.Right) || (directionList[2] == EnumVectorDirection.DownRight) || (directionList[2] == EnumVectorDirection.UpRight)) &&
422 | ((directionList[3] == EnumVectorDirection.Up) || (directionList[3] == EnumVectorDirection.UpLeft) || (directionList[3] == EnumVectorDirection.UpRight)) &&
423 | ((directionList[4] == EnumVectorDirection.Left) || (directionList[4] == EnumVectorDirection.DownLeft) || (directionList[4] == EnumVectorDirection.UpLeft)))) {
424 |
425 | float horLineInclination1 = Math.Abs(keyPointsList[j-4].x - keyPointsList[j-3].x);
426 | float horLineInclination2 = Math.Abs(keyPointsList[j-2].x - keyPointsList[j-5].x);
427 | float verLineInclination1 = Math.Abs(keyPointsList[j-5].y - keyPointsList[j-4].y);
428 | float verLineInclination2 = Math.Abs(keyPointsList[j-3].y - keyPointsList[j-2].y);
429 |
430 | if ((horLineInclination1 < precisionSquareAlignment*4) &&
431 | (horLineInclination2 < precisionSquareAlignment*4) &&
432 | (verLineInclination1 < precisionSquareAlignment*4) &&
433 | (verLineInclination2 < precisionSquareAlignment*4)) {
434 |
435 | hasFound = true;
436 | }
437 | }
438 | } else {
439 | isSquare = false;
440 | }
441 | }
442 | }
443 | }
444 |
445 | previousFrame = currentFrame;
446 | }
447 |
448 | i++;
449 | }
450 |
451 | if (hasFound) {
452 | return EnumGestures.Square;
453 | }
454 |
455 | return EnumGestures.Nothing;
456 | }
457 | }
458 |
--------------------------------------------------------------------------------
/Assets/Scripts/GestureUtils.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: af5a9b46632a4407dba877680972d29e
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Scripts/LeapController.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | * Copyright (c) 2013 Danilo Gaby Andersen Trindade
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | * and to permit persons to whom the Software is furnished to do so, subject to the
10 | * following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18 | * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | using UnityEngine;
23 | using System.Collections;
24 | using System.Collections.Generic;
25 | using System;
26 | using System.IO;
27 | using Leap;
28 | using System.Runtime.InteropServices;
29 |
30 | public class LeapController : MonoBehaviour {
31 |
32 | private const float CANVAS_SIZE = 512.0f;
33 |
34 | ///
35 | /// Constant indicating accepted frame variation to cancel out noises.
36 | ///
37 | private const float NORMAL_FRAME_VARIATION = 250.0f;
38 |
39 | Listener listener;
40 | Controller controller;
41 |
42 | GestureInterpreter gi = null;
43 | GestureUtils gu = null;
44 |
45 | public Renderer canvasRenderer;
46 | Texture2D canvas;
47 | string status = "Nothing.";
48 |
49 | ///
50 | /// Start this instance.
51 | ///
52 | void Start () {
53 | listener = new Listener();
54 | controller = new Controller(listener);
55 |
56 | //This constructor can be called with parameters to change default precision values.
57 | gu = new GestureUtils();
58 |
59 | gi = new GestureInterpreter();
60 | gi.callbackInstance = this;
61 | }
62 |
63 | ///
64 | /// Update this instance.
65 | ///
66 | void Update () {
67 | Frame frame = controller.Frame();
68 | gi.DetectMovement(frame);
69 | }
70 |
71 | ///
72 | /// Raises the GU event.
73 | ///
74 | public void OnGUI() {
75 | GUIStyle style = new GUIStyle();
76 | style.fontSize = 100;
77 | GUI.Label(new Rect(CANVAS_SIZE/2.0f - 75.0f, 30.0f, 150.0f, 50.0f), status, style);
78 | }
79 |
80 | ///
81 | /// Raises the application quit event.
82 | ///
83 | public void OnApplicationQuit() {
84 | Debug.Log("Quit!");
85 | controller.Dispose();
86 | }
87 |
88 | ///
89 | /// Signals the start of a gesture movement.
90 | ///
91 | public void beginOfGestureCallback() {
92 | Debug.Log("Gesture started! Clearing canvas...");
93 | canvas = new Texture2D((int)CANVAS_SIZE, (int)CANVAS_SIZE, TextureFormat.ARGB32, false);
94 | for (int i = 0; i < canvas.width; i++) {
95 | for (int j = 0; j < canvas.width; j++) {
96 | canvas.SetPixel(i, j, Color.white);
97 | }
98 | }
99 | canvasRenderer.material.mainTexture = canvas;
100 | canvas.Apply();
101 |
102 | GC.Collect();
103 | }
104 |
105 | ///
106 | /// End of gesture movement callback.
107 | ///
108 | ///
109 | /// Data of the gesture gathered.
110 | ///
111 | public void endOfGestureCallback(GestureData data) {
112 | GestureUtils.EnumGestures gResult;
113 |
114 | Debug.Log("Gesture ended!");
115 | List pointList = new List();
116 | GestureData normalizedData = data.getNormalizedGestureData(CANVAS_SIZE);
117 |
118 | GestureFrame previousFrame = (GestureFrame)normalizedData.frames[0];
119 | pointList.Add(new Vector2(previousFrame.position.x, previousFrame.position.y));
120 | for (int i = 1; i < normalizedData.frames.Count; i++) {
121 | GestureFrame currentFrame = (GestureFrame)normalizedData.frames[i];
122 |
123 | if ((Math.Abs(currentFrame.position.x - previousFrame.position.x) < NORMAL_FRAME_VARIATION) &&
124 | (Math.Abs(currentFrame.position.y - previousFrame.position.y) < NORMAL_FRAME_VARIATION)) {
125 |
126 | pointList.Add(new Vector2(currentFrame.position.x, currentFrame.position.y));
127 | previousFrame = currentFrame;
128 | }
129 |
130 | }
131 |
132 | //At gesture end, draw the normalized data.
133 | Vector2 previousPoint = pointList[0];
134 | for (int i = 1; i < pointList.Count; i++) {
135 | Vector2 currentPoint = pointList[i];
136 | DrawLine(canvas, previousPoint.x, previousPoint.y, currentPoint.x, currentPoint.y, Color.black);
137 | previousPoint = currentPoint;
138 | }
139 |
140 | canvas.Apply();
141 |
142 | //The checker method only receives canvas if you want the points used drawn on the screen,
143 | //can just receive a points list otherwise.
144 | gResult = gu.GestureChecker(pointList, canvas, CANVAS_SIZE);
145 |
146 | switch(gResult) {
147 | case GestureUtils.EnumGestures.DownZigZag:
148 | Debug.Log("Downwards Zig Zag!");
149 | status = "Downwards Zig Zag!";
150 | break;
151 | case GestureUtils.EnumGestures.RightZigZag:
152 | Debug.Log("Rightwards Zig Zag!");
153 | status = "Rightwards Zig Zag!";
154 | break;
155 | case GestureUtils.EnumGestures.Square:
156 | Debug.Log("Square!");
157 | status = "Square!";
158 | break;
159 | default:
160 | Debug.Log("No Gesture found.");
161 | status = "Nothing.";
162 | break;
163 | }
164 |
165 | }
166 |
167 | ///
168 | /// Draws a line between the points passed.
169 | ///
170 | ///
171 | /// Texture to draw on.
172 | ///
173 | ///
174 | /// X coordinate of point 1.
175 | ///
176 | ///
177 | /// Y coordinate of point 1.
178 | ///
179 | ///
180 | /// X coordinate of point 2.
181 | ///
182 | ///
183 | /// Y coordinate of point 2.
184 | ///
185 | ///
186 | /// Color to use.
187 | ///
188 | void DrawLine(Texture2D a_Texture, float x1, float y1, float x2, float y2, Color a_Color) {
189 |
190 | float b = x2 - x1;
191 | float h = y2 - y1;
192 | float l = Mathf.Abs(b);
193 | if (Mathf.Abs (h) > l) l = Mathf.Abs(h);
194 | int il = (int)l;
195 | float dx = b / (float)l;
196 | float dy = h / (float)l;
197 |
198 | for ( int i = 0; i <= il; i++ )
199 | {
200 | a_Texture.SetPixel((int)x1, a_Texture.height-(int)y1, a_Color);
201 |
202 | x1 += dx;
203 | y1 += dy;
204 | }
205 | }
206 |
207 | }
208 |
--------------------------------------------------------------------------------
/Assets/Scripts/LeapController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 33727fed51a764b3182a2d46ee61179e
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Scripts/PointSimplifier.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | * Copyright (c) 2013 Danilo Gaby Andersen Trindade
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9 | * and to permit persons to whom the Software is furnished to do so, subject to the
10 | * following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18 | * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | using System;
23 | using System.Collections.Generic;
24 | using UnityEngine;
25 |
26 | public class PointSimplifier
27 | {
28 | ///
29 | /// Runs the Ramer-Douglas-Peucker algorithm to straighten the lines in the point list.
30 | ///
31 | ///
32 | /// An ArrayList with the straightened lines.
33 | ///
34 | ///
35 | /// List of points to straighten.
36 | ///
37 | ///
38 | /// Precision in pixels of points to consider in the same line.
39 | ///
40 | ///
41 | /// Start of the pointList to consider. Default to 0;
42 | ///
43 | ///
44 | /// End of the pointList to consider. Negative numbers will be considered total size of the list. Default to -1.
45 | ///
46 | public static List RamerDouglasPeucker(List pointList, float precision, int startPosition = 0, int endPosition = -1) {
47 | float dmax = 0.0f;
48 | int index = -1;
49 |
50 | List resultList = new List();
51 |
52 | if (endPosition < 0) {
53 | endPosition = pointList.Count-1;
54 | }
55 |
56 | for (int i = startPosition; i < endPosition; i++) {
57 | float d = PerpendicularDistance(pointList[i], pointList[startPosition], pointList[endPosition]);
58 | if (d > dmax) {
59 | index = i;
60 | dmax = d;
61 | }
62 | }
63 |
64 | if (dmax >= precision) {
65 | List result2 = RamerDouglasPeucker(pointList, precision, index, endPosition);
66 | resultList = RamerDouglasPeucker(pointList, precision, startPosition, index);
67 |
68 | result2.RemoveAt(0);
69 | resultList.AddRange(result2);
70 | } else {
71 | resultList.Add(pointList[startPosition]);
72 | resultList.Add(pointList[endPosition]);
73 | }
74 |
75 | return resultList;
76 | }
77 |
78 | ///
79 | /// Calculates the distance between two points.
80 | ///
81 | ///
82 | /// The distance.
83 | ///
84 | ///
85 | /// First point.
86 | ///
87 | ///
88 | /// Second point.
89 | ///
90 | private static float PointDistance(Vector2 point1, Vector2 point2) {
91 | float dx = point1.x - point2.x;
92 | float dy = point1.y - point2.y;
93 | return (float)Math.Sqrt( dx*dx + dy*dy );
94 | }
95 |
96 | ///
97 | /// Calculates Angular Coefficient of a line between two different points.
98 | ///
99 | ///
100 | /// The coefficient.
101 | ///
102 | ///
103 | /// First point.
104 | ///
105 | ///
106 | /// Second point.
107 | ///
108 | private static float AngularCoefficient(Vector2 point1, Vector2 point2) {
109 | float yDiff = (point1.y - point2.y);
110 | float xDiff = (point1.x - point2.x);
111 | if (xDiff == 0.0f) xDiff = 0.0001f;
112 |
113 | return (yDiff/xDiff);
114 | }
115 |
116 | ///
117 | /// Calculates Y-Intercept from the angular coeficient of a line
118 | /// between two different points and one of these points.
119 | ///
120 | ///
121 | /// The Y-intercept.
122 | ///
123 | ///
124 | /// Point.
125 | ///
126 | ///
127 | /// Angular coeficient.
128 | ///
129 | private static float YIntercept(Vector2 point, float angularCoef) {
130 | return (point.y - (angularCoef*point.x));
131 | }
132 |
133 | ///
134 | /// Calculates the distance from a point to a line.
135 | ///
136 | ///
137 | /// The distance.
138 | ///
139 | ///
140 | /// Point.
141 | ///
142 | ///
143 | /// Line start point.
144 | ///
145 | ///
146 | /// Line end point.
147 | ///
148 | private static float PerpendicularDistance(Vector2 point, Vector2 lineStartPoint, Vector2 lineEndPoint) {
149 |
150 | float d = 0.0f;
151 | float denom = 0.0001f;
152 |
153 | if (lineStartPoint.x == lineEndPoint.x) {
154 | return (Math.Abs(point.x - lineStartPoint.x));
155 | } else {
156 | float angCoef = AngularCoefficient(lineStartPoint, lineEndPoint);
157 | float yInter = YIntercept(lineStartPoint, angCoef);
158 |
159 | d = Math.Abs((angCoef*point.x)-point.y+yInter);
160 | denom = (float)Math.Sqrt((angCoef*angCoef)+1);
161 | }
162 |
163 | return (d/denom);
164 | }
165 |
166 | }
167 |
168 |
--------------------------------------------------------------------------------
/Assets/Scripts/PointSimplifier.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fcd89b7b47e7f424e993bccca45ff464
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Textures.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b92860cea1e5446f4929289eaacf7deb
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Textures/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Textures/.DS_Store
--------------------------------------------------------------------------------
/Assets/Textures/BaseTexture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Textures/BaseTexture.png
--------------------------------------------------------------------------------
/Assets/Textures/BaseTexture.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3d841e48d4f9c42b993fe1b70153645b
3 | TextureImporter:
4 | serializedVersion: 2
5 | mipmaps:
6 | mipMapMode: 0
7 | enableMipMap: 1
8 | linearTexture: 0
9 | correctGamma: 0
10 | fadeOut: 0
11 | borderMipMap: 0
12 | mipMapFadeDistanceStart: 1
13 | mipMapFadeDistanceEnd: 3
14 | bumpmap:
15 | convertToNormalMap: 0
16 | externalNormalMap: 0
17 | heightScale: .25
18 | normalMapFilter: 0
19 | isReadable: 1
20 | grayScaleToAlpha: 0
21 | generateCubemap: 0
22 | seamlessCubemap: 0
23 | textureFormat: -1
24 | maxTextureSize: 1024
25 | textureSettings:
26 | filterMode: -1
27 | aniso: -1
28 | mipBias: -1
29 | wrapMode: -1
30 | nPOTScale: 1
31 | lightmap: 0
32 | compressionQuality: 50
33 | textureType: 5
34 | buildTargetSettings: []
35 | userData:
36 |
--------------------------------------------------------------------------------
/Assets/Textures/gesture_downzig.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Textures/gesture_downzig.jpg
--------------------------------------------------------------------------------
/Assets/Textures/gesture_downzig.jpg.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 54c698e2b0fd04a9b97111c347824d62
3 | TextureImporter:
4 | serializedVersion: 2
5 | mipmaps:
6 | mipMapMode: 0
7 | enableMipMap: 1
8 | linearTexture: 0
9 | correctGamma: 0
10 | fadeOut: 0
11 | borderMipMap: 0
12 | mipMapFadeDistanceStart: 1
13 | mipMapFadeDistanceEnd: 3
14 | bumpmap:
15 | convertToNormalMap: 0
16 | externalNormalMap: 0
17 | heightScale: .25
18 | normalMapFilter: 0
19 | isReadable: 0
20 | grayScaleToAlpha: 0
21 | generateCubemap: 0
22 | seamlessCubemap: 0
23 | textureFormat: -1
24 | maxTextureSize: 1024
25 | textureSettings:
26 | filterMode: -1
27 | aniso: -1
28 | mipBias: -1
29 | wrapMode: -1
30 | nPOTScale: 1
31 | lightmap: 0
32 | compressionQuality: 50
33 | textureType: -1
34 | buildTargetSettings: []
35 | userData:
36 |
--------------------------------------------------------------------------------
/Assets/Textures/gesture_rightzig.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Textures/gesture_rightzig.jpg
--------------------------------------------------------------------------------
/Assets/Textures/gesture_rightzig.jpg.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 77e7178ae568142d69ef60f3da62f952
3 | TextureImporter:
4 | serializedVersion: 2
5 | mipmaps:
6 | mipMapMode: 0
7 | enableMipMap: 1
8 | linearTexture: 0
9 | correctGamma: 0
10 | fadeOut: 0
11 | borderMipMap: 0
12 | mipMapFadeDistanceStart: 1
13 | mipMapFadeDistanceEnd: 3
14 | bumpmap:
15 | convertToNormalMap: 0
16 | externalNormalMap: 0
17 | heightScale: .25
18 | normalMapFilter: 0
19 | isReadable: 0
20 | grayScaleToAlpha: 0
21 | generateCubemap: 0
22 | seamlessCubemap: 0
23 | textureFormat: -1
24 | maxTextureSize: 1024
25 | textureSettings:
26 | filterMode: -1
27 | aniso: -1
28 | mipBias: -1
29 | wrapMode: -1
30 | nPOTScale: 1
31 | lightmap: 0
32 | compressionQuality: 50
33 | textureType: -1
34 | buildTargetSettings: []
35 | userData:
36 |
--------------------------------------------------------------------------------
/Assets/Textures/gesture_square.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Assets/Textures/gesture_square.jpg
--------------------------------------------------------------------------------
/Assets/Textures/gesture_square.jpg.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2f990a96ab35a40d18a35befbaeaba4c
3 | TextureImporter:
4 | serializedVersion: 2
5 | mipmaps:
6 | mipMapMode: 0
7 | enableMipMap: 1
8 | linearTexture: 0
9 | correctGamma: 0
10 | fadeOut: 0
11 | borderMipMap: 0
12 | mipMapFadeDistanceStart: 1
13 | mipMapFadeDistanceEnd: 3
14 | bumpmap:
15 | convertToNormalMap: 0
16 | externalNormalMap: 0
17 | heightScale: .25
18 | normalMapFilter: 0
19 | isReadable: 0
20 | grayScaleToAlpha: 0
21 | generateCubemap: 0
22 | seamlessCubemap: 0
23 | textureFormat: -1
24 | maxTextureSize: 1024
25 | textureSettings:
26 | filterMode: -1
27 | aniso: -1
28 | mipBias: -1
29 | wrapMode: -1
30 | nPOTScale: 1
31 | lightmap: 0
32 | compressionQuality: 50
33 | textureType: -1
34 | buildTargetSettings: []
35 | userData:
36 |
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/NavMeshLayers.asset
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Leap Motion - Unity 3D Pattern Recognition
2 | =============
3 |
4 | Simple Unity example showing how to detect gesture patterns by straightening the point collection
5 | from the leap frames, using the Ramer-Douglas-Peucker algorithm, and then comparing the sharp
6 | turns made during the gesture.
7 |
8 | For more information on the Ramer-Douglas-Peucker algorithm, check
9 | http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
10 |
11 | The examples shows the path that the Leap Motion device recognized and the points being considered
12 | when detecting the pattern made. The small squares are points still considered after a high precision
13 | passing of the Ramer-Douglas-Peucker algorithm, and the big squares are points considered after a
14 | lower precision pass on the algorithm, which is done if no gestures were detected with the first.
15 |
16 | Gestures this example is able to detect:
17 |
18 |   
19 |
20 | Video showing the detection:
21 | http://www.youtube.com/watch?v=T26jokJPqRk
22 |
23 |
24 |
25 | License info:
26 |
27 | The MIT License (MIT)
28 | Copyright (c) 2013 Danilo Gaby Andersen Trindade
29 |
30 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
31 |
32 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
33 |
34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 |
--------------------------------------------------------------------------------
/Screenshots/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Screenshots/.DS_Store
--------------------------------------------------------------------------------
/Screenshots/gesture_downzig.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Screenshots/gesture_downzig.jpg
--------------------------------------------------------------------------------
/Screenshots/gesture_rightzig.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Screenshots/gesture_rightzig.jpg
--------------------------------------------------------------------------------
/Screenshots/gesture_square.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DaniloT/leap_patterns/0ef5f01712c968a880da708e9a6ff56f4e86153f/Screenshots/gesture_square.jpg
--------------------------------------------------------------------------------
/leap_patterns.userprefs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------