相机渲染

This commit is contained in:
YHH
2020-06-18 23:22:54 +08:00
parent feaac83ee7
commit e83bb087ea
13 changed files with 124 additions and 47 deletions

View File

@@ -1,16 +1,18 @@
///<reference path="../Component.ts"/>
class Camera extends Component {
private _zoom;
private _origin: Vector2;
private _origin: Vector2 = Vector2.zero;
private _transformMatrix: Matrix2D = Matrix2D.identity;
private _inverseTransformMatrix = Matrix2D.identity;
private _projectionMatrix = Matrix2D.identity;
private _minimumZoom = 0.3;
private _maximumZoom = 3;
private _areMatrixesDirty = true;
private _inset: CameraInset;
private _bounds: Rectangle;
private _inset: CameraInset = new CameraInset();
private _bounds: Rectangle = new Rectangle();
private _areBoundsDirty = true;
private _isProjectionMatrixDirty = true;
public get bounds(){
if (this._areMatrixesDirty)
@@ -104,6 +106,14 @@ class Camera extends Component {
this.setZoom(0);
}
public onSceneSizeChanged(newWidth: number, newHeight: number){
this._isProjectionMatrixDirty = true;
let oldOrigin = this._origin;
this.origin = new Vector2(newWidth / 2, newHeight / 2);
this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin));
}
public setMinimumZoom(minZoom: number): Camera{
if (this._zoom < minZoom)
this._zoom = this.minimumZoom;