Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HoverCameraController):Using HoverCameraController together with UIButton may result in a conflict #392

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/components/controller/HoverCameraController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ComponentBase } from "../ComponentBase";

/**
* Hovering camera controller
* @group CameraController
* @group CameraController
*/
export class HoverCameraController extends ComponentBase {
/**
Expand Down Expand Up @@ -54,7 +54,7 @@ export class HoverCameraController extends ComponentBase {
/**
* Right mouse movement coefficient
*/
public mouseRightFactor: number = 0.5;
public mouseRightFactor: number = 0.25;

/**
* Left mouse movement coefficient
Expand Down Expand Up @@ -103,6 +103,24 @@ export class HoverCameraController extends ComponentBase {
private _mouseRightDown: boolean = false;
private _bottomClamp: number = 89.99;
private _topClamp: number = -89.99;
/**
* Max angle of pitch
*/
get bottomClamp(): number {
return this._bottomClamp;
}
set bottomClamp(value: number) {
this._bottomClamp = value > 89.99 ? 89.99 : value;
}
/**
* Min angle of pitch
*/
get topClamp(): number {
return this._topClamp;
}
set topClamp(value: number) {
this._topClamp = value < -89.99 ? -89.99 : value;
}
private _tempDir = new Vector3();
private _tempPos = new Vector3();

Expand All @@ -121,8 +139,8 @@ export class HoverCameraController extends ComponentBase {
public start(): void {
this.camera = this.object3D.getOrAddComponent(Camera3D);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_DOWN, this.onMouseDown, this);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_MOVE, this.onMouseMove, this);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_UP, this.onMouseUp, this);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_MOVE, this.onMouseMove, this, null, 10);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_UP, this.onMouseUp, this, null, 10);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_WHEEL, this.onMouseWheel, this);
}

Expand All @@ -147,7 +165,7 @@ export class HoverCameraController extends ComponentBase {
this.roll = roll;
this.pitch = pitch;
this.distance = distance;
if(this.maxDistance < distance * 1.5){
if (this.maxDistance < distance * 1.5) {
this.maxDistance = distance * 1.5;
}
if (target) {
Expand Down Expand Up @@ -213,18 +231,10 @@ export class HoverCameraController extends ComponentBase {
// return;
if (!this.enable) return;
if (this._mouseRightDown) {
let p = 0.25; //this.distance / (this.camera.far - this.camera.near);
let f = this.camera.transform.forward;
Vector3Ex.mulScale(f, e.movementY * p * this.camera.aspect, Vector3.HELP_1);
Vector3.HELP_1.x = -1 * e.movementX * Math.cos((this._roll * Math.PI) / 180) - e.movementY * Math.sin((this._roll * Math.PI) / 180);
Vector3.HELP_1.z = -1 * e.movementY * Math.cos((this._roll * Math.PI) / 180) + e.movementX * Math.sin((this._roll * Math.PI) / 180);
this._targetPos.x += Vector3.HELP_1.x * this.mouseRightFactor;
// this._targetPos.y -= Vector3.HELP_1.y;
this._targetPos.z += Vector3.HELP_1.z * this.mouseRightFactor;

let f2 = this.camera.transform.right;
Vector3Ex.mulScale(f2, -e.movementX * p, Vector3.HELP_1);
this._targetPos.x -= Vector3.HELP_1.x * this.mouseRightFactor;
// this._targetPos.y -= Vector3.HELP_1.y;
this._targetPos.z -= Vector3.HELP_1.z * this.mouseRightFactor;
}

if (this._mouseLeftDown) {
Expand All @@ -235,8 +245,7 @@ export class HoverCameraController extends ComponentBase {
}

public onBeforeUpdate(view?: View3D) {
if (!this.enable)
return;
if (!this.enable) return;

if (this._flowTarget) {
Vector3.HELP_0.copyFrom(this._flowTarget.transform.worldPosition);
Expand Down
Loading