1 /** 2 * potree.js 3 * http://potree.org 4 * 5 * Copyright 2012, Markus Sch�tz 6 * Licensed under the GPL Version 2 or later. 7 * - http://potree.org/wp/?page_id=7 8 * - http://www.gnu.org/licenses/gpl-3.0.html 9 * 10 */ 11 12 /** 13 * 14 * @param camera 15 * @class fly like a bird 16 * @augments CamHandler 17 * @author Markus Sch�tz 18 */ 19 function FreeFlightCamHandler(camera){ 20 this.camera = camera; 21 this.velocity = [0,0,0]; 22 this.targetVelocity = [0,0,0]; 23 this.targetVelocityMultiplicator = 20.0; 24 this.x = 0; 25 this.y = 0; 26 this.speedMultiplier = 0.2; 27 this.qualityToggle = 0; 28 } 29 30 FreeFlightCamHandler.prototype = new CamHandler(); 31 32 FreeFlightCamHandler.prototype.update = function(time){ 33 this.velocity[0] = 0.2 *this.velocity[0] + 0.8 * this.targetVelocity[0] * this.targetVelocityMultiplicator; 34 this.velocity[1] = 0.2 *this.velocity[1] + 0.8 * this.targetVelocity[1] * this.targetVelocityMultiplicator; 35 this.velocity[2] = 0.2 *this.velocity[2] + 0.8 * this.targetVelocity[2] * this.targetVelocityMultiplicator; 36 37 var t = [this.velocity[0]* time, this.velocity[1]* time, this.velocity[2] * time]; 38 39 this.camera.translate(t[0], t[1], t[2]); 40 41 //Potree.isLowQualityMode = this.qualityToggle > 0 || V3.length(this.velocity) > 0.1; 42 if(this.qualityToggle > 0){ 43 this.qualityToggle -= time; 44 } 45 }; 46 47 FreeFlightCamHandler.prototype.invokeKeyDown = function(event){ 48 if(event.which == 83 ){ 49 //s 50 this.targetVelocity[2] = 1 * this.speedMultiplier; 51 }else if(event.which == 87 ){ 52 //w 53 this.targetVelocity[2] = -1 * this.speedMultiplier; 54 }else if(event.which == 68 ){ 55 //d 56 this.targetVelocity[0] = 1 * this.speedMultiplier; 57 }else if(event.which == 65 ){ 58 //a 59 this.targetVelocity[0] = -1 * this.speedMultiplier; 60 } 61 62 63 }; 64 65 FreeFlightCamHandler.prototype.invokeKeyUp = function(event){ 66 if(event.which == 83 ){ 67 //s 68 this.targetVelocity[2] = 0; 69 }else if(event.which == 87 ){ 70 //w 71 this.targetVelocity[2] = 0; 72 }else if(event.which == 68 ){ 73 //d 74 this.targetVelocity[0] = 0; 75 }else if(event.which == 65 ){ 76 //a 77 this.targetVelocity[0] = 0; 78 } 79 80 }; 81 82 FreeFlightCamHandler.prototype.invokeKeyPress = function(event){ 83 84 }; 85 86 FreeFlightCamHandler.prototype.invokeMouseDown = function(event){ 87 88 }; 89 90 FreeFlightCamHandler.prototype.invokeMouseUp = function(event){ 91 }; 92 93 FreeFlightCamHandler.prototype.invokeMouseMove = function(event, diffX, diffY){ 94 95 }; 96 97 FreeFlightCamHandler.prototype.invokeMouseDrag = function(event, pressedKeys, diffX, diffY){ 98 99 if(pressedKeys.length == 1 && pressedKeys.contains(0) && KeyListener.pressedKeys.contains(18)){ 100 this.camera.translate((this.speedMultiplier * -diffX) / 10.0, (this.speedMultiplier * diffY) / 10.0, 0); 101 this.qualityToggle = 0.1; 102 }else if(pressedKeys.length == 1 && pressedKeys.contains(0)){ 103 var pos = this.camera.localPosition; 104 105 var toOrigin = M4x4.translate3(-pos[0], -pos[1], -pos[2], M4x4.I); 106 var rotY = M4x4.rotate(-diffX / 100.0, [0,1,0], M4x4.I); 107 var rotX = M4x4.rotate(-diffY / 100.0, this.camera.getSideVector(), M4x4.I); 108 var backToPos = M4x4.translate3(pos[0], pos[1], pos[2], M4x4.I); 109 110 var transform = M4x4.mul(toOrigin, this.camera.transform); 111 transform = M4x4.mul(rotX, transform); 112 transform = M4x4.mul(backToPos, transform); 113 //this.camera.setTransform(transform); 114 this.camera.transform = transform; 115 116 117 var transform = M4x4.mul(toOrigin, this.camera.transform); 118 transform = M4x4.mul(rotY, transform); 119 transform = M4x4.mul(backToPos, transform); 120 //this.camera.setTransform(transform); 121 this.camera.transform = transform; 122 this.qualityToggle = 0.1; 123 } 124 125 126 }; 127 128 FreeFlightCamHandler.prototype.invokeMouseWheel = function(delta){ 129 // var amount = -delta / 100.0; 130 // this.camera.translate(0,0,amount); 131 132 var amount = delta / 2000.0; 133 this.speedMultiplier += amount; 134 this.speedMultiplier = Math.max(0.01, Math.min(10.0, this.speedMultiplier)); 135 }; 136 137