Skip to content

Commit

Permalink
zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Oct 26, 2023
1 parent 4c14356 commit 359b5da
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions dist/diagram.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@testing-library/dom": "^9.3.3",
"@types/chai": "^4.3.9",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.8",
"@types/node": "^20.8.9",
"@types/three": "^0.157.2",
"chai": "^4.3.10",
"ini": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/controller/controllerbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export abstract class ControllerBase extends Controller {
return true
case "movementYUp":
case "NumpadSubtract":
this.container.view.camera.adjustHeight(-delta * 10)
this.container.view.camera.adjustHeight(-delta * 8)
return true
case "NumpadAdd":
this.container.view.camera.adjustHeight(delta * 10)
this.container.view.camera.adjustHeight(delta * 8)
return true
case "KeyOUp":
this.container.view.camera.toggleMode()
Expand Down
11 changes: 7 additions & 4 deletions src/events/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ export class Keyboard {
mousetouch = (e) => {
const factor = e.ctrlKey ? 0.5 : 1
const dx = e.dx * factor
if (this.released["movementX"]) {
this.released["movementX"] += dx
} else {
this.released["movementX"] = dx
const dy = e.dy * factor
if (Math.abs(dy) > 3 * Math.abs(dx)) {
const cy = this.released["movementY"] ?? 0.0
this.released["movementY"] = cy + dy
return
}
const cx = this.released["movementX"] ?? 0.0
this.released["movementX"] = cx + dx
}

private addHandlers(element: HTMLCanvasElement) {
Expand Down
19 changes: 16 additions & 3 deletions src/view/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,31 @@ export class Camera {
}

aimView(aim: AimEvent, fraction = 0.08) {
const h = this.height
this.camera.fov = this.camera.aspect < 0.8 ? 60 : 40
if (h < 10 * R) {
const factor = 100 * (10 * R - h)
this.camera.fov -= factor
console.log(this.camera.fov)
}
this.camera.position.lerp(
aim.pos.clone().addScaledVector(unitAtAngle(aim.angle), -R * 18),
fraction
)
this.camera.position.z = this.height
this.camera.position.z = h
this.camera.up = up
this.camera.lookAt(aim.pos.clone().addScaledVector(up, 2 * R))
this.camera.lookAt(aim.pos.clone().addScaledVector(up, h / 2))
}

adjustHeight(delta) {
this.height = MathUtils.clamp(this.height + delta, 1, 6)
delta = this.height < 10 * R ? delta / 8 : delta
this.height = MathUtils.clamp(this.height + delta, R * 6, R * 120)
if (this.height > R * 100) {
this.suggestMode(this.topView)
}
if (this.height < R * 70) {
this.suggestMode(this.aimView)
}
}

suggestMode(mode) {
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,12 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.4.tgz#a4ed836e069491414bab92c31fdea9e557aca0d9"
integrity sha512-1Gjee59G25MrQGk8bsNvC6fxNiRgUlGn2wlhGf95a59DrprnnHk80FIMMFG9XHMdrfsuA119ht06QPDXA1Z7tw==

"@types/node@*", "@types/node@^20.8.8":
version "20.8.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.8.tgz#adee050b422061ad5255fc38ff71b2bb96ea2a0e"
integrity sha512-YRsdVxq6OaLfmR9Hy816IMp33xOBjfyOgUd77ehqg96CFywxAPbDbXvAsuN2KVg2HOT8Eh6uAfU+l4WffwPVrQ==
"@types/node@*", "@types/node@^20.8.9":
version "20.8.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.9.tgz#646390b4fab269abce59c308fc286dcd818a2b08"
integrity sha512-UzykFsT3FhHb1h7yD4CA4YhBHq545JC0YnEz41xkipN88eKQtL6rSgocL5tbAP6Ola9Izm/Aw4Ora8He4x0BHg==
dependencies:
undici-types "~5.25.1"
undici-types "~5.26.4"

"@types/qs@*":
version "6.9.9"
Expand Down Expand Up @@ -1571,9 +1571,9 @@ camelcase@^6.0.0, camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001541:
version "1.0.30001553"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001553.tgz#e64e7dc8fd4885cd246bb476471420beb5e474b5"
integrity sha512-N0ttd6TrFfuqKNi+pMgWJTb9qrdJu4JSpgPFLe/lrD19ugC6fZgF0pUewRowDwzdDnb9V41mFcdlYgl/PyKf4A==
version "1.0.30001554"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001554.tgz#ba80d88dff9acbc0cd4b7535fc30e0191c5e2e2a"
integrity sha512-A2E3U//MBwbJVzebddm1YfNp7Nud5Ip+IPn4BozBmn4KqVX7AvluoIDFWjsv5OkGnKUXQVmMSoMKLa3ScCblcQ==

chai@^4.3.10:
version "4.3.10"
Expand Down Expand Up @@ -2022,9 +2022,9 @@ ee-first@1.1.1:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.535:
version "1.4.565"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.565.tgz#205f3746a759ec3c43bce98b9eef5445f2721ea9"
integrity sha512-XbMoT6yIvg2xzcbs5hCADi0dXBh4//En3oFXmtPX+jiyyiCTiM9DGFT2SLottjpEs9Z8Mh8SqahbR96MaHfuSg==
version "1.4.567"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.567.tgz#c92e8fbc2bd15df3068d92571733a218a5413add"
integrity sha512-8KR114CAYQ4/r5EIEsOmOMqQ9j0MRbJZR3aXD/KFA8RuKzyoUB4XrUCg+l8RUGqTVQgKNIgTpjaG8YHRPAbX2w==

emittery@^0.13.1:
version "0.13.1"
Expand Down Expand Up @@ -4713,10 +4713,10 @@ undefsafe@^2.0.5:
resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.5.tgz#38733b9327bdcd226db889fb723a6efd162e6e2c"
integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==

undici-types@~5.25.1:
version "5.25.3"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.25.3.tgz#e044115914c85f0bcbb229f346ab739f064998c3"
integrity sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==
undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

universalify@^0.2.0:
version "0.2.0"
Expand Down

0 comments on commit 359b5da

Please sign in to comment.