Added option to fix prev thing

This commit is contained in:
Thomas FORGIONE 2015-05-18 09:28:51 +02:00
parent e67896341f
commit c2f971f9e9
4 changed files with 26 additions and 10 deletions

View File

@ -114,6 +114,9 @@ block content
input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked) input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked)
label(for="showarrows" style={'margin-right':'10px'}) Show arrows label(for="showarrows" style={'margin-right':'10px'}) Show arrows
input#recommendation(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'})
label(for="recommendation" style={'margin-right':'10px'}) Fixed prev
audio#music(controls, volume=0.5) audio#music(controls, volume=0.5)
source(src="/static/data/music/bobomb.ogg") source(src="/static/data/music/bobomb.ogg")
source(src="/static/data/music/bobomb.mp3") source(src="/static/data/music/bobomb.mp3")

View File

@ -1,5 +1,6 @@
var ButtonManager = function(cameras) { var ButtonManager = function(cameras, previewer) {
this.cameras = cameras; this.cameras = cameras;
this.previewer = previewer;
this.showArrows = true; this.showArrows = true;
this.beenFullscreen = false; this.beenFullscreen = false;
@ -13,6 +14,8 @@ var ButtonManager = function(cameras) {
this.collisionElement = document.getElementById('collisions'); this.collisionElement = document.getElementById('collisions');
this.showarrowsElement = document.getElementById('showarrows'); this.showarrowsElement = document.getElementById('showarrows');
this.recommendationElement = document.getElementById('recommendation');
this.fullscreenElement.onclick = function() {fullscreen();}; this.fullscreenElement.onclick = function() {fullscreen();};
(function(self) { (function(self) {
@ -31,6 +34,10 @@ var ButtonManager = function(cameras) {
self.collisionElement.onchange = function() {self.cameras.mainCamera().collisions = self.collisionElement.checked;} self.collisionElement.onchange = function() {self.cameras.mainCamera().collisions = self.collisionElement.checked;}
self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;} self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;}
self.resetElement.onclick = function() {self.cameras.mainCamera().reset();} self.resetElement.onclick = function() {self.cameras.mainCamera().reset();}
self.recommendationElement.onchange = function() {
previewer.fixedRecommendation(self.recommendationElement.checked);
}
})(this); })(this);
} }

View File

@ -2,20 +2,22 @@ var Previewer = function(renderer) {
this.domElement = document.createElement('canvas'); this.domElement = document.createElement('canvas');
this.ctx = this.domElement.getContext('2d'); this.ctx = this.domElement.getContext('2d');
this.renderer = renderer; this.renderer = renderer;
this.fixed = false;
} }
Previewer.prototype.render = function(prev, container_width, container_height) { Previewer.prototype.render = function(prev, container_width, container_height) {
var width = container_width / 5; var width, height, left, bottom;
var height = container_height / 5;
var left = prev.x - width/2;
var bottom = renderer.domElement.height - prev.y + height/5;
if (prev.go) { if (prev.go) {
width = Math.floor(container_width / 5); width = Math.floor(container_width / 5);
height = Math.floor(container_height / 5); height = Math.floor(container_height / 5);
left = Math.floor(prev.x - width/2); if (!this.fixed) {
bottom = Math.floor(renderer.domElement.height - prev.y + height/5); left = Math.floor(prev.x - width/2);
bottom = Math.floor(this.renderer.domElement.height - prev.y + height/5);
} else {
left = 0;
bottom = 0;
}
// Draw border // Draw border
var can_bottom = container_height - bottom - height ; var can_bottom = container_height - bottom - height ;
@ -40,7 +42,7 @@ Previewer.prototype.render = function(prev, container_width, container_height) {
// Do render in previsualization // Do render in previsualization
prev.camera.look(); prev.camera.look();
this.renderer.setScissor(left, bottom, width, height); this.renderer.setScissor(left, bottom, width, height);
this.renderer.enableScissorTest (true); this.renderer.enableScissorTest(true);
this.renderer.setViewport(left, bottom, width, height); this.renderer.setViewport(left, bottom, width, height);
this.renderer.render(scene, prev.camera); this.renderer.render(scene, prev.camera);
@ -54,3 +56,7 @@ Previewer.prototype.clear = function() {
this.clearNeeded = false; this.clearNeeded = false;
} }
} }
Previewer.prototype.fixedRecommendation = function(bool) {
this.fixed = bool;
}

View File

@ -137,7 +137,7 @@ function initListeners() {
document.addEventListener('keydown', function(event) { if (event.keyCode == 27) { stopFullscreen();} }, false); document.addEventListener('keydown', function(event) { if (event.keyCode == 27) { stopFullscreen();} }, false);
// HTML Bootstrap buttons // HTML Bootstrap buttons
buttonManager = new ButtonManager(cameras); buttonManager = new ButtonManager(cameras, previewer);
// Camera selecter for hover and clicking recommendations // Camera selecter for hover and clicking recommendations
cameraSelecter = new CameraSelecter(renderer, cameras, buttonManager); cameraSelecter = new CameraSelecter(renderer, cameras, buttonManager);