fingerDemo.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function LeapToy::createFingerLevel( %this )
  23. {
  24. // Create background.
  25. %this.createBackground();
  26. // Create the ground.
  27. %this.createGround();
  28. // Create circles that will track the fingers
  29. %this.createFingerCircles();
  30. // Set the gravity.
  31. SandboxScene.setGravity( 0, 0);
  32. // Set the manipulation mode.
  33. Sandbox.useManipulation( off );
  34. // Swap action maps
  35. // Swap action maps
  36. GestureMap.pop();
  37. BreakoutMap.pop();
  38. FingerMap.push();
  39. // Create the help text scene
  40. %helpText = new SimSet();
  41. %helpText.add(new ScriptObject() { Text = "This demo will track pointables."; });
  42. %helpText.add(new ScriptObject() { Text = " "; });
  43. %helpText.add(new ScriptObject() { Text = "Whenever the Leap Motion device detects a finger"; });
  44. %helpText.add(new ScriptObject() { Text = "or tool, a circle will appear on screen."; });
  45. %helpText.add(new ScriptObject() { Text = " "; });
  46. %helpText.add(new ScriptObject() { Text = "Press H to return to the demo."; });
  47. %this.createHelpTextScene(%helpText);
  48. %helpText.delete();
  49. }
  50. //-----------------------------------------------------------------------------
  51. function LeapToy::createFingerCircles(%this)
  52. {
  53. for (%i = 0; %i < 10; %i++)
  54. {
  55. %name = "Finger" @ %i;
  56. // Create the circle.
  57. %circle = new Sprite();
  58. %circle.setName(%name);
  59. %circle.Position = "-10 5";
  60. %circle.setBodyType("Kinematic");
  61. %circle.Size = 5;
  62. %circle.Image = "LeapToy:circleThree";
  63. %circle.Visible = false;
  64. %circle.AngularVelocity = 180;
  65. %this.fingers[%i] = %circle;
  66. // Add to the scene.
  67. SandboxScene.add( %circle );
  68. }
  69. }
  70. //-----------------------------------------------------------------------------
  71. function LeapToy::showFingerCircle(%this, %id, %worldPosition)
  72. {
  73. echo("Finger " SPC %id SPC ":" SPC %worldPosition);
  74. %finger = %this.fingers[%id];
  75. if (!isObject(%finger))
  76. return;
  77. if (!%finger.visible)
  78. {
  79. %finger.visible = true;
  80. }
  81. %finger.setPosition(%worldPosition);
  82. %this.schedule(100, "checkFingerActivity", %id, %worldPosition);
  83. }
  84. //-----------------------------------------------------------------------------
  85. function LeapToy::checkFingerActivity(%this, %id, %worldPosition)
  86. {
  87. %finger = %this.fingers[%id];
  88. // Likely no activity, since the device is sensitive
  89. if (%finger.position $= %worldPosition)
  90. %finger.visible = false;
  91. }