Added 8 among many coins functionnality

This commit is contained in:
Thomas FORGIONE 2015-07-20 14:41:59 +02:00
parent 6a4cd21081
commit 19ae7aa76c
8 changed files with 157 additions and 94 deletions

View File

@ -13,9 +13,11 @@ var Info = function(id, finishAction) {
previousNext: false, previousNext: false,
hovered: false, hovered: false,
pointerLocked: false, pointerLocked: false,
switchedLockOption: false switchedLockOption: false,
redCoins: false
}; };
this.redCoins = [];
this.results = {}; this.results = {};
this.finishAction = finishAction; this.finishAction = finishAction;
@ -37,6 +39,7 @@ Info.prototype.execute = function() {
this.loadHovered(); this.loadHovered();
this.loadSwitchedLockOption(); this.loadSwitchedLockOption();
this.loadPointerLocked(); this.loadPointerLocked();
this.loadRedCoins();
}; };
Info.prototype.tryMerge = function() { Info.prototype.tryMerge = function() {
@ -58,7 +61,7 @@ Info.prototype.tryMerge = function() {
// Merges the results of every SQL requests done by the load... methods // Merges the results of every SQL requests done by the load... methods
Info.prototype.merge = function() { Info.prototype.merge = function() {
this.finalResult = []; this.finalResult = {redCoins : [], events : []};
for (;;) { for (;;) {
// Find next element // Find next element
@ -79,7 +82,12 @@ Info.prototype.merge = function() {
} }
// Add the next element in results and shift its table // Add the next element in results and shift its table
this.finalResult.push(this.results[nextIndex].shift()); this.finalResult.events.push(this.results[nextIndex].shift());
}
// Set red coins
for (var i = 0; i < this.redCoins.length; i++) {
this.finalResult.redCoins.push(this.redCoins[i]);
} }
}; };
@ -324,6 +332,26 @@ Info.prototype.loadSwitchedLockOption = function() {
); );
}; };
Info.prototype.loadRedCoins = function() {
var self = this;
this.client.query(
"SELECT coin_id FROM coin WHERE exp_id = $1",
[self.id],
function(err, result) {
if (err !== null) {
Log.dberror(err + ' in loadRedCoins');
} else {
console.log(result.rows);
for (var i in result.rows) {
self.redCoins.push(result.rows[i].coin_id);
}
}
self.ready.redCoins = true;
self.tryMerge();
}
);
}
var UserCreator = function(finishAction) { var UserCreator = function(finishAction) {
this.finishAction = finishAction; this.finishAction = finishAction;

View File

@ -30,6 +30,7 @@ L3D:
--js l3d/src/cameras/Camera.js \ --js l3d/src/cameras/Camera.js \
--js l3d/src/cameras/FixedCamera.js \ --js l3d/src/cameras/FixedCamera.js \
--js l3d/src/cameras/PointerCamera.js \ --js l3d/src/cameras/PointerCamera.js \
--js l3d/src/scenes/createCoins.js \
--js l3d/src/scenes/initScene.js \ --js l3d/src/scenes/initScene.js \
--js_output_file ../static/js/l3d.min.js --js_output_file ../static/js/l3d.min.js

View File

@ -94,7 +94,7 @@ function objectClickerOnClick(camera1, buttonManager, recommendations, coins) {
// Send event to DB // Send event to DB
event = new L3D.DB.Event.CoinClicked(); event = new L3D.DB.Event.CoinClicked();
event.coin_id = coins.indexOf(obj); event.coin_id = obj.id;
event.send(); event.send();
} else if (obj instanceof L3D.BaseRecommendation) { } else if (obj instanceof L3D.BaseRecommendation) {

View File

@ -18,11 +18,18 @@ function main() {
container = document.getElementById('container'); container = document.getElementById('container');
initThreeElements(); initThreeElements();
init();
var xhr = new XMLHttpRequest();
xhr.open("GET", "/prototype/replay_info/" + params.get.id, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
init(JSON.parse(xhr.responseText));
onWindowResize(); onWindowResize();
setInterval(render, 20); setInterval(render, 20);
}
};
xhr.send();
} }
@ -34,7 +41,7 @@ function initThreeElements() {
} }
function init() { function init(data) {
// Initialize stats counter // Initialize stats counter
stats = new Stats(); stats = new Stats();
@ -48,10 +55,12 @@ function init() {
container.appendChild(renderer.domElement); container.appendChild(renderer.domElement);
// Initialize replay camera // Initialize replay camera
camera1 = new L3D.ReplayCamera(50, container_size.width() / container_size.height(), 0.01, 100000, coins); camera1 = new L3D.ReplayCamera(50, container_size.width()/container_size.height(), 0.01, 100000, coins, data);
recommendations = initMainScene(camera1, scene, coins); recommendations = initMainScene(camera1, scene, coins, undefined, data.redCoins);
camera1.cameras = recommendations; camera1.cameras = recommendations;
camera1.start();
// Add listeners // Add listeners
initListeners(); initListeners();

View File

@ -12,20 +12,10 @@ L3D.ReplayCamera = function() {
this.new_position = new THREE.Vector3(); this.new_position = new THREE.Vector3();
this.new_target = new THREE.Vector3(); this.new_target = new THREE.Vector3();
var id = params.get.id; this.data = arguments[5];
var xhr = new XMLHttpRequest(); this.started = true;
xhr.open("GET", "/prototype/replay_info/" + id, true); this.path = this.data.events;
var self = this;
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
self.path = JSON.parse(xhr.responseText);
self.started = true;
self.nextEvent();
}
};
xhr.send();
// Set Position // Set Position
this.theta = Math.PI; this.theta = Math.PI;
@ -39,6 +29,12 @@ L3D.ReplayCamera.prototype.look = function() {
this.lookAt(this.target); this.lookAt(this.target);
}; };
L3D.ReplayCamera.prototype.start = function() {
this.counter = 0;
this.started = true;
this.nextEvent();
}
// Update function // Update function
L3D.ReplayCamera.prototype.update = function(time) { L3D.ReplayCamera.prototype.update = function(time) {
if (this.started) { if (this.started) {
@ -106,7 +102,11 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
if (this.event.type == 'camera') { if (this.event.type == 'camera') {
this.move(this.event); this.move(this.event);
} else if (this.event.type == 'coin') { } else if (this.event.type == 'coin') {
this.coins[this.event.id].get(); // Get the coin with the same id of event
for (var i = 0; i < this.coins.length; i++) {
if (this.coins[i].id === this.event.id)
this.coins[i].get();
}
// Wait a little before launching nextEvent // Wait a little before launching nextEvent
(function(self) { (function(self) {
setTimeout(function() { setTimeout(function() {
@ -167,6 +167,7 @@ L3D.ReplayCamera.prototype.anglesFromVectors = function() {
L3D.ReplayCamera.prototype.move = function(recommendation) { L3D.ReplayCamera.prototype.move = function(recommendation) {
console.log(this.position.x, this.position.y, this.position.z);
var otherCamera = recommendation.camera || recommendation; var otherCamera = recommendation.camera || recommendation;
this.moving = true; this.moving = true;

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,23 @@
// http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array#answer-2450976
L3D.shuffle = function(array) {
var currentIndex = array.length, temporaryValue, randomIndex ;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
};
L3D.LogFunction = function(a,b) { L3D.LogFunction = function(a,b) {
var val = 100*a/b; var val = 100*a/b;
$('.progress-bar').css('width', val+'%').attr('aria-valuenow', val); $('.progress-bar').css('width', val+'%').attr('aria-valuenow', val);
@ -195,19 +215,42 @@ L3D.resetBobombElements = function() {
}; };
}; };
L3D.createBobombCoins = function() { L3D.generateCoins = function(totalCoins, coin_ids) {
if (coin_ids === undefined)
L3D.shuffle(totalCoins);
else {
for (var i = 0; i < coin_ids.length; i++) {
for (var j = 0; j < totalCoins.length; j++) {
if (coin_ids[i] === totalCoins[j].id) {
// Swap i and j
var tmp = totalCoins[i];
totalCoins[i] = totalCoins[j];
totalCoins[j] = tmp;
}
}
}
}
var indices = [];
var coins = []; var coins = [];
coins.push( for (var i = 0; i < 8; i++) {
new Coin(-1.6204001515660262,12.245208850063094,-24.871861611322934), coins.push(totalCoins[i].coin);
new Coin(23.509767766131876,13.6929075780209,-6.1716274892265615), totalCoins[i].coin.id = totalCoins[i].id;
new Coin(34.797219873325524,13.088500612704706,-2.1784858128827413), indices.push(totalCoins[i].id);
new Coin(-23.255456493345882,15.763954882327724,-11.08029248078497), }
new Coin(-7.238094745133173,12.95460420281499,-3.1009487490121885),
new Coin(-17.10578612221326,24.17871082944758,-11.574224169812915), console.log(coin_ids, indices)
new Coin(-12.418656949661646,17.09780294217035,32.472022253887665),
new Coin(7.132802719121488,8.802400710545713,22.258165594421055) if (coin_ids === undefined)
); L3D.DB.Private.sendData('/posts/coin-id', {indices : indices});
return coins; return coins;
}; };
@ -277,7 +320,7 @@ L3D.createBobombRecommendations = function(width, height) {
}; };
L3D.initBobomb = function(camera, scene, coins, clickable) { L3D.initBobomb = function(camera, scene, coins, clickable, coin_ids) {
L3D.addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
@ -293,7 +336,7 @@ L3D.initBobomb = function(camera, scene, coins, clickable) {
scene.add(camera); scene.add(camera);
Coin.init(); Coin.init();
var tmp = L3D.createBobombCoins(); var tmp = L3D.generateCoins(L3D.createBobombCoins(), coin_ids);
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);
@ -431,19 +474,6 @@ L3D.createWhompRecommendations = function(width, height) {
return recos; return recos;
}; };
L3D.createWhompCoins = function() {
return [
new Coin(-5.529176900669821,2.886514571524507,4.127968972716147),
new Coin(-3.336263561768484,9.341710952326468,1.0230063543998414),
new Coin(1.985057515492925,12.151756532082196,1.3355674703297925),
new Coin(8.100383890535953,4.6489182333624335,1.9132972963126775),
new Coin(0.6049016864458896,6.2498603432959584,3.6272087520336264),
new Coin(-1.4497656612870164,6.263594147452652,-4.0488101538390694),
new Coin(6.753883218882444,2.019245026490682,-7.001046531863012),
new Coin(3.4354286209455246,3.487313067990168,-4.091947594995703)
];
};
L3D.resetWhompElements = function() { L3D.resetWhompElements = function() {
return { return {
position : new THREE.Vector3(-6.725817925071645,1.4993570618328055,-10.356480813212423), position : new THREE.Vector3(-6.725817925071645,1.4993570618328055,-10.356480813212423),
@ -451,7 +481,7 @@ L3D.resetWhompElements = function() {
}; };
}; };
L3D.initWhomp = function(recommendation, scene, coins, clickable) { L3D.initWhomp = function(recommendation, scene, coins, clickable, coin_ids) {
L3D.addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
@ -467,7 +497,7 @@ L3D.initWhomp = function(recommendation, scene, coins, clickable) {
scene.add(recommendation); scene.add(recommendation);
Coin.init(0.002); Coin.init(0.002);
var tmp = L3D.createWhompCoins(); var tmp = L3D.generateCoins(L3D.createWhompCoins(), coin_ids);
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);
@ -517,19 +547,6 @@ L3D.initMountainScene = function(scene, collidableObjects, recommendation, click
collidableObjects.push(loader.obj); collidableObjects.push(loader.obj);
}; };
L3D.createMountainCoins = function() {
return [
new Coin(-18.766484229298513,-6.174512332611151,16.379061147364553),
new Coin(-22.48878786991581,-17.698282433679474,1.6030258853572397),
new Coin(-8.604868977581164,-17.3348862459467,-11.923191659094416),
new Coin(24.81563047462934,-12.174170400556296,5.612049952487652),
new Coin(-6.4854226987006305,0.34787283214634307,-17.2093293607182),
new Coin(-14.50190371481413,20.88721463986533,7.923724946536855),
new Coin(-13.980787439949077,-0.10719616576499978,22.24889144136683),
new Coin(4.491305202472262,3.6813420775366277,10.03229664467681)
];
};
L3D.createMountainRecommendations = function(width, height) { L3D.createMountainRecommendations = function(width, height) {
var recos = []; var recos = [];
@ -605,7 +622,7 @@ L3D.resetMountainElements = function() {
}; };
}; };
L3D.initMountain = function(recommendation, scene, coins, clickable) { L3D.initMountain = function(recommendation, scene, coins, clickable, coin_ids) {
L3D.addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
@ -621,7 +638,7 @@ L3D.initMountain = function(recommendation, scene, coins, clickable) {
scene.add(recommendation); scene.add(recommendation);
Coin.init(); Coin.init();
var tmp = L3D.createMountainCoins(); var tmp = L3D.generateCoins(L3D.createMountainCoins(), coin_ids);
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);

View File

@ -11,6 +11,7 @@ DROP TABLE IF EXISTS Experiment CASCADE;
DROP TABLE IF EXISTS FpsCounter CASCADE; DROP TABLE IF EXISTS FpsCounter CASCADE;
DROP TABLE IF EXISTS PointerLocked CASCADE; DROP TABLE IF EXISTS PointerLocked CASCADE;
DROP TABLE IF EXISTS SwitchedLockOption CASCADE; DROP TABLE IF EXISTS SwitchedLockOption CASCADE;
DROP TABLE IF EXISTS Coin CASCADE;
DROP TYPE IF EXISTS VECTOR3 CASCADE; DROP TYPE IF EXISTS VECTOR3 CASCADE;
DROP TYPE IF EXISTS CAMERA CASCADE; DROP TYPE IF EXISTS CAMERA CASCADE;
@ -33,89 +34,94 @@ CREATE TYPE CAMERA AS(
); );
-- Base tables -- Base tables
CREATE TABLE users( CREATE TABLE Users(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
name CHAR(50) name CHAR(50)
); );
CREATE TABLE scene( CREATE TABLE Scene(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
name CHAR(50) name CHAR(50)
); );
CREATE TABLE experiment( CREATE TABLE Experiment(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
user_id SERIAL REFERENCES users (id), user_id SERIAL REFERENCES Users (id),
scene_id SERIAL REFERENCES scene (id) scene_id SERIAL REFERENCES Scene (id)
);
CREATE TABLE Coin(
exp_id SERIAL REFERENCES Experiment (id),
coin_id INTEGER
); );
-- Init scene table -- Init scene table
INSERT INTO scene(name) VALUES ('peachcastle'); INSERT INTO Scene(name) VALUES ('peachcastle');
INSERT INTO scene(name) VALUES ('bobomb'); INSERT INTO Scene(name) VALUES ('bobomb');
INSERT INTO scene(name) VALUES ('coolcoolmountain'); INSERT INTO Scene(name) VALUES ('coolcoolmountain');
INSERT INTO scene(name) VALUES ('whomp'); INSERT INTO Scene(name) VALUES ('whomp');
-- Events -- Events
CREATE TABLE arrowclicked( CREATE TABLE ArrowClicked(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
arrow_id INTEGER arrow_id INTEGER
); );
CREATE TABLE coinclicked( CREATE TABLE CoinClicked(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
coin_id INTEGER coin_id INTEGER
); );
CREATE TABLE keyboardevent( CREATE TABLE KeyboardEvent(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
camera CAMERA camera CAMERA
); );
CREATE TABLE resetclicked( CREATE TABLE ResetClicked(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW() time TIMESTAMP DEFAULT NOW()
); );
CREATE TABLE previousnextclicked( CREATE TABLE PreviousNextClicked(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
previousnext PREVIOUSNEXT NOT NULL, previousnext PREVIOUSNEXT NOT NULL,
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
camera CAMERA camera CAMERA
); );
CREATE TABLE hovered( CREATE TABLE Hovered(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
start BOOLEAN NOT NULL, start BOOLEAN NOT NULL,
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
arrow_id INTEGER arrow_id INTEGER
); );
CREATE TABLE fpscounter( CREATE TABLE FpsCounter(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
fps REAL fps REAL
); );
CREATE TABLE pointerlocked( CREATE TABLE PointerLocked(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
locked BOOLEAN locked BOOLEAN
); );
CREATE TABLE switchedlockoption( CREATE TABLE SwitchedLockOption(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
exp_id SERIAL REFERENCES experiment (id), exp_id SERIAL REFERENCES Experiment (id),
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
locked BOOLEAN locked BOOLEAN
); );