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

cell indices passed in only, no position

parent b5d09210
No related branches found
No related tags found
No related merge requests found
......@@ -23,16 +23,30 @@
new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})];
function DMACell(mode, position, indices) {
function DMACell(mode, indices) {
this.position = position;
this.indices = indices;
this.position = this._calcPositionForScale(30);
this.parts = this._initParts();
this.drawForMode(mode);
}
DMACell.prototype._calcPositionForScale = function(scale){
var position = {};
var indices = this.indices;
var octHeight = 3*scale/8*Math.sqrt(5);//this isn't quite right
var triHeight = scale/2*Math.sqrt(3);
position.x = indices.x*scale;
position.y = indices.y*triHeight;
position.z = indices.z*octHeight;
if (indices.y%2 == 1) position.x -= scale/2;
if (indices.z%2 == 1) position.y -= triHeight*4/3;
return position;
};
DMACell.prototype._initParts = function(){
var parts = [];
for (var i=0;i<3;i++){
......
......@@ -55,7 +55,8 @@ Lattice = Backbone.Model.extend({
}
var index = this._subtract(position, this.get("cellsMin"));
cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), absPosition, position);
cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position);
this.set("numCells", this.get("numCells")+1);
window.three.render();
},
......@@ -146,14 +147,14 @@ Lattice = Backbone.Model.extend({
removeCell: function(object){
var cell = object.parent.myCell;
var relativeIndex = this._subtract(cell.indices, this.get("cellsMin"));
var index = this._subtract(cell.indices, this.get("cellsMin"));
var cells = this.get("cells");
cells[relativeIndex.x][relativeIndex.y][relativeIndex.z] = null;
cells[index.x][index.y][index.z] = null;
cell.remove();
//todo shrink cells matrix if needed
this.set("numCells", cells.length);
this.set("numCells", this.get("numCells")-1);
window.three.render();
},
......
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