physics intro
parent
685f1298ac
commit
c7cf4a42c0
|
@ -80,7 +80,7 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
|
|||
|
||||
loader = new THREE.ImageLoader();
|
||||
|
||||
loader.crossOrigin = true;
|
||||
loader.crossOrigin = '';
|
||||
|
||||
loader.path = data.baseUrl;
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Physics
|
||||
* @param id
|
||||
* @param name
|
||||
* @param physicsType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics = function Physics(
|
||||
id,
|
||||
name,
|
||||
physicsType
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Physics (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(physicsType)) {
|
||||
physicsType = GameLib.D3.Physics.PHYSICS_TYPE_CANNON;
|
||||
}
|
||||
this.physicsType = physicsType;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.Physics Types
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.Physics.PHYSICS_TYPE_CANNON = 0x1;
|
||||
|
||||
/**
|
||||
* @returns {THREE.Physics}
|
||||
*/
|
||||
GameLib.D3.Physics.prototype.createInstance = function(update) {
|
||||
var instance = CANNON;
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Physics.prototype.updateInstance = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs a warning and throws an error if not cannon
|
||||
*/
|
||||
GameLib.D3.Physics.prototype.isNotCannonThrow = function() {
|
||||
if (this.physicsType !== GameLib.D3.Physics.PHYSICS_TYPE_CANNON) {
|
||||
console.warn('Only CANNON supported for this function');
|
||||
throw new Error('Only CANNON supported for this function');
|
||||
}
|
||||
};
|
|
@ -1,16 +1,30 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @param graphics
|
||||
* @param implementation
|
||||
* @param apiSystem GameLib.API.System
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System = function(
|
||||
graphics,
|
||||
implementation,
|
||||
apiSystem
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.implementation = implementation;
|
||||
|
||||
if (implementation instanceof GameLib.D3.Graphics) {
|
||||
this.physics = null;
|
||||
this.graphics = implementation;
|
||||
this.graphics.isNotThreeThrow();
|
||||
} else if (implementation instanceof GameLib.D3.Physics) {
|
||||
this.graphics = null;
|
||||
this.physics = implementation;
|
||||
this.physics.isNotCannonThrow();
|
||||
} else {
|
||||
throw new Error('Unhandled implementation : ' + implementation);
|
||||
}
|
||||
|
||||
this.implementation = implementation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiSystem)) {
|
||||
apiSystem = {};
|
||||
|
@ -44,6 +58,7 @@ GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2;
|
|||
GameLib.System.SYSTEM_TYPE_INPUT = 0x4;
|
||||
GameLib.System.SYSTEM_TYPE_STORAGE = 0x8;
|
||||
GameLib.System.SYSTEM_TYPE_GUI = 0x10;
|
||||
GameLib.System.SYSTEM_TYPE_PHYSICS = 0x20;
|
||||
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
|
||||
|
||||
GameLib.System.prototype.createInstance = function() {
|
||||
|
@ -57,9 +72,6 @@ GameLib.System.prototype.createInstance = function() {
|
|||
GameLib.System.prototype.start = function() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||
// this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
|
||||
// this.followObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Follow]);
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @param graphics
|
||||
* @param physics
|
||||
* @param apiSystem GameLib.API.System
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System.Physics = function(
|
||||
graphics,
|
||||
physics,
|
||||
apiSystem
|
||||
) {
|
||||
|
||||
GameLib.System.call(
|
||||
this,
|
||||
graphics,
|
||||
physics,
|
||||
apiSystem
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue