Files
cocos4/cocos/renderer/core/view.js
T
Yun Hsiao Wu 243d645760 ES6 scene-graph (#3234)
* ES6 base-node

* ES6 node

* ES6 node activator

* ES6 component scheduler

* ES6 find

* ES6 scene

* ES6 private node

* fix linter globals
2018-09-13 01:29:59 +08:00

80 lines
1.7 KiB
JavaScript

// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import { vec3, color4, mat4 } from '../../core/vmath';
import enums from '../enums';
import { frustum } from '../../3d/geom-utils';
let _m4_tmp = mat4.create();
let _genID = 0;
/**
* A representation of a single camera view
*/
export default class View {
/**
* Setup a default view
*/
constructor() {
this._id = _genID++;
// priority. the smaller one will be rendered first
this._priority = 0;
// viewport
this._rect = {
x: 0, y: 0, w: 1, h: 1
};
// TODO:
// this._scissor = {
// x: 0, y: 0, w: 1, h: 1
// };
// clear options
this._color = color4.create(0.3, 0.3, 0.3, 1);
this._depth = 1;
this._stencil = 0;
this._clearFlags = enums.CLEAR_COLOR | enums.CLEAR_DEPTH;
this._clearModel = null;
// matrix
this._matView = mat4.create();
this._matProj = mat4.create();
this._matViewProj = mat4.create();
this._matInvViewProj = mat4.create();
// stages & framebuffer
this._stages = [];
this._cullingByID = false;
this._framebuffer = null;
this._shadowLight = null; // TODO: should not refer light in view.
this._frustum = frustum.create();
}
/**
* Get the view's forward direction
* @param {vec3} out the receiving vector
* @returns {vec3} the receiving vector
*/
getForward(out) {
return vec3.set(
out,
-this._matView.m02,
-this._matView.m06,
-this._matView.m10
);
}
/**
* Get the view's observing location
* @param {vec3} out the receiving vector
* @returns {vec3} the receiving vector
*/
getPosition(out) {
mat4.invert(_m4_tmp, this._matView);
return mat4.getTranslation(out, _m4_tmp);
}
}