Anders and Briegel in Python
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

67 行
1.5KB

  1. var mouse = {};
  2. mouse.wasClick = true;
  3. mouse.raycaster = new THREE.Raycaster();
  4. mouse.onFreeMove = function() {
  5. console.log("Free move");
  6. };
  7. mouse.onDrag = function() {
  8. console.log("Drag");
  9. };
  10. mouse.onClick = function() {
  11. console.log("Click");
  12. };
  13. mouse.onCtrlClick = function() {
  14. console.log("Ctrl-click");
  15. };
  16. mouse.onShiftClick = function() {
  17. console.log("Shift-click");
  18. };
  19. mouse.prepare = function() {
  20. var el = gui.renderer.domElement;
  21. el.addEventListener("mousedown", mouse.onDown);
  22. el.addEventListener("mouseup", mouse.onUp);
  23. el.addEventListener("mousemove", mouse.onMove);
  24. };
  25. mouse.onDown = function(event) {
  26. mouse.wasClick = true;
  27. mouse.pressed = true;
  28. };
  29. mouse.onUp = function(event) {
  30. if (!mouse.wasClick) {
  31. return;
  32. }
  33. mouse.pressed = false;
  34. if (event.ctrlKey) {
  35. mouse.onCtrlClick();
  36. } else if (event.shiftKey) {
  37. mouse.onShiftClick();
  38. } else {
  39. mouse.onClick();
  40. }
  41. };
  42. mouse.onMove = function(event) {
  43. mouse.wasClick = false;
  44. mouse.position_absolute = {
  45. x: event.clientX,
  46. y: event.clientY
  47. };
  48. mouse.position_relative = {
  49. x: (event.clientX / window.innerWidth) * 2 - 1,
  50. y: -(event.clientY / window.innerHeight) * 2 + 1
  51. };
  52. gui.setInfoPosition(mouse.position_absolute);
  53. mouse.raycaster.setFromCamera(mouse.position_relative, gui.camera);
  54. mouse.ray = mouse.raycaster.ray;
  55. if (mouse.pressed) {
  56. mouse.onDrag();
  57. } else {
  58. mouse.onFreeMove();
  59. }
  60. };