index.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>Proof of concept - Objets tangibles</title>
  7. </head>
  8. <body>
  9. <script src="/jquery-1.7.2.js"></script>
  10. <script src="/lodash.js"></script>
  11. <script src="/socket.io/socket.io.js"></script>
  12. <script src="/tuio.js"></script>
  13. <style>
  14. body {
  15. background: #000;
  16. margin: 0;
  17. }
  18. .tuioCursor {
  19. background: #fff;
  20. height: 8px;
  21. left: 0;
  22. position: absolute;
  23. top: 0;
  24. width: 8px;
  25. }
  26. .tuioObj {
  27. background: #f00;
  28. height: 15px;
  29. left: 0;
  30. position: absolute;
  31. top: 0;
  32. width: 8px;
  33. rotate: 0deg;
  34. }
  35. </style>
  36. <script>
  37. $(function() {
  38. const urlParams = new URLSearchParams(window.location.search);
  39. const debugParams = urlParams.get('debug');
  40. const debug = debugParams ? true : false;
  41. if (debug) {
  42. console.log('--- Debug activated ---');
  43. }
  44. var dotGroups = [];
  45. var client = new Tuio.Client({
  46. host: 'http://localhost:5000'
  47. }),
  48. screenW = $(document).width(),
  49. screenH = $(document).height()
  50. cursors = {},
  51. objects = {},
  52. onConnect = function() {
  53. if (debug) {
  54. console.log('connected');
  55. }
  56. },
  57. onAddTuioCursor = function(addCursor) {
  58. var $addCursor = $('<div class="tuioCursor"></div>');
  59. $('body').append($addCursor);
  60. cursors[addCursor.getCursorId()] = $addCursor;
  61. onUpdateTuioCursor(addCursor);
  62. },
  63. onUpdateTuioCursor = function(updateCursor) {
  64. var $updateCursor = cursors[updateCursor.getCursorId()];
  65. $updateCursor.css({
  66. left: updateCursor.getScreenX(screenW),
  67. top: updateCursor.getScreenY(screenH)
  68. });
  69. },
  70. onRemoveTuioCursor = function(removeCursor) {
  71. var $removeCursor = cursors[removeCursor.getCursorId()];
  72. $removeCursor.remove();
  73. delete[removeCursor.getCursorId()];
  74. },
  75. onAddTuioObject = function(addObject) {
  76. var $addObject = $('<div class="tuioObj"></div>');
  77. $('body').append($addObject);
  78. objects[addObject.symbolID] = $addObject;
  79. onUpdateTuioObject(addObject);
  80. if (debug) {
  81. console.log('addTuioObject', addObject);
  82. console.log(objects);
  83. }
  84. },
  85. onUpdateTuioObject = function(updateObject) {
  86. var $updateObject = objects[updateObject.symbolID];
  87. $updateObject.css({
  88. left: updateObject.getScreenX(screenW),
  89. top: updateObject.getScreenY(screenH),
  90. rotate : updateObject.getAngleDegrees()
  91. });
  92. if (debug) {
  93. console.log('updateTuioObject', updateObject);
  94. }
  95. },
  96. onRemoveTuioObject = function(removeObject) {
  97. var $removeObject = objects[removeObject.symbolID];
  98. $removeObject.remove();
  99. delete[removeObject.symbolID];
  100. if (debug) {
  101. console.log('removeTuioObject', removeObject);
  102. }
  103. },
  104. onRefresh = function(time) {
  105. };
  106. client.on("connect", onConnect);
  107. client.on("addTuioCursor", onAddTuioCursor);
  108. client.on("updateTuioCursor", onUpdateTuioCursor);
  109. client.on("removeTuioCursor", onRemoveTuioCursor);
  110. client.on("addTuioObject", onAddTuioObject);
  111. client.on("updateTuioObject", onUpdateTuioObject);
  112. client.on("removeTuioObject", onRemoveTuioObject);
  113. client.on("refresh", onRefresh);
  114. client.connect();
  115. });
  116. </script>
  117. </body>
  118. </html>