Skip to content

Commit

Permalink
Merge pull request #201 from yannbriancon/feature/rotate-to-on-one-an…
Browse files Browse the repository at this point in the history
…gle-only

Feature: rotateTo on one angle only
  • Loading branch information
yomotsu authored Jul 19, 2021
2 parents 1db91c5 + 2da484d commit d9642d3
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
8 changes: 6 additions & 2 deletions dist/CameraControls.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as _THREE from 'three';
import { ACTION, PointerInput, MouseButtons, Touches, FitToOptions, CameraControlsEventMap } from './types';
import { THREESubset, ACTION, PointerInput, MouseButtons, Touches, FitToOptions, CameraControlsEventMap } from './types';
import { EventDispatcher } from './EventDispatcher';
export declare class CameraControls extends EventDispatcher {
static install(libs: any): void;
static install(libs: {
THREE: THREESubset;
}): void;
static readonly ACTION: Readonly<typeof ACTION>;
minPolarAngle: number;
maxPolarAngle: number;
Expand Down Expand Up @@ -71,6 +73,8 @@ export declare class CameraControls extends EventDispatcher {
addEventListener<K extends keyof CameraControlsEventMap>(type: K, listener: (event: CameraControlsEventMap[K]) => any): void;
removeEventListener<K extends keyof CameraControlsEventMap>(type: K, listener: (event: CameraControlsEventMap[K]) => any): void;
rotate(azimuthAngle: number, polarAngle: number, enableTransition?: boolean): void;
rotateAzimuthTo(azimuthAngle: number, enableTransition?: boolean): void;
rotatePolarTo(polarAngle: number, enableTransition?: boolean): void;
rotateTo(azimuthAngle: number, polarAngle: number, enableTransition?: boolean): void;
dolly(distance: number, enableTransition?: boolean): void;
dollyTo(distance: number, enableTransition?: boolean): void;
Expand Down
8 changes: 8 additions & 0 deletions dist/camera-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@
if (enableTransition === void 0) { enableTransition = false; }
this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi + polarAngle, enableTransition);
};
CameraControls.prototype.rotateAzimuthTo = function (azimuthAngle, enableTransition) {
if (enableTransition === void 0) { enableTransition = false; }
this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi, enableTransition);
};
CameraControls.prototype.rotatePolarTo = function (polarAngle, enableTransition) {
if (enableTransition === void 0) { enableTransition = false; }
this.rotateTo(this._sphericalEnd.theta, this._sphericalEnd.phi + polarAngle, enableTransition);
};
CameraControls.prototype.rotateTo = function (azimuthAngle, polarAngle, enableTransition) {
if (enableTransition === void 0) { enableTransition = false; }
var theta = THREE.MathUtils.clamp(azimuthAngle, this.minAzimuthAngle, this.maxAzimuthAngle);
Expand Down
2 changes: 1 addition & 1 deletion dist/camera-controls.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/camera-controls.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,14 @@ var CameraControls = (function (_super) {
if (enableTransition === void 0) { enableTransition = false; }
this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi + polarAngle, enableTransition);
};
CameraControls.prototype.rotateAzimuthTo = function (azimuthAngle, enableTransition) {
if (enableTransition === void 0) { enableTransition = false; }
this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi, enableTransition);
};
CameraControls.prototype.rotatePolarTo = function (polarAngle, enableTransition) {
if (enableTransition === void 0) { enableTransition = false; }
this.rotateTo(this._sphericalEnd.theta, this._sphericalEnd.phi + polarAngle, enableTransition);
};
CameraControls.prototype.rotateTo = function (azimuthAngle, polarAngle, enableTransition) {
if (enableTransition === void 0) { enableTransition = false; }
var theta = THREE.MathUtils.clamp(azimuthAngle, this.minAzimuthAngle, this.maxAzimuthAngle);
Expand Down
18 changes: 18 additions & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import * as _THREE from 'three';
export interface THREESubset {
MOUSE: typeof _THREE.MOUSE;
Vector2: typeof _THREE.Vector2;
Vector3: typeof _THREE.Vector3;
Vector4: typeof _THREE.Vector4;
Quaternion: typeof _THREE.Quaternion;
Matrix4: typeof _THREE.Matrix4;
Spherical: typeof _THREE.Spherical;
Box3: typeof _THREE.Box3;
Sphere: typeof _THREE.Sphere;
Raycaster: typeof _THREE.Raycaster;
MathUtils: {
DEG2RAD: typeof _THREE.MathUtils.DEG2RAD;
clamp: typeof _THREE.MathUtils.clamp;
[key: string]: any;
};
[key: string]: any;
}
export declare enum ACTION {
NONE = 0,
ROTATE = 1,
Expand Down
22 changes: 22 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ Rotate azimuthal angle(horizontal) and polar angle(vertical).

---

#### `rotateAzimuthTo( azimuthAngle, enableTransition )`

Rotate azimuthal angle(horizontal) and keep the same polar angle(vertical) target.

| Name | Type | Description |
| ------------------ | --------- | ----------- |
| `azimuthAngle` | `number` | Azimuth rotate angle. In radian. |
| `enableTransition` | `boolean` | Whether to move smoothly or immediately |

---

#### `rotatePolarTo( polarAngle, enableTransition )`

Rotate polar angle(vertical) and keep the same azimuthal angle(horizontal) target.

| Name | Type | Description |
| ------------------ | --------- | ----------- |
| `polarAngle` | `number` | Polar rotate angle. In radian. |
| `enableTransition` | `boolean` | Whether to move smoothly or immediately |

---

#### `rotateTo( azimuthAngle, polarAngle, enableTransition )`

Rotate azimuthal angle(horizontal) and polar angle(vertical) to a given point.
Expand Down
22 changes: 22 additions & 0 deletions src/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,28 @@ export class CameraControls extends EventDispatcher {

}

// azimuthAngle in radian
rotateAzimuthTo( azimuthAngle: number, enableTransition: boolean = false ): void {

this.rotateTo(
this._sphericalEnd.theta + azimuthAngle,
this._sphericalEnd.phi,
enableTransition,
);

}

// polarAngle in radian
rotatePolarTo( polarAngle: number, enableTransition: boolean = false ): void {

this.rotateTo(
this._sphericalEnd.theta,
this._sphericalEnd.phi + polarAngle,
enableTransition,
);

}

// azimuthAngle in radian
// polarAngle in radian
rotateTo( azimuthAngle: number, polarAngle: number, enableTransition: boolean = false ): void {
Expand Down

0 comments on commit d9642d3

Please sign in to comment.