drag.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. this.moveAction = function(controllerID, point){
  2. let pos = this.parent.localToWorld(this.position);
  3. if( point && this.pointerDragStart){
  4. let newPos = new THREE.Vector3().subVectors(point, this.pointerDragStart);
  5. if(this.lockZ){
  6. this.position = this.parent.worldToLocal(new THREE.Vector3(newPos.x, newPos.y, pos.z)); //[newPos.x, newPos.y, newPos.z]
  7. } else {
  8. this.position = this.parent.worldToLocal(newPos);
  9. }
  10. this.positionChanged();
  11. }
  12. }
  13. this.doButtonTriggerupAction = function(buttonID, controllerID){
  14. let pointer = this.getScene().findNodeByID(controllerID);
  15. this.pointerDragStart = false;
  16. pointer.dragID = false;
  17. }
  18. this.doButtonTriggerdownAction = function(buttonID, controllerID, point){
  19. let pointer = this.getScene().findNodeByID(controllerID);
  20. if(point) {
  21. //console.log('POINT:', point);
  22. let wp = new THREE.Vector3().subVectors( point, this.parent.localToWorld(this.position));
  23. this.pointerDragStart = wp;
  24. }
  25. pointer.dragID = this.id;
  26. }
  27. this.mousedownAction = function(point, controllerID){
  28. this.triggerdownAction(point, controllerID);
  29. }
  30. this.mouseupAction = function(point, controllerID){
  31. this.triggerupAction(point, controllerID);
  32. }
  33. this.triggerdownAction = function(point, controllerID){
  34. this.doButtonTriggerdownAction(this.id, controllerID, point);
  35. }
  36. this.triggerupAction = function(point, controllerID){
  37. this.doButtonTriggerupAction(this.id, controllerID);
  38. }