Skip to content

Commit

Permalink
feat(orbit): fix orbit under ortho camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeboy-cn committed Jan 18, 2025
1 parent 750bded commit 462b7f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions samples/base/Sample_CameraType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ let options = {
fov: 45,
frustumSize: 10,
'ortho': () => {
options.near = -100
options.far = 100
options.near = -1000
options.far = 1000
camera.ortho(options.frustumSize, options.near, options.far)
},
'perspective': () => {
Expand Down
11 changes: 11 additions & 0 deletions src/components/controller/OrbitController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Vector3 } from '../../math/Vector3';
import { Vector3Ex } from '../../util/Vector3Ex';
import { clamp } from '../../math/MathUtil';
import { PointerEvent3D } from '../../event/eventConst/PointerEvent3D';
import { CameraType } from '../../core/CameraType';

/**
* Orbit Camera Controller
Expand Down Expand Up @@ -190,6 +191,7 @@ export class OrbitController extends ComponentBase {
}
if (changed) {
this._spherical.setCoords(this._position.x - this._target.x, this._position.y - this._target.y, this._position.z - this._target.z)
this.updateCamera();
} else if (!this._isMouseDown && this.autoRotate) {
this._spherical.theta -= this.autoRotateSpeed * Math.PI / 180;
this.updateCamera();
Expand All @@ -211,6 +213,15 @@ export class OrbitController extends ComponentBase {
this._spherical.radius += e.deltaY * this.zoomFactor;
this._spherical.radius = clamp(this._spherical.radius, this.minDistance, this.maxDistance);
this.updateCamera();

if(this._camera.type === CameraType.ortho){
this._camera.frustumSize += e.deltaY * this.zoomFactor
if(this._camera.frustumSize < this._minDistance)
this._camera.frustumSize = this._minDistance
else if(this._camera.frustumSize > this._maxDistance)
this._camera.frustumSize = this._maxDistance
this._camera.updateProjection()
}
}
/**
* @internal
Expand Down
4 changes: 2 additions & 2 deletions src/core/Camera3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ export class Camera3D extends ComponentBase {
*/
public ortho(frustumSize: number, near: number, far: number) {
this.frustumSize = frustumSize;
let w = frustumSize * 0.5 * this.aspect;
let h = frustumSize * 0.5;
let w = frustumSize * this.aspect;
let h = frustumSize;
let left = -w / 2;
let right = w / 2;
let top = h / 2;
Expand Down

0 comments on commit 462b7f8

Please sign in to comment.