From 1ead5228e3ae4020d959b71805b1dc2c4230d504 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 27 May 2015 15:08:12 -0700 Subject: [PATCH] gik part placement working again --- js/cells/DMACell.js | 14 ++++++++++++++ js/cells/GIKCell.js | 18 +++++++++++++++++- js/models/ThreeModel.js | 6 +++--- js/threeViews/Highlighter.js | 7 ++++--- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 2575f0f6..d0297963 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -139,6 +139,20 @@ DMACell.prototype.getEuler = function(){ return this.object3D.rotation.clone(); }; +DMACell.prototype.axisScale = function(axis){ + switch (axis){ + case "x": + return this.xScale(); + case "y": + return this.yScale(); + case "z": + return this.zScale(); + default: + console.warn(axis + " axis not recognized"); + break; + } +}; + DMACell.prototype.xScale = function(){ return globals.lattice.xScale(0); }; diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index ac5d263e..9910f7fe 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -15,6 +15,7 @@ GIKCell.prototype.setSuperCell = function(superCell, index){ this.superCell = superCell; this.superCellIndex = index; + console.log(this.indices); CubeCell.call(this, this.indices); if (this.superCellIndex == this.superCell.getLength()) this.object3D.rotateZ(Math.PI); return this.object3D; @@ -25,7 +26,10 @@ }; GIKCell.prototype._translateCell = function(object3D){ - if (this.superCellIndex) object3D.position.set(-this.superCellIndex*this.xScale(),0, 0); + if (this.superCellIndex != null) { + var offset = this.superCellIndex-this.superCell.getLength(); + object3D.position.set(offset*this.xScale(),0, 0); + } return object3D; }; @@ -48,6 +52,18 @@ return parts; }; + GIKCell.prototype.calcHighlighterPosition = function(face){ + +// var params = CubeCell.prototype.calcHighlighterPosition.call(); + var direction = face.normal.clone().applyEuler(this.object3D.rotation).applyEuler(this.superCell.object3D.rotation); + var position = globals.lattice.getPositionForIndex(this.indices); + var self = this; + _.each(_.keys(position), function(key){ + position[key] += direction[key]*self.axisScale(key)/2; + }); + return {index: _.clone(this.indices), direction:direction, position:position}; + }; + self.GIKCell = GIKCell; })(); \ No newline at end of file diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index 4c96beec..a3a13c63 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -21,9 +21,9 @@ function ThreeModel(){ function initialize(){ - camera.position.x = 125; - camera.position.y = 100; - camera.position.z = 165; + camera.position.x = 15; + camera.position.y = 12; + camera.position.z = 12; camera.up.set(0,0,1);//set z axis as "up" scene.fog = new THREE.FogExp2(0xcccccc, 0.000); diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 3948934f..bb032115 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -210,14 +210,15 @@ GIKHighlighter = Highlighter.extend({ }, _setPosition: function(position, direction){ - this.mesh.position.set(position.x+direction.x, position.y+direction.y, position.z+globals.lattice.zScale()/2*direction.z); + this.mesh.position.set(position.x+direction.x/2, position.y+direction.y/2, position.z+globals.lattice.zScale()*direction.z/2); }, _setRotation: function(direction, index){ var superCellIndex = globals.appState.get("superCellIndex"); - if ((index.z%2 == 0 && Math.abs(direction.z) > 0.9) || (index.z%2 != 0 && Math.abs(direction.z) < 0.1)) this.mesh.rotation.set(0, 0, Math.PI/2); + if ((index.z%2 == 0 && Math.abs(direction.z) > 0.9) || (index.z%2 != 0 && Math.abs(direction.z) < 0.1)) + this.mesh.rotation.set(0, 0, Math.PI/2); else this.mesh.rotation.set(0,0,0); - this.mesh.translateX(superCellIndex); + this.mesh.translateX(superCellIndex - this.mesh.scale.x/2 + 0.5); }, updateGikLength: function(){ -- GitLab