Added undo button (only one level)

This commit is contained in:
Thomas FORGIONE 2015-04-29 15:51:25 +02:00
parent 5df1d17746
commit cda69b86c6
3 changed files with 18 additions and 1 deletions

View File

@ -26,6 +26,7 @@ button.
<button class="btn btn-primary" id="full" style="margin-bottom: 10px; display: none;">Fullscreen</button> <button class="btn btn-primary" id="full" style="margin-bottom: 10px; display: none;">Fullscreen</button>
<button class="btn btn-primary" id="reset" style="margin-bottom:10px">Reset camera</button> <button class="btn btn-primary" id="reset" style="margin-bottom:10px">Reset camera</button>
<button class="btn btn-primary" id="undo" style="margin-bottom:10px">Undo</button>
<input type="checkbox" id="fullarrow" style="margin-bottom:10px"> <input type="checkbox" id="fullarrow" style="margin-bottom:10px">
<label for="fullarrow">Full arrow</label> <label for="fullarrow">Full arrow</label>
<input type="checkbox" id="collisions" style="margin-bottom:10px" checked> <input type="checkbox" id="collisions" style="margin-bottom:10px" checked>

View File

@ -247,6 +247,16 @@ PointerCamera.prototype.log = function() {
console.log("(" + this.target.x + "," + this.target.y + ',' + this.target.z + ')'); console.log("(" + this.target.x + "," + this.target.y + ',' + this.target.z + ')');
} }
PointerCamera.prototype.save = function() {
this.backup = {};
this.backup.position = this.position.clone();
this.backup.target = this.target.clone();
}
PointerCamera.prototype.load = function() {
this.move(this.backup);
}
// Static members // Static members
PointerCamera.DISTANCE_X = 1000; PointerCamera.DISTANCE_X = 1000;
PointerCamera.DISTANCE_Z = 300; PointerCamera.DISTANCE_Z = 300;

View File

@ -65,6 +65,10 @@ function init() {
showArrows = showarrows.checked; showArrows = showarrows.checked;
} }
document.getElementById('undo').onclick = function() {
cameras.mainCamera().load();
}
// on initialise le moteur de rendu // on initialise le moteur de rendu
container = document.getElementById('container'); container = document.getElementById('container');
container.style.height = container_size.height() + 'px'; container.style.height = container_size.height() + 'px';
@ -474,9 +478,11 @@ function updateMouse(event) {
function click(event) { function click(event) {
var newCamera = pointedCamera(event); var newCamera = pointedCamera(event);
if (newCamera !== undefined) if (newCamera !== undefined) {
cameras.mainCamera().save();
cameras.mainCamera().move(newCamera); cameras.mainCamera().move(newCamera);
} }
}
function pointedCamera(event) { function pointedCamera(event) {
var returnCamera; var returnCamera;