index.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. </style>
  27. <script>
  28. function getHypotenuse(touch1, touch2, screenW, screenH) {
  29. var w = Math.abs(touch1.w - touch2.w);
  30. var h = Math.abs(touch1.h - touch2.h);
  31. return Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2));
  32. }
  33. $(function() {
  34. var client = new Tuio.Client({
  35. host: 'http://localhost:5000'
  36. }),
  37. screenW = $(document).width(),
  38. screenH = $(document).height()
  39. cursors = {},
  40. onConnect = function() {
  41. console.log('connected');
  42. },
  43. onAddTuioCursor = function(addCursor) {
  44. var $addCursor = $('<div class="tuioCursor"></div>');
  45. $('body').append($addCursor);
  46. cursors[addCursor.getCursorId()] = $addCursor;
  47. onUpdateTuioCursor(addCursor);
  48. },
  49. onUpdateTuioCursor = function(updateCursor) {
  50. var $updateCursor = cursors[updateCursor.getCursorId()];
  51. $updateCursor.css({
  52. left: updateCursor.getScreenX(screenW),
  53. top: updateCursor.getScreenY(screenH)
  54. });
  55. var cursorIds = Object.keys(cursors);
  56. var dots = [];
  57. cursorIds.forEach(function(cursor) {
  58. dots.push({
  59. id: cursor,
  60. w: cursors[cursor][0].offsetLeft,
  61. h: cursors[cursor][0].offsetTop
  62. });
  63. });
  64. var groups = {};
  65. for (var i = 0; i < dots.length; i++) {
  66. for (var j = 0; j < dots.length; j++) {
  67. if (j !== i) {
  68. var hyp = getHypotenuse(dots[i], dots[j]);
  69. console.log(i, j, hyp);
  70. }
  71. }
  72. }
  73. },
  74. onRemoveTuioCursor = function(removeCursor) {
  75. //console.log('remove', removeCursor);
  76. var $removeCursor = cursors[removeCursor.getCursorId()];
  77. $removeCursor.remove();
  78. delete[removeCursor.getCursorId()];
  79. },
  80. onAddTuioObject = function(addObject) {
  81. console.log(addObject);
  82. },
  83. onUpdateTuioObject = function(updateObject) {
  84. console.log(updateObject);
  85. },
  86. onRemoveTuioObject = function(removeObject) {
  87. console.log(removeObject);
  88. },
  89. onRefresh = function(time) {
  90. };
  91. client.on("connect", onConnect);
  92. client.on("addTuioCursor", onAddTuioCursor);
  93. client.on("updateTuioCursor", onUpdateTuioCursor);
  94. client.on("removeTuioCursor", onRemoveTuioCursor);
  95. client.on("addTuioObject", onAddTuioObject);
  96. client.on("updateTuioObject", onUpdateTuioObject);
  97. client.on("removeTuioObject", onRemoveTuioObject);
  98. client.on("refresh", onRefresh);
  99. client.connect();
  100. });
  101. </script>
  102. </body>
  103. </html>