From bb3b93d8ef6bb2f86f2e5ece157ea8f49af7e8d5 Mon Sep 17 00:00:00 2001
From: Marco Fugaro
Date: Tue, 13 Jul 2021 20:26:25 +0200
Subject: [PATCH 1/3] OrbitControls: add getDistance()
---
docs/examples/en/controls/OrbitControls.html | 5 +++++
docs/examples/ko/controls/OrbitControls.html | 5 +++++
docs/examples/zh/controls/OrbitControls.html | 5 +++++
examples/jsm/controls/OrbitControls.js | 6 ++++++
4 files changed, 21 insertions(+)
diff --git a/docs/examples/en/controls/OrbitControls.html b/docs/examples/en/controls/OrbitControls.html
index 4ed5eaf68e54db..98a8c7cfa1d5bb 100644
--- a/docs/examples/en/controls/OrbitControls.html
+++ b/docs/examples/en/controls/OrbitControls.html
@@ -282,6 +282,11 @@ [method:radians getPolarAngle] ()
Get the current vertical rotation, in radians.
+ [method:radians getDistance] ()
+
+ Get the current dolly distance ( [page:PerspectiveCamera] only ).
+
+
[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )
Adds key event listeners to the given DOM element. *window* is a recommended argument for using this method.
diff --git a/docs/examples/ko/controls/OrbitControls.html b/docs/examples/ko/controls/OrbitControls.html
index 3631080311a3d0..5a3d8fb787b017 100644
--- a/docs/examples/ko/controls/OrbitControls.html
+++ b/docs/examples/ko/controls/OrbitControls.html
@@ -278,6 +278,11 @@
[method:radians getPolarAngle] ()
라디안 단위로 현재 수직 회전값을 가져옵니다.
+ [method:radians getDistance] ()
+
+ Get the current dolly distance ( [page:PerspectiveCamera] only ).
+
+
[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )
Adds key event listeners to the given DOM element. *window* is a recommended argument for using this method.
diff --git a/docs/examples/zh/controls/OrbitControls.html b/docs/examples/zh/controls/OrbitControls.html
index 659a8f276d8a5b..107520bd209b9a 100644
--- a/docs/examples/zh/controls/OrbitControls.html
+++ b/docs/examples/zh/controls/OrbitControls.html
@@ -280,6 +280,11 @@
[method:radians getPolarAngle] ()
获得当前的垂直旋转,单位为弧度。
+ [method:radians getDistance] ()
+
+ Get the current dolly distance ( [page:PerspectiveCamera] only ).
+
+
[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )
为指定的DOM元素添加按键监听。推荐将window作为指定的DOM元素。
diff --git a/examples/jsm/controls/OrbitControls.js b/examples/jsm/controls/OrbitControls.js
index 72362b88a1b22d..25a033fc8f029c 100644
--- a/examples/jsm/controls/OrbitControls.js
+++ b/examples/jsm/controls/OrbitControls.js
@@ -114,6 +114,12 @@ class OrbitControls extends EventDispatcher {
};
+ this.getDistance = function () {
+
+ return spherical.radius;
+
+ };
+
this.listenToKeyEvents = function ( domElement ) {
domElement.addEventListener( 'keydown', onKeyDown );
From eeed1c366c4f6273b586d9a371b44495166e5e54 Mon Sep 17 00:00:00 2001
From: Marco Fugaro
Date: Thu, 22 Jul 2021 14:55:26 +0200
Subject: [PATCH 2/3] OrbitControls: compute getDistance manually for
orthographic camera
---
examples/jsm/controls/OrbitControls.js | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/examples/jsm/controls/OrbitControls.js b/examples/jsm/controls/OrbitControls.js
index 25a033fc8f029c..17810b89d486a9 100644
--- a/examples/jsm/controls/OrbitControls.js
+++ b/examples/jsm/controls/OrbitControls.js
@@ -116,6 +116,13 @@ class OrbitControls extends EventDispatcher {
this.getDistance = function () {
+ // compute the distance manually if the camera is orthographic
+ if ( this.object.isOrthographicCamera ) {
+
+ return this.object.position.distanceTo( this.target );
+
+ }
+
return spherical.radius;
};
From 5da924d89c940aea9d9e2cacdea734c4cb1298b8 Mon Sep 17 00:00:00 2001
From: Marco Fugaro
Date: Thu, 22 Jul 2021 17:13:04 +0200
Subject: [PATCH 3/3] Simplify getDistance()
---
docs/examples/en/controls/OrbitControls.html | 4 ++--
docs/examples/ko/controls/OrbitControls.html | 4 ++--
docs/examples/zh/controls/OrbitControls.html | 4 ++--
examples/jsm/controls/OrbitControls.js | 9 +--------
4 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/docs/examples/en/controls/OrbitControls.html b/docs/examples/en/controls/OrbitControls.html
index 98a8c7cfa1d5bb..9d2e3536a39b13 100644
--- a/docs/examples/en/controls/OrbitControls.html
+++ b/docs/examples/en/controls/OrbitControls.html
@@ -282,9 +282,9 @@ [method:radians getPolarAngle] ()
Get the current vertical rotation, in radians.
- [method:radians getDistance] ()
+ [method:Float getDistance] ()
- Get the current dolly distance ( [page:PerspectiveCamera] only ).
+ Returns the distance from the camera to the target.
[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )
diff --git a/docs/examples/ko/controls/OrbitControls.html b/docs/examples/ko/controls/OrbitControls.html
index 5a3d8fb787b017..bc2a8f601eb981 100644
--- a/docs/examples/ko/controls/OrbitControls.html
+++ b/docs/examples/ko/controls/OrbitControls.html
@@ -278,9 +278,9 @@ [method:radians getPolarAngle] ()
라디안 단위로 현재 수직 회전값을 가져옵니다.
- [method:radians getDistance] ()
+ [method:Float getDistance] ()
- Get the current dolly distance ( [page:PerspectiveCamera] only ).
+ Returns the distance from the camera to the target.
[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )
diff --git a/docs/examples/zh/controls/OrbitControls.html b/docs/examples/zh/controls/OrbitControls.html
index 107520bd209b9a..ec1bc51c2eda90 100644
--- a/docs/examples/zh/controls/OrbitControls.html
+++ b/docs/examples/zh/controls/OrbitControls.html
@@ -280,9 +280,9 @@ [method:radians getPolarAngle] ()
获得当前的垂直旋转,单位为弧度。
- [method:radians getDistance] ()
+ [method:Float getDistance] ()
- Get the current dolly distance ( [page:PerspectiveCamera] only ).
+ Returns the distance from the camera to the target.
[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )
diff --git a/examples/jsm/controls/OrbitControls.js b/examples/jsm/controls/OrbitControls.js
index 17810b89d486a9..1a2f74663fa352 100644
--- a/examples/jsm/controls/OrbitControls.js
+++ b/examples/jsm/controls/OrbitControls.js
@@ -116,14 +116,7 @@ class OrbitControls extends EventDispatcher {
this.getDistance = function () {
- // compute the distance manually if the camera is orthographic
- if ( this.object.isOrthographicCamera ) {
-
- return this.object.position.distanceTo( this.target );
-
- }
-
- return spherical.radius;
+ return this.object.position.distanceTo( this.target );
};