I have a map of tiles that is drawn using two triangles. I draw my map using a height map to generate vertices and make a Cell(tile) out of 4 vertices like so:
cells[x][z] = new Cell(corner1, corner2, corner3, corner4, colour1, colour2, colour3, colour4);
Now I want it so that if 3 corners match in colour, let's say blue, and the other 4th is green then I should have one triangle will be that blue and the other that is green.
Now my logic for this is as follows:
// triangle 1
VertexInfo v1 = new VertexInfo();
VertexInfo v2 = new VertexInfo();
VertexInfo v3 = new VertexInfo();
// triangle 2
VertexInfo v4 = new VertexInfo();
VertexInfo v5 = new VertexInfo();
VertexInfo v6 = new VertexInfo();
for (Cell[] cellrow : chunks[c].cells) {
for (Cell cell : cellrow) {
if (cell.getColor1().equals(cell.getColor4())
&& cell.getColor1().equals(cell.getColor2())
&& cell.getColor2().equals(cell.getColor4())
&& !cell.getColor1().equals(cell.getColor3())) {
/* 4\
* | \
* 1--\2
*/
v1.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos());
v2.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos());
v3.setPos(cell.getCorner4()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos());
v4.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v5.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v6.setPos(cell.getCorner2()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
meshBuilder.triangle(v1, v2, v3);
meshBuilder.triangle(v4, v5, v6);
} else if (cell.getColor2().equals(cell.getColor1())
&& cell.getColor2().equals(cell.getColor3())
&& cell.getColor3().equals(cell.getColor1())
&& !cell.getColor2().equals(cell.getColor4())) {
/* /3
* / |
* 1/--2
*/
v1.setPos(cell.getCorner1()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos());
v2.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos());
v3.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos());
v4.setPos(cell.getCorner3()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos());
v5.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos());
v6.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos());
meshBuilder.triangle(v1, v2, v3);
meshBuilder.triangle(v4, v5, v6);
} else if (cell.getColor3().equals(cell.getColor4())
&& cell.getColor3().equals(cell.getColor2())
&& cell.getColor2().equals(cell.getColor4())
&& !cell.getColor3().equals(cell.getColor1())) {
/* 4\--3
* \ |
* \2
*/
v1.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos());
v2.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos());
v3.setPos(cell.getCorner4()).setNor(cell.getLeftNormal()).setCol(cell.getColor3()).setUV(cell.getTexturePos());
v4.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v5.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v6.setPos(cell.getCorner2()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
meshBuilder.triangle(v1, v2, v3);
meshBuilder.triangle(v4, v5, v6);
}else if (cell.getColor4().equals(cell.getColor1())
&& cell.getColor4().equals(cell.getColor3())
&& cell.getColor3().equals(cell.getColor1())
&& !cell.getColor4().equals(cell.getColor2())) {
/* 4--/3
* | /
* 1/
*/
v1.setPos(cell.getCorner1()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos());
v2.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos());
v3.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor2()).setUV(cell.getTexturePos());
v4.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos());
v5.setPos(cell.getCorner3()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos());
v6.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor4()).setUV(cell.getTexturePos());
meshBuilder.triangle(v1, v2, v3);
meshBuilder.triangle(v4, v5, v6);
} else {
/* 4---3
* | |
* 1---2
* (both same colour)
*/
v1.setPos(cell.getCorner1()).setNor(cell.getLeftNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v2.setPos(cell.getCorner3()).setNor(cell.getLeftNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v3.setPos(cell.getCorner2()).setNor(cell.getLeftNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v4.setPos(cell.getCorner4()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v5.setPos(cell.getCorner3()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
v6.setPos(cell.getCorner1()).setNor(cell.getRightNormal()).setCol(cell.getColor1()).setUV(cell.getTexturePos());
meshBuilder.triangle(v1, v2, v3);
meshBuilder.triangle(v4, v5, v6);
}
}
But with the above logic I get this:
I don't see why this isn't working. Does anyone have a solution? or has anyone already done this?