From fa8b0999600997305f4e16b71071e716a990cb29 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 18 Aug 2015 00:05:27 -0400
Subject: [PATCH] hex base planes

---
 js/baseplane/HexagonalBasePlane.js            | 53 ++++++++++++-------
 js/baseplane/HexagonalRotBasePlane.js         |  4 ++
 js/baseplane/RotEdgeOctaBasePlane.js          |  5 +-
 .../latticeSubclasses/HexagonalLattice.js     |  2 +-
 .../latticeSubclasses/HexagonalRotLattice.js  |  2 +-
 5 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/js/baseplane/HexagonalBasePlane.js b/js/baseplane/HexagonalBasePlane.js
index b012fd78..40be1725 100644
--- a/js/baseplane/HexagonalBasePlane.js
+++ b/js/baseplane/HexagonalBasePlane.js
@@ -14,32 +14,45 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
 
         _makeBasePlaneMesh: function(){
 
-            var scale = lattice.xScale();
-            var dimX = this.get("dimX")*scale;
-            var dimY = this.get("dimY")*scale;
-
-//            var geometry = new THREE.Geometry();
-//
-//            for ( var i = - dimX; i <= dimX+1; i += scale ) {
-//                geometry.vertices.push( new THREE.Vector3(-dimX-scale/2, i-scale/2, 0.01));
-//                geometry.vertices.push( new THREE.Vector3(dimX-scale/2, i-scale/2, 0.01));
-//                geometry.vertices.push( new THREE.Vector3(i-scale/2, -dimX-scale/2, 0.01));
-//                geometry.vertices.push( new THREE.Vector3(i-scale/2, dimX-scale/2, 0.01));
-//
-//            }
-//
+            var xScale = lattice.xScale();
+            var yScale = lattice.yScale();
+            var dimX = this.get("dimX");
+            var dimY = this.get("dimY");
+
+            var geometry = new THREE.Geometry();
+
+            for (var i=-dimY;i<=dimY+1;i++) {
+                for (var j=-dimX;j<=dimX;j+=1){
+                    if (i%2 == 0){
+                        geometry.vertices.push( new THREE.Vector3(j*xScale-xScale/2, i*yScale-1/2, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+0.5)*xScale-xScale/2, i*yScale-1, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+0.5)*xScale-xScale/2, i*yScale-1, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+1)*xScale-xScale/2, i*yScale-1/2, 0.01));
+                        geometry.vertices.push( new THREE.Vector3(j*xScale-xScale/2, i*yScale-1/2, 0.01));
+                        geometry.vertices.push( new THREE.Vector3(j*xScale-xScale/2, (i+1)*yScale-1, 0.01));
+                    } else {
+                        geometry.vertices.push( new THREE.Vector3(j*xScale-xScale/2, i*yScale-1, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+0.5)*xScale-xScale/2, i*yScale-1/2, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+0.5)*xScale-xScale/2, i*yScale-1/2, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+1)*xScale-xScale/2, i*yScale-1, 0.01))
+                        geometry.vertices.push( new THREE.Vector3((j+0.5)*xScale-xScale/2, i*yScale-1/2, 0.01));
+                        geometry.vertices.push( new THREE.Vector3((j+0.5)*xScale-xScale/2, (i+1)*yScale-1, 0.01));
+                    }
+                }
+            }
+
             var planeGeometry = new THREE.Geometry();
-            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.vertices.push( new THREE.Vector3(-dimX*xScale-xScale/2, -dimX*yScale-yScale/2, 0));
+            planeGeometry.vertices.push( new THREE.Vector3(dimX*xScale+xScale/2, -dimX*yScale-yScale/2, 0));
+            planeGeometry.vertices.push( new THREE.Vector3(-dimX*xScale-xScale/2, dimX*yScale+yScale/2, 0));
+            planeGeometry.vertices.push( new THREE.Vector3(dimX*xScale+xScale/2, dimX*yScale+yScale/2, 0));
             planeGeometry.faces.push(new THREE.Face3(0, 1, 3));
             planeGeometry.faces.push(new THREE.Face3(0, 3, 2));
             planeGeometry.computeFaceNormals();
 
             var mesh = new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({color:0x000000, transparent:true, opacity:0.0}));
-            return [mesh];
-//            return [mesh, new THREE.Line(geometry, new THREE.LineBasicMaterial({color:0x000000, transparent:true, linewidth:2, opacity:this.get("material").opacity}), THREE.LinePieces)];
+//            return [mesh];
+            return [mesh, new THREE.Line(geometry, new THREE.LineBasicMaterial({color:0x000000, transparent:true, linewidth:2, opacity:this.get("material").opacity}), THREE.LinePieces)];
         }
     });
 });
\ No newline at end of file
diff --git a/js/baseplane/HexagonalRotBasePlane.js b/js/baseplane/HexagonalRotBasePlane.js
index 0812c034..a6b27cd7 100644
--- a/js/baseplane/HexagonalRotBasePlane.js
+++ b/js/baseplane/HexagonalRotBasePlane.js
@@ -12,6 +12,10 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
             var params = SquareBasePlane.prototype.calcHighlighterParams.call(this, face, point);
             params.position.x += lattice.xScale()/2;
             return params;
+        },
+
+        nextCellPosition: function(highlighterPosition){
+            return highlighterPosition;
         }
 
     });
diff --git a/js/baseplane/RotEdgeOctaBasePlane.js b/js/baseplane/RotEdgeOctaBasePlane.js
index 9c7e6b71..b8d808c6 100644
--- a/js/baseplane/RotEdgeOctaBasePlane.js
+++ b/js/baseplane/RotEdgeOctaBasePlane.js
@@ -16,10 +16,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
         },
 
         nextCellPosition: function(highlighterPosition){
-            highlighterPosition.x -= lattice.xScale()/2;
-            highlighterPosition.y -= lattice.yScale()/2;//undo what we did in calc highlighter params
-            var newPosition = highlighterPosition.clone().add(highlighterPosition.clone().sub(this.getAbsolutePosition()));
-            return lattice.getIndexForPosition(newPosition);
+            return highlighterPosition;
         }
 
     });
diff --git a/js/lattice/latticeSubclasses/HexagonalLattice.js b/js/lattice/latticeSubclasses/HexagonalLattice.js
index 98fbbb5a..b62b5c27 100644
--- a/js/lattice/latticeSubclasses/HexagonalLattice.js
+++ b/js/lattice/latticeSubclasses/HexagonalLattice.js
@@ -9,7 +9,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
     var HexLattice =  {
 
         _initLatticeType: function(){
-            require(['squareBaseplane'], function(BasePlaneClass){
+            require(['hexBaseplane'], function(BasePlaneClass){
                 globals.basePlane = new BasePlaneClass();
             });
             require([this.getHighlighterFile()], function(HighlighterClass){
diff --git a/js/lattice/latticeSubclasses/HexagonalRotLattice.js b/js/lattice/latticeSubclasses/HexagonalRotLattice.js
index 67aed09b..66186904 100644
--- a/js/lattice/latticeSubclasses/HexagonalRotLattice.js
+++ b/js/lattice/latticeSubclasses/HexagonalRotLattice.js
@@ -44,7 +44,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
         xScale: function(cellSeparation){
             if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return 2+Math.sqrt(3)/2+2*cellSeparation;
+            return 3+2*cellSeparation;
         },
 
         yScale: function(cellSeparation){
-- 
GitLab