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

feat: add ortho control for camera #278

Merged
merged 19 commits into from
Jun 8, 2021

Conversation

singlecoder
Copy link
Member

@singlecoder singlecoder commented May 13, 2021

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

@@ -0,0 +1,136 @@
import { Camera, Entity, Script, Vector2, Vector3 } from "oasis-engine";

Copy link
Collaborator

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 {
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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-commenter
Copy link

codecov-commenter commented Jun 8, 2021

Codecov Report

Merging #278 (6f11a70) into dev/0.4 (ebaa542) will increase coverage by 0.21%.
The diff coverage is 90.74%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
packages/controls/src/index.ts 0.00% <0.00%> (ø)
packages/controls/src/OrthoControl.ts 94.28% <92.45%> (ø)
packages/loader/src/gltf/parser/MaterialParser.ts 0.00% <0.00%> (-16.00%) ⬇️
packages/loader/src/gltf/parser/SceneParser.ts 0.00% <0.00%> (-12.95%) ⬇️
...ader/src/scene-loader/resources/TextureResource.ts 0.00% <0.00%> (-6.90%) ⬇️
packages/draco/src/decoder.ts 0.00% <0.00%> (ø)
packages/loader/src/scene-loader/Oasis.ts 0.00% <0.00%> (ø)
...ackages/loader/src/scene-loader/ResourceManager.ts 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ebaa542...6f11a70. Read the comment docs.

private _zoomScaleUnit: number = 25.0;
private _zoomMinSize: number = 0.0;
private _zoomMaxSize: number = Infinity;
private _isPanStart: boolean = false;
Copy link
Collaborator

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);
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger.warn()

Copy link
Collaborator

@gz65555 gz65555 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@gz65555 gz65555 merged commit c4c72e4 into galacean:dev/0.4 Jun 8, 2021
luzhuang pushed a commit to luzhuang/engine that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants