r3-legacy/bak/r3-d3-engine.js

63 lines
1.4 KiB
JavaScript

/**
* Engine Superset
* @param engineType
* @param instance {CANNON | Ammo | Goblin}
* @constructor
*/
R3.D3.Engine = function Engine(
engineType,
instance
) {
this.engineType = engineType;
this.instance = instance;
};
R3.D3.Engine.prototype.toApiEngine = function() {
//TODO: create API.Engine sometime
return {
engineType : this.engineType
}
};
/**
* True if CANNON physics
* @returns {boolean}
*/
R3.D3.Engine.prototype.isCannon = function() {
return (this.engineType == R3.D3.Engine.ENGINE_TYPE_CANNON)
};
/**
* Logs a warning and throws an error if not cannon
*/
R3.D3.Engine.prototype.isNotCannonThrow = function() {
if (this.engineType != R3.D3.Engine.ENGINE_TYPE_CANNON) {
console.warn('Only CANNON supported for this function');
throw new Error('Only CANNON supported for this function');
}
};
/**
* True if Ammo physics
* @returns {boolean}
*/
R3.D3.Engine.prototype.isAmmo = function() {
return (this.engineType == R3.D3.Engine.ENGINE_TYPE_AMMO)
};
/**
* True if Goblin physics
* @returns {boolean}
*/
R3.D3.Engine.prototype.isGoblin = function() {
return (this.engineType == R3.D3.Engine.ENGINE_TYPE_GOBLIN)
};
/**
* Physics R3.D3.Engine Types
* @type {number}
*/
R3.D3.Engine.ENGINE_TYPE_CANNON = 0x1;
R3.D3.Engine.ENGINE_TYPE_AMMO = 0x2;
R3.D3.Engine.ENGINE_TYPE_GOBLIN = 0x3;