Advertisement
Guest User

Untitled

a guest
Oct 14th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. var MouseZoom = pc.createScript('mouseZoom');
  2. MouseZoom.attributes.add('targetFOV', { type: 'number' });
  3.  
  4. // initialize code called once per entity
  5. MouseZoom.prototype.initialize = function() {
  6. this.originalFOV = this.entity.camera.fov;
  7. this.pos = new pc.Vec3();
  8.  
  9. // Disabling the context menu stops the browser displaying a menu when
  10. // you right-click the page
  11. this.app.mouse.disableContextMenu();
  12.  
  13. this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
  14. this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
  15. };
  16.  
  17.  
  18. MouseZoom.prototype.onMouseDown = function (event) {
  19.  
  20. // If the right mouse button is pressed, apply the target FOV
  21. if (event.button === pc.MOUSEBUTTON_RIGHT) {
  22. this.entity.camera.fov = this.targetFOV;
  23.  
  24. //TODO: Set sensitivity down
  25. }
  26. };
  27.  
  28. MouseZoom.prototype.onMouseUp = function (event) {
  29.  
  30. // If the right mouse button is pressed, return to normal FOV.
  31. if (event.button === pc.MOUSEBUTTON_RIGHT) {
  32. this.entity.camera.fov = this.originalFOV;
  33. }
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement