Added sum docs

This commit is contained in:
Thomas FORGIONE 2015-07-09 14:43:35 +02:00
parent 7d449db916
commit d76a5bc99b
7 changed files with 101 additions and 154 deletions

View File

@ -165,16 +165,31 @@ L3D.Previewer.prototype.update = function(arg) {
this.drawn = arg;
};
/**
* @description Changes the camera used for the preview
* @param {THREE.Camera} camera the new camera for preview
*/
L3D.Previewer.prototype.setCamera = function(camera) {
this.camera = camera;
}
};
/**
* @description Sets the position of the preview (automatically moves the
* preview if the mouse is in the border of the canvas)
* @param {Number} x x coordinate of the mouse
* @param {Number} y y coordinate of the mouse
*/
L3D.Previewer.prototype.setPosition = function(x, y) {
this.mouse.x = x;
this.mouse.y = y;
}
};
/**
* @description Resets the size of the canvas and clears it
* @param width {Number} the new width
* @param height {Number} the new height
*/
L3D.Previewer.prototype.setSize = function(width, height) {
this.domElement.width = width;
this.domElement.height = height;
}
};

View File

@ -83,4 +83,4 @@ L3D.StartCanvas.prototype.setSize = function(width, height) {
if (this.shown)
this.render(true);
}
};

View File

@ -203,10 +203,13 @@ var ProgressiveLoader = function(path, scene, camera, callback, log) {
*/
this.modulus = 150;
/**
* Log function : called each time with the number of elements currently
* received and the number of elements in total as parameter
* @type {function}
*/
this.log = log;
r = this;
};
/**

View File

@ -61,6 +61,11 @@ L3D.BaseRecommendation = function(arg1, arg2, arg3, arg4, position, target) {
L3D.BaseRecommendation.prototype = Object.create(THREE.Object3D.prototype);
L3D.BaseRecommendation.prototype.constructor = L3D.BaseRecommendation;
/**
* Computes the intersections with its mesh
* @param raycaster {THREE.Raycaster} the raycaster considered
* @param intersects {Object[]} collisions in which we will append the stuff
*/
L3D.BaseRecommendation.prototype.raycast = function(raycaster, intersects) {
var intersectsThis = [];

View File

@ -1,148 +0,0 @@
L3D.CameraSelecter = function(renderer, scene, camera, cameras, coins, buttonManager) {
this.raycaster = new THREE.Raycaster();
this.renderer = renderer;
this.mouse = {};
this.camera = camera;
this.cameras = cameras;
this.prev = {};
this.buttonManager = buttonManager;
this.scene = scene;
this.coins = coins;
};
L3D.CameraSelecter.prototype.pointedCamera = function() {
var returnCamera;
var x = ( this.mouse.x / this.renderer.domElement.width ) * 2 - 1;
var y = - (this.mouse.y / this.renderer.domElement.height) * 2 + 1;
var camera = this.camera;
if (camera.pointerLocked) {
this.mouse.x = this.renderer.domElement.width/2 ;
this.mouse.y = this.renderer.domElement.height/2 ;
x = 0;
y = 0;
}
var vector = new THREE.Vector3(x, y, 0.5);
vector.unproject(camera);
this.raycaster.set(camera.position, vector.sub(camera.position).normalize());
var intersects = this.raycaster.intersectObjects(this.scene.children, true);
if ( intersects.length > 0 ) {
var minDistance;
var bestIndex;
// Looking for cameras
for (var i in intersects) {
if (intersects[i].object.raycastable) {
if ( minDistance === undefined || intersects[i].distance < minDistance ) {
if (intersects[i].object instanceof THREE.Mesh) {
minDistance = intersects[i].distance;
bestIndex = i;
}
}
}
}
if (bestIndex !== undefined) {
// if (this.cameras.getById(intersects[bestIndex].object.parent.id) !== undefined) {
var obj = intersects[bestIndex].object;
for (var coin in this.coins) {
if (obj === this.coins[coin].mesh) {
return this.coins[coin];
}
}
if (intersects[bestIndex].object.parent.parent instanceof L3D.BaseRecommendation) {
this.currentPointedCamera = intersects[bestIndex].object.parent.parent;
return this.currentPointedCamera;
}
// }
}
}
this.currentPointedCamera = null;
};
L3D.CameraSelecter.prototype.update = function(event, y) {
var e;
if (event !== undefined) {
this.mouse.x = event.offsetX === undefined ? event.layerX : event.offsetX;
this.mouse.y = event.offsetY === undefined ? event.layerY : event.offsetY;
}
if (y !== undefined) {
this.mouse.x = this.renderer.domElement.width/2;
this.mouse.y = this.renderer.domElement.height/2;
}
var previousCamera = this.currentPointedCamera;
var hovered = this.pointedCamera();
if (hovered !== undefined && !(hovered instanceof Coin)) {
if (hovered !== previousCamera) {
// log it
e = new L3D.BD.Event.Hovered();
e.start = true;
e.arrow_id = this.cameras.indexOf(this.currentPointedCamera);
e.send();
this.prev.x = this.mouse.x;
this.prev.y = this.mouse.y;
}
this.prev.camera = hovered;
this.prev.go = true;
} else {
if (this.prev.go) {
// Log if previous was not null
e = new L3D.BD.Event.Hovered();
e.start = false;
e.arrow_id = null;
e.send();
}
this.prev.go = false;
}
document.getElementById('container').style.cursor = hovered ? "pointer" : "auto";
if (this.camera.pointerLocked)
this.camera.mousePointer.render(hovered ? L3D.MousePointer.RED : L3D.MousePointer.BLACK);
};
L3D.CameraSelecter.prototype.click = function(event) {
var e;
var newCamera = this.pointedCamera();
if (newCamera !== undefined && !(newCamera instanceof Coin)) {
e = new L3D.BD.Event.ArrowClicked();
e.arrow_id = this.cameras.indexOf(newCamera);
e.send();
newCamera.check();
this.camera.moveHermite(newCamera);
buttonManager.updateElements();
} else if (newCamera instanceof Coin) {
// Coin found, notify server
e = new L3D.BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera);
e.send();
newCamera.get();
}
};

View File

@ -64,6 +64,7 @@ List.prototype.push = function(element) {
/**
* Sorts the list by creating an array, sorting it, and recopying it to the list
* @param comparator {function} comparator between objects
* Complexity O(size() * log (size()))
*/
List.prototype.sort = function(comparator) {

View File

@ -4,23 +4,84 @@ function pointerCheck(camera) {
return (camera instanceof L3D.PointerCamera && camera.pointerLocked);
}
/**
* Class to allow easy object clicking
* @constructor
* @memberof L3D
* @param renderer {THREE.Renderer} the renderer
* @param camera {THREE.Camera} the camera to use
* @param objects {Object[]} the objects on which the collision is possible
* @param onHover {function} callback called when the mouse hovers an object
* @param onClick {function} callback called when the user clicks an object
* @param [domElement=document] {Element} element to which ObjectClicker listens to
*/
var ObjectClicker = function(renderer, camera, objects, onHover, onClick, domElement) {
/**
* Renderer used
* @type {THREE.Renderer}
*/
this.renderer = renderer;
/**
* Objects on which the collision is possible
* @type {Object[]}
*/
this.objects = objects;
/**
* Function called when the mouse hovers an object
* @type {function}
*/
this.onHover = onHover;
/**
* Function called when the user clicks on an object
* @type {function}
*/
this.onClick = onClick;
/**
* Camera used for ray casting
* @type {THREE.Camera}
*/
this.camera = camera;
/**
* Position of the mouse
* @type {Object}
*/
this.mouse = {x: null, y: null};
/**
* Element on which we will listen
* @type {Element}
*/
this.domElement = domElement || document;
/**
* Element currently hovered
* @type {Object}
*/
this.hoveredElement = null;
/**
* Raycaster used for finding the objects
* @private
* @type {THREE.Raycaster}
*/
this.raycaster = new THREE.Raycaster();
/**
* Currently pointed object
* @type {Object}
*/
this.currentPointedObject = null;
/**
* Previously pointed object
* @type {Object}
*/
this.previousPointedObject = null;
// Add event listeners
@ -30,6 +91,9 @@ var ObjectClicker = function(renderer, camera, objects, onHover, onClick, domEle
};
/**
* Returns the object pointed by the mouse
*/
ObjectClicker.prototype.getPointedObject = function() {
// Compute x and y for unprojection
@ -60,6 +124,10 @@ ObjectClicker.prototype.getPointedObject = function() {
};
/**
* Updates the position of the mouse and the hovered object and calls onHover
* @param event {Event} the event received by 'mousemove'
*/
ObjectClicker.prototype.update = function(event) {
// Set mouse position
@ -87,6 +155,9 @@ ObjectClicker.prototype.update = function(event) {
};
/**
* Calls onClick on the current pointed element
*/
ObjectClicker.prototype.click = function() {
this.onClick(this.currentPointedObject, this.mouse.x, this.mouse.y);