r3-legacy/src/game-lib-d3-viewport.js

89 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-01-11 16:09:06 +01:00
/**
* Viewport Runtime
* @param graphics GameLib.GraphicsRuntime
2017-01-11 16:09:06 +01:00
* @param apiViewport GameLib.D3.API.Viewport
* @constructor
*/
GameLib.D3.Viewport = function (
graphics,
2017-02-21 18:55:18 +01:00
apiViewport
2017-01-11 16:09:06 +01:00
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiViewport)) {
apiViewport = {};
}
GameLib.D3.API.Viewport.call(
2017-01-11 16:09:06 +01:00
this,
apiViewport.id,
apiViewport.name,
apiViewport.width,
apiViewport.height,
apiViewport.x,
apiViewport.y,
apiViewport.parentEntity
);
2017-12-04 13:23:15 +01:00
GameLib.Component.call(this);
2017-01-11 16:09:06 +01:00
};
2018-01-07 12:40:16 +01:00
GameLib.D3.Viewport.prototype = Object.create(GameLib.Component.prototype);
2017-01-11 16:09:06 +01:00
GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
/**
*
2017-08-24 22:20:40 +02:00
* @returns {boolean}
2017-01-11 16:09:06 +01:00
*/
2017-06-28 17:09:06 +02:00
GameLib.D3.Viewport.prototype.createInstance = function() {
2018-02-08 13:57:15 +01:00
this.instance = new THREE.Vector4(
this.x,
this.y,
this.width,
this.height
);
2017-10-23 14:52:35 +02:00
GameLib.Component.prototype.createInstance.call(this);
2017-01-11 16:09:06 +01:00
};
/**
*
*/
2018-02-08 13:57:15 +01:00
GameLib.D3.Viewport.prototype.updateInstance = function(property) {
if (
property === 'x' ||
property === 'y' ||
property === 'width' ||
property === 'height'
) {
this.instance.x = this.x;
this.instance.y = this.y;
this.instance.z = this.width;
this.instance.w = this.height;
}
2017-01-11 16:09:06 +01:00
};
/**
* GameLib.D3.Viewport to GameLib.D3.API.Viewport
* @returns {GameLib.D3.API.Viewport}
*/
2017-05-16 14:51:57 +02:00
GameLib.D3.Viewport.prototype.toApiObject = function() {
2017-01-11 16:09:06 +01:00
var apiViewport = new GameLib.D3.API.Viewport(
this.id,
this.name,
this.width,
this.height,
this.x,
this.y,
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiViewport;
};