physics intro

beta.r3js.org
-=yb4f310 2017-06-24 18:09:44 +02:00
parent 685f1298ac
commit c7cf4a42c0
4 changed files with 82 additions and 11 deletions

View File

@ -80,7 +80,7 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
loader = new THREE.ImageLoader();
loader.crossOrigin = true;
loader.crossOrigin = '';
loader.path = data.baseUrl;

View File

@ -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');
}
};

View File

@ -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]);

View File

@ -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
);