/** * Input parent class * @param graphics GameLib.D3.Graphics * @param apiInputEditor GameLib.D3.API.Input.Editor * @constructor */ GameLib.D3.Input.Editor = function ( graphics, apiInputEditor ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); GameLib.D3.API.Input.Editor.call( this, apiInputEditor.id, apiInputEditor.name, apiInputEditor.camera, apiInputEditor.parentEntity ); this.instance = this.createInstance(); }; GameLib.D3.Input.Editor.prototype = Object.create(GameLib.D3.API.Input.Editor.prototype); GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor; GameLib.D3.Input.Editor.prototype.createInstance = function(update) { if (update) { return this.instance; } var instance = document.getElementById(this.domElementId); this.resize = this.onWindowResize.bind(this); window.addEventListener('resize', this.resize, false ); // this.clearScene(); this.boundMouseMove = this.mouseMove.bind(this); instance.addEventListener('contextmenu', function(event){ if (event.stopPropagation) { event.stopPropagation(); } if (event.preventDefault) { event.preventDefault(); } event.cancelBubble = true; return false; }, false); instance.addEventListener('mousedown', this.mouseDown.bind(this), false); instance.addEventListener('keydown', this.keypress.bind(this), false); instance.addEventListener('mousemove', this.boundMouseMove, false); return instance; }; GameLib.D3.Input.Editor.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; /** * GameLib.D3.Input.Editor to GameLib.D3.API.Input.Editor * @returns {GameLib.D3.API.Input.Editor} */ GameLib.D3.Input.Editor.prototype.toApiComponent = function() { var apiInputEditor = new GameLib.D3.API.Input.Editor( this.id, this.name, this.domElementId, GameLib.Utils.IdOrNull(this.pathFollowingComponent), GameLib.Utils.IdOrNull(this.parentEntity), GameLib.Utils.IdOrNull(this.wheelFL), GameLib.Utils.IdOrNull(this.wheelFR), GameLib.Utils.IdOrNull(this.wheelRL), GameLib.Utils.IdOrNull(this.wheelRR), this.heightOffset, this.distance, this.distanceGrain, this.rotationFactor ); return apiInputEditor; }; GameLib.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent) { var apiInputEditor = GameLib.D3.API.Input.Editor.FromObjectComponent(objectComponent); return new GameLib.D3.Input.Editor( graphics, apiInputEditor ); }; GameLib.D3.Input.Editor.prototype.update = function(deltaTime) { if (this.pathFollowingComponent) { this.pathFollowingComponent.mesh.localPosition.x = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.x); this.pathFollowingComponent.mesh.localPosition.y = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.y); this.pathFollowingComponent.mesh.localPosition.z = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.z); if (this.keyLeft) { this.distance -= this.distanceGrain; } if (this.keyRight) { this.distance += this.distanceGrain; } this.pathFollowingComponent.mesh.localPosition.x += (this.distance * this.pathFollowingComponent.rotationMatrix.left.x); this.pathFollowingComponent.mesh.localPosition.y += (this.distance * this.pathFollowingComponent.rotationMatrix.left.y); this.pathFollowingComponent.mesh.localPosition.z += (this.distance * this.pathFollowingComponent.rotationMatrix.left.z); this.wheelFL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed; this.wheelFR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed; this.wheelFL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed; this.wheelFR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed; this.wheelRL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed; this.wheelRR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed; } };