|
|
|
@ -2,6 +2,11 @@ import * as THREE from 'three';
|
|
|
|
|
import { Vector3 } from 'three';
|
|
|
|
|
import { Orbit } from '../Geometry/Orbit';
|
|
|
|
|
|
|
|
|
|
const ViewScopeSize = 4e4;
|
|
|
|
|
//相机活动范围
|
|
|
|
|
const ViewScopeMin = new Vector3(-ViewScopeSize, -ViewScopeSize * 0.7, -ViewScopeSize);
|
|
|
|
|
const ViewScopeMax = ViewScopeMin.clone().negate();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 相机的控制.
|
|
|
|
@ -30,12 +35,16 @@ export class CameraControl
|
|
|
|
|
//观察的轨道.
|
|
|
|
|
private m_Orbit: Orbit = new Orbit();
|
|
|
|
|
|
|
|
|
|
//最大最小视口高度
|
|
|
|
|
m_MinViewHeight = 1e-3;
|
|
|
|
|
m_MaxViewHeight = 3e4;
|
|
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
|
{
|
|
|
|
|
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2,
|
|
|
|
|
-10000, 10000));
|
|
|
|
|
-ViewScopeSize, ViewScopeSize));
|
|
|
|
|
|
|
|
|
|
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
|
|
|
|
|
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, ViewScopeSize));
|
|
|
|
|
|
|
|
|
|
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
|
|
|
|
|
|
|
|
|
@ -60,7 +69,7 @@ export class CameraControl
|
|
|
|
|
}
|
|
|
|
|
set ViewHeight(height)
|
|
|
|
|
{
|
|
|
|
|
this.m_ViewHeight = THREE.Math.clamp(height, 1e-8, 1e8);
|
|
|
|
|
this.m_ViewHeight = THREE.Math.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetSize(width: number, height: number)
|
|
|
|
@ -81,6 +90,7 @@ export class CameraControl
|
|
|
|
|
mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
|
|
|
|
|
mouseMove.applyQuaternion(this.Camera.quaternion);
|
|
|
|
|
this.m_Target.add(mouseMove);
|
|
|
|
|
this.m_Target.clamp(ViewScopeMin, ViewScopeMax);
|
|
|
|
|
this.Update();
|
|
|
|
|
}
|
|
|
|
|
Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3)
|
|
|
|
@ -114,7 +124,7 @@ export class CameraControl
|
|
|
|
|
if (this.Camera instanceof THREE.OrthographicCamera)
|
|
|
|
|
{
|
|
|
|
|
this.ViewHeight *= scale;
|
|
|
|
|
if (scaleCenter)
|
|
|
|
|
if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
|
|
|
|
|
{
|
|
|
|
|
this.m_Target.sub(scaleCenter);
|
|
|
|
|
this.m_Target.multiplyScalar(scale);
|
|
|
|
@ -131,7 +141,7 @@ export class CameraControl
|
|
|
|
|
}
|
|
|
|
|
ZoomExtensBox3(box3: THREE.Box3)
|
|
|
|
|
{
|
|
|
|
|
if (!box3) return;
|
|
|
|
|
if (!box3 || box3.isEmpty()) return;
|
|
|
|
|
this.Camera.updateMatrixWorld(false);
|
|
|
|
|
//变换到相机坐标系
|
|
|
|
|
box3.applyMatrix4(this.Camera.matrixWorldInverse);
|
|
|
|
@ -148,11 +158,11 @@ export class CameraControl
|
|
|
|
|
//
|
|
|
|
|
if (aspectRatio > viewAspectRatio)
|
|
|
|
|
{
|
|
|
|
|
this.m_ViewHeight = size.x / viewAspectRatio;
|
|
|
|
|
this.ViewHeight = size.x / viewAspectRatio;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.m_ViewHeight = size.y;
|
|
|
|
|
this.ViewHeight = size.y;
|
|
|
|
|
}
|
|
|
|
|
this.Update();
|
|
|
|
|
}
|
|
|
|
|