-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
feat: add ortho control for camera #278
Conversation
… feat/camera-control
@@ -0,0 +1,136 @@ | |||
import { Camera, Entity, Script, Vector2, Vector3 } from "oasis-engine"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need comment for class
return Math.pow(0.95, this.zoomSpeed); | ||
} | ||
|
||
private _handlePan(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should update camera transform in onUpdate
function to avoid unnecessary calculation. use a flag to mark whether to update transform.
} | ||
|
||
onUpdate(dt: number): void { | ||
if (!this.enabled) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for enabled
is false
*/ | ||
export class OrthoControl extends Script { | ||
camera: Entity; | ||
cameraComp: Camera; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless for the class
Codecov Report
@@ Coverage Diff @@
## dev/0.4 #278 +/- ##
===========================================
+ Coverage 40.47% 40.68% +0.21%
===========================================
Files 328 329 +1
Lines 18283 18288 +5
Branches 2413 2405 -8
===========================================
+ Hits 7400 7441 +41
+ Misses 10882 10847 -35
+ Partials 1 0 -1
Continue to review full report at Codecov.
|
private _zoomScaleUnit: number = 25.0; | ||
private _zoomMinSize: number = 0.0; | ||
private _zoomMaxSize: number = Infinity; | ||
private _isPanStart: boolean = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_isPanMove
const { _panStart: panStart, _panEnd: panEnd } = this; | ||
Vector2.subtract(panEnd, panStart, this._panDelta); | ||
this._handlePan(); | ||
panEnd.cloneTo(panStart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isPanMove = false
* @param y - The y-axis coordinate (unit: pixel) | ||
*/ | ||
panMove(x: number, y: number): void { | ||
if (this.enabled === false || this._isPanStart === false) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isPanMove = true
* @param y - The y-axis coordinate (unit: pixel) | ||
*/ | ||
panMove(x: number, y: number): void { | ||
if (this.enabled === false || this._isPanStart === false) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!this.enabled
private _handlePan(): void { | ||
const { width, height } = this.engine.canvas; | ||
const { x, y } = this._panDelta; | ||
const { camera: cameraComp } = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use camera
*/ | ||
panMove(x: number, y: number): void { | ||
if (this.enabled === false || this._isPanStart === false) return; | ||
this._panEnd.setValue(x, y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger.warn()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Please check if the PR fulfills these requirements