ソースを参照

OrbitControls: add getDistance() (#22126)

* OrbitControls: add getDistance()

* OrbitControls: compute getDistance manually for orthographic camera

* Simplify getDistance()
Marco Fugaro 4 年 前
コミット
ae4a7c4af5

+ 5 - 0
docs/examples/en/controls/OrbitControls.html

@@ -282,6 +282,11 @@ controls.touches = {
 			Get the current vertical rotation, in radians.
 		</p>
 
+		<h3>[method:Float getDistance] ()</h3>
+		<p>
+			Returns the distance from the camera to the target.
+		</p>
+
 		<h3>[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )</h3>
 		<p>
 			Adds key event listeners to the given DOM element. *window* is a recommended argument for using this method.

+ 5 - 0
docs/examples/ko/controls/OrbitControls.html

@@ -278,6 +278,11 @@ controls.touches = {
 			라디안 단위로 현재 수직 회전값을 가져옵니다.
 		</p>
 
+		<h3>[method:Float getDistance] ()</h3>
+		<p>
+			Returns the distance from the camera to the target.
+		</p>
+
 		<h3>[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )</h3>
 		<p>
 			Adds key event listeners to the given DOM element. *window* is a recommended argument for using this method.

+ 5 - 0
docs/examples/zh/controls/OrbitControls.html

@@ -280,6 +280,11 @@ controls.touches = {
 			获得当前的垂直旋转,单位为弧度。
 		</p>
 
+		<h3>[method:Float getDistance] ()</h3>
+		<p>
+			Returns the distance from the camera to the target.
+		</p>
+
 		<h3>[method:void listenToKeyEvents] ( [param:HTMLDOMElement domElement] )</h3>
 		<p>
 			为指定的DOM元素添加按键监听。推荐将window作为指定的DOM元素。

+ 6 - 0
examples/jsm/controls/OrbitControls.js

@@ -114,6 +114,12 @@ class OrbitControls extends EventDispatcher {
 
 		};
 
+		this.getDistance = function () {
+
+			return this.object.position.distanceTo( this.target );
+
+		};
+
 		this.listenToKeyEvents = function ( domElement ) {
 
 			domElement.addEventListener( 'keydown', onKeyDown );