diff --git a/js/baseplane/BasePlane.js b/js/baseplane/BasePlane.js index 97435485ad9427ed03bfddece2e44f60cb68fc83..10a4ea2fdd3f23c79a61e709a1712eb7afa1e1e6 100644 --- a/js/baseplane/BasePlane.js +++ b/js/baseplane/BasePlane.js @@ -24,6 +24,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'], //draw mesh var meshes = this._makeBasePlaneMesh(); var object3D = new THREE.Object3D(); + this._setPosition(object3D, 0); _.each(meshes, function(mesh){ object3D.add(mesh); }); @@ -46,6 +47,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'], three.render(); }, + _setPosition: function(object3D, height){ + if (!object3D || object3D === undefined) object3D = this.get("object3D"); + object3D.position.set(0,0,height-lattice.zScale()/2); + }, + getAbsoluteIndex: function(){ return this.highligherIndex.clone(); }, diff --git a/js/baseplane/RotEdgeOctaBasePlane.js b/js/baseplane/RotEdgeOctaBasePlane.js index 7c4b4413763e8102b10aca54e9eae66b01d6faf5..e3fb3ff48191445a16949fa210bedb5be9a42d47 100644 --- a/js/baseplane/RotEdgeOctaBasePlane.js +++ b/js/baseplane/RotEdgeOctaBasePlane.js @@ -8,12 +8,18 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three', return SquareBasePlane.extend({ - calcHighlighterParams: function(face, point){ - var params = SquareBasePlane.prototype.calcHighlighterParams.call(this, face, point); + _setPosition: function(object3D, height){ + if (!object3D || object3D === undefined) object3D = this.get("object3D"); + object3D.position.set(0,0,height-lattice.zScale()); + }, + + calcHighlighterParams: function(face, point, index){ + var params = SquareBasePlane.prototype.calcHighlighterParams.call(this, face, point, index); params.position.x -= lattice.xScale()/2; params.position.y -= lattice.yScale()/2; params.position.z -= lattice.zScale()/2; return params; } + }); }); \ No newline at end of file diff --git a/js/baseplane/SquareBasePlane.js b/js/baseplane/SquareBasePlane.js index 29bdbc73bed90532755defb04d26ea91effdcda3..def953f2a479275c94c648a87a19dc410f95e82c 100644 --- a/js/baseplane/SquareBasePlane.js +++ b/js/baseplane/SquareBasePlane.js @@ -16,19 +16,19 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three', var geometry = new THREE.Geometry(); - for ( var i = - dimX; i <= dimX; i += scale ) { - geometry.vertices.push( new THREE.Vector3(-dimX, i, 0)); - geometry.vertices.push( new THREE.Vector3(dimX, i, 0)); - geometry.vertices.push( new THREE.Vector3(i, -dimX, 0)); - geometry.vertices.push( new THREE.Vector3(i, dimX, 0)); + for ( var i = - dimX; i <= dimX+1; i += scale ) { + geometry.vertices.push( new THREE.Vector3(-dimX-scale/2, i-scale/2, 0)); + geometry.vertices.push( new THREE.Vector3(dimX-scale/2, i-scale/2, 0)); + geometry.vertices.push( new THREE.Vector3(i-scale/2, -dimX-scale/2, 0)); + geometry.vertices.push( new THREE.Vector3(i-scale/2, dimX-scale/2, 0)); } var planeGeometry = new THREE.Geometry(); - planeGeometry.vertices.push( new THREE.Vector3(-dimX, -dimX, 0)); - planeGeometry.vertices.push( new THREE.Vector3(dimX, -dimX, 0)); - planeGeometry.vertices.push( new THREE.Vector3(-dimX, dimX, 0)); - planeGeometry.vertices.push( new THREE.Vector3(dimX, dimX, 0)); + planeGeometry.vertices.push( new THREE.Vector3(-dimX-scale/2, -dimX-scale/2, 0)); + planeGeometry.vertices.push( new THREE.Vector3(dimX+scale/2, -dimX-scale/2, 0)); + planeGeometry.vertices.push( new THREE.Vector3(-dimX-scale/2, dimX+scale/2, 0)); + planeGeometry.vertices.push( new THREE.Vector3(dimX+scale/2, dimX+scale/2, 0)); planeGeometry.faces.push(new THREE.Face3(0, 1, 3)); planeGeometry.faces.push(new THREE.Face3(0, 3, 2)); planeGeometry.computeFaceNormals(); diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index a265d3ec5950c6e6465e96011df624ac2424177b..1b7ca98276b5ea718d74d0c3e2e4b733b7fcb8d8 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -12,7 +12,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', function makePartWithLength(length){ var geo = new THREE.BoxGeometry(lattice.xScale(0),lattice.yScale(0),lattice.zScale(0)); geo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1)); - geo.applyMatrix(new THREE.Matrix4().makeTranslation(-length/2+0.5, 0, 0)); + geo.applyMatrix(new THREE.Matrix4().makeTranslation(length/2-0.5, 0, 0)); return geo; } diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index f7c254dc9cc686e4e1ada1c5e5f77d87c7db605c..b79e5827dffabe8641f0c02e12272d729dabd50e 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -98,16 +98,16 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _indexForPosition: function(absPosition){ return new THREE.Vector3( - Math.floor(absPosition.x/this.xScale()), - Math.floor(absPosition.y/this.yScale()), - Math.floor(absPosition.z/this.zScale())); + Math.round(absPosition.x/this.xScale()), + Math.round(absPosition.y/this.yScale()), + Math.round(absPosition.z/this.zScale())); }, _positionForIndex: function(index){ var position = index.clone(); - position.x = (position.x+0.5)*this.xScale(); - position.y = (position.y+0.5)*this.yScale(); - position.z = (position.z+0.5)*this.zScale(); + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z)*this.zScale(); return position; }, diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js index 8fc717cb46e1b7d0a16535648b2b68681e82c70c..6f94d781b265f973a105942270ade7c5069735c2 100644 --- a/js/lattice/OctaRotEdgeLattice.js +++ b/js/lattice/OctaRotEdgeLattice.js @@ -17,22 +17,16 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th }, getIndexForPosition: function(absPosition){ - return new THREE.Vector3( - Math.floor(absPosition.x/this.xScale()+0.5), - Math.floor(absPosition.y/this.yScale()+0.5), - Math.floor(absPosition.z/this.zScale())+0.5); + return this._indexForPosition(absPosition); }, getPositionForIndex: function(index){ - var position = index.clone(); + index = index.clone(); if (index.z %2 != 0){ - position.x += 0.5; - position.y += 0.5; + index.x += 0.5; + index.y += 0.5; } - position.x = (position.x)*this.xScale(); - position.y = (position.y)*this.yScale(); - position.z = (position.z+1)*this.zScale(); - return position; + return this._positionForIndex(index); }, xScale: function(cellSeparation){ diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js index 508c40e2e7ff345738554fce7d494ddd23551686..7173dece647f911852b0e121d11bf85457db1c50 100644 --- a/js/lattice/OctaVertexLattice.js +++ b/js/lattice/OctaVertexLattice.js @@ -17,18 +17,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th }, getIndexForPosition: function(absPosition){ - return new THREE.Vector3( - Math.floor(absPosition.x/this.xScale()+0.5), - Math.floor(absPosition.y/this.yScale()+0.5), - Math.floor(absPosition.z/this.zScale())+0.5); + return this._indexForPosition(absPosition); }, getPositionForIndex: function(index){ - var position = index.clone(); - position.x = (position.x)*this.xScale(); - position.y = (position.y)*this.yScale(); - position.z = (position.z+0.5)*this.zScale(); - return position; + return this._positionForIndex(index); }, xScale: function(cellSeparation){