增加用户缩放相机体验,扩大相机范围,并且限定用户的缩放范围,避免缩放后物体过小而对象找不到的问题.

This commit is contained in:
ChenX 2018-05-31 10:48:43 +08:00
parent 35443367f3
commit 4f3d7a6388
4 changed files with 14 additions and 7 deletions

View File

@ -18,6 +18,8 @@ export declare class CameraUpdate {
private m_Target;
private m_Direction;
private m_Orbit;
m_MinViewHeight: number;
m_MaxViewHeight: number;
constructor();
readonly Aspect: number;
readonly Camera: THREE.Camera;

View File

@ -24,7 +24,9 @@ class CameraUpdate {
this.m_Direction = new THREE.Vector3(0, 0, -1);
//观察的轨道.
this.m_Orbit = new Orbit_1.Orbit();
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2, -100000, 100000));
this.m_MinViewHeight = 10;
this.m_MaxViewHeight = 3e4;
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2, -1e6, 1e6));
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
this.m_Orbit.UpdateRoValue(this.m_Direction);
@ -41,7 +43,7 @@ class CameraUpdate {
return this.m_ViewHeight;
}
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, height) {
this.m_Width = width;
@ -84,7 +86,7 @@ class CameraUpdate {
Zoom(scale, scaleCenter) {
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);
this.m_Target.add(scaleCenter);

File diff suppressed because one or more lines are too long

View File

@ -30,10 +30,13 @@ export class CameraUpdate
//观察的轨道.
private m_Orbit: Orbit = new Orbit();
m_MinViewHeight = 10;
m_MaxViewHeight = 3e4;
constructor()
{
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2,
-100000, 100000));
-1e6, 1e6));
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
@ -60,7 +63,7 @@ export class CameraUpdate
}
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)
@ -114,7 +117,7 @@ export class CameraUpdate
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);