Anders and Briegel in Python
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

69 satır
1.6KB

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