Skip to content
Snippets Groups Projects
Commit 8d6fc42a authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

lattice subclassing

parent 21a31e9b
No related branches found
No related tags found
No related merge requests found
......@@ -10,15 +10,15 @@ $(function(){
//init threeJS and geometry models
window.three = new ThreeModel();
var lattice = new Lattice();
window.lattice = new OctaFaceLattice();
//setup ui
var appState = new AppState({lattice:lattice});
new MenuWrapper({lattice:lattice, model:appState});
var appState = new AppState({lattice:window.lattice});
new MenuWrapper({lattice:window.lattice, model:appState});
new NavBar({model:appState});
//threeJS View
new ThreeView({model:window.three, lattice:lattice, appState:appState});
new ThreeView({model:window.three, lattice:window.lattice, appState:appState});
lattice.addCellAtIndex({x:0,y:0,z:0});
window.lattice.addCellAtIndex({x:0,y:0,z:0});
});
......@@ -53,27 +53,21 @@ Lattice = Backbone.Model.extend({
///////////////////////////////ADD/REMOVE CELLS/////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
addCellAtPosition: function(absPosition){
addCellAtIndex: function(indices){
//calc indices in cell matrix
var scale = this.get("scale");
var octHeight = 2*scale/Math.sqrt(6);
var triHeight = scale/2*Math.sqrt(3);
var position = {};
position.x = Math.round(absPosition.x/scale);
position.y = Math.round(absPosition.y/triHeight);
position.z = Math.round(absPosition.z/octHeight);
if (position.z%2 == 1) position.y += 1;
var cells = this.get("cells");
this._checkForMatrixExpansion(cells, indices);
this.addCellAtIndex(position);
var index = this._subtract(indices, this.get("cellsMin"));
if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = this._makeCellForLatticeType(indices, scale);
else console.warn("already a cell there");
this.set("numCells", this.get("numCells")+1);
window.three.render();
},
addCellAtIndex: function(indices){
var cells = this.get("cells");
var scale = this.get("scale");
_checkForMatrixExpansion: function(cells, indices){
//check for matrix expansion
var lastMax = this.get("cellsMax");
var lastMin = this.get("cellsMin");
var newMax = this._updateCellsMax(indices, lastMax);
......@@ -86,12 +80,6 @@ Lattice = Backbone.Model.extend({
this._expandCellsArray(cells, this._subtract(lastMin, newMin), true);
this.set("cellsMin", newMin);
}
var index = this._subtract(indices, this.get("cellsMin"));
if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = new DMASideOctaCell(this.get("cellMode"), indices, scale, this);
else console.warn("already a cell there");
this.set("numCells", this.get("numCells")+1);
window.three.render();
},
removeCell: function(cell){
......@@ -253,4 +241,47 @@ Lattice = Backbone.Model.extend({
});
}
});
\ No newline at end of file
});
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////FACE CONN OCTA LATTICE////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
OctaFaceLattice = Lattice.extend({
addCellAtPosition: function(absPosition){
//calc indices in cell matrix
var scale = this.get("scale");
var octHeight = 2*scale/Math.sqrt(6);
var triHeight = scale/2*Math.sqrt(3);
var position = {};
position.x = Math.round(absPosition.x/scale);
position.y = Math.round(absPosition.y/triHeight);
position.z = Math.round(absPosition.z/octHeight);
if (position.z%2 == 1) position.y += 1;
this.addCellAtIndex(position);
},
_makeCellForLatticeType: function(indices, scale){
return new DMASideOctaCell(this.get("cellMode"), indices, scale, this);
}
});
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////EDGE CONN OCTA LATTICE////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////VERTEX CONN OCTA LATTICE//////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////CUBE LATTICE//////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment