(delta)
| 267 | } |
| 268 | |
| 269 | update(delta) { |
| 270 | let factor = (1 - Math.exp(-delta / this.tau)); |
| 271 | |
| 272 | this.currentMethod.updateReferences(); |
| 273 | this.currentMethod.computeReferences(); |
| 274 | let refRot = this.currentMethod.getReferenceRot(); |
| 275 | let refVp = this.currentMethod.getReferenceVp(); |
| 276 | let refDist = this.currentMethod.getReferenceDist(); |
| 277 | |
| 278 | // Compute residuals |
| 279 | let resPh = refRot.x - this.currentRot.x; |
| 280 | let resTh = refRot.y - this.currentRot.y; |
| 281 | let resPs = refRot.z - this.currentRot.z; |
| 282 | |
| 283 | if (resTh > Math.PI) { |
| 284 | resTh -= Math.PI * 2; |
| 285 | this.currentRot.y += Math.PI * 2 |
| 286 | } |
| 287 | if (resTh < -Math.PI) { |
| 288 | resTh += Math.PI * 2; |
| 289 | this.currentRot.y -= Math.PI * 2 |
| 290 | } |
| 291 | |
| 292 | let resX = refVp.x - this.currentVp.x; |
| 293 | let resY = refVp.y - this.currentVp.y; |
| 294 | let resZ = refVp.z - this.currentVp.z; |
| 295 | |
| 296 | let resDist = refDist - this.currentDist; |
| 297 | |
| 298 | // Update variables |
| 299 | this.currentRot.x += resPh * factor; |
| 300 | this.currentRot.y += resTh * factor; |
| 301 | this.currentRot.z += resPs * factor; |
| 302 | this.currentVp.x += resX * factor; |
| 303 | this.currentVp.y += resY * factor; |
| 304 | this.currentVp.z += resZ * factor; |
| 305 | this.currentDist += resDist * factor; |
| 306 | |
| 307 | // Apply to camera. |
| 308 | this.camera.rotation.x = this.currentRot.x; |
| 309 | this.camera.rotation.y = this.currentRot.y; |
| 310 | this.camera.rotation.z = this.currentRot.z; |
| 311 | |
| 312 | let eye = new THREE.Vector3(0, 0, 0); |
| 313 | eye.x = -Math.cos(this.currentRot.x) * Math.sin(this.currentRot.y); |
| 314 | eye.y = Math.sin(this.currentRot.x); |
| 315 | eye.z = -Math.cos(this.currentRot.x) * Math.cos(this.currentRot.y); |
| 316 | |
| 317 | let center = new THREE.Vector3(); |
| 318 | center.copy(this.currentVp); |
| 319 | center.x -= eye.x * this.currentDist; |
| 320 | center.y -= eye.y * this.currentDist; |
| 321 | center.z -= eye.z * this.currentDist; |
| 322 | this.camera.position.x = center.x; |
| 323 | this.camera.position.y = center.y; |
| 324 | this.camera.position.z = center.z; |
| 325 | } |
| 326 | } |
no test coverage detected