//This will be used for generating initial vertexes public void generateInitial3Dway(myTerrain terrain) { leftSideVertexes = new List <Vector3>(); rightSideVertexes = new List <Vector3>(); if (way.nodes.Count == 2) { Vector3 up = new Vector3(0, 1, 0); Vector3 forward = way.nodes[1].meterPosition - way.nodes[0].meterPosition; forward.y = 0.0f; //Vector3 right = Vector3.Cross(forward ,up);********************************************** Vector3 right = Vector3.Cross(up, forward); right = right.normalized; Vector3 left = -1 * right; //LEFT SIDE Vector2 pointLeft1 = new Vector2(way.nodes[0].meterPosition.x, way.nodes[0].meterPosition.z) + new Vector2(left.x, left.z) * (waySize / 2.0f); Vector2 pointLeft2 = new Vector2(way.nodes[1].meterPosition.x, way.nodes[1].meterPosition.z) + new Vector2(left.x, left.z) * (waySize / 2.0f); Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y); Vector3 pointLeft2Pos = new Vector3(pointLeft2.x, terrain.getTerrainHeight2(pointLeft2.y + bbox.meterBottom, pointLeft2.x + bbox.meterLeft), pointLeft2.y); leftSideVertexes.Add(pointLeft1Pos); leftSideVertexes.Add(pointLeft2Pos); if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp) { streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft1Pos, way.nodes[0].id)); } if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp) { streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft2Pos, way.nodes[1].id)); } //RIGHT SIDE Vector2 pointRight1 = new Vector2(way.nodes[0].meterPosition.x, way.nodes[0].meterPosition.z) + new Vector2(right.x, right.z) * (waySize / 2.0f); Vector2 pointRight2 = new Vector2(way.nodes[1].meterPosition.x, way.nodes[1].meterPosition.z) + new Vector2(right.x, right.z) * (waySize / 2.0f); Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y); Vector3 pointRight2Pos = new Vector3(pointRight2.x, terrain.getTerrainHeight2(pointRight2.y + bbox.meterBottom, pointRight2.x + bbox.meterLeft), pointRight2.y); rightSideVertexes.Add(pointRight1Pos); rightSideVertexes.Add(pointRight2Pos); if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp) { streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight1Pos, way.nodes[0].id)); } if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp) { streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight2Pos, way.nodes[1].id)); } } else { for (int i = 0; i < way.nodes.Count - 2; i++) { Vector3 up = new Vector3(0, 1, 0); Vector3 forward1 = way.nodes[i + 1].meterPosition - way.nodes[i].meterPosition; forward1.y = 0.0f; Vector3 right1 = Vector3.Cross(up, forward1); right1 = right1.normalized; Vector3 left1 = -1 * right1; Vector3 forward2 = way.nodes[i + 2].meterPosition - way.nodes[i + 1].meterPosition; forward2.y = 0.0f; Vector3 right2 = Vector3.Cross(up, forward2); right2 = right2.normalized; Vector3 left2 = -1 * right2; //INITIAL POINTS ARE ADDED TO NODES3D if (i == 0) { Vector2 pointLeft1 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f); Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y); leftSideVertexes.Add(pointLeft1Pos); Vector2 pointRight1 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f); Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y); rightSideVertexes.Add(pointRight1Pos); } //1ST LINE LEFT Vector2 p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f); Vector2 p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f); //2ND LINE LEFT Vector2 p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f); Vector2 p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f); //INTERSECTION LEFT Vector2 iL = new Vector2(); Vector3 iLPos; if (!Geometry.getInfiniteLineIntersection(ref iL, p0, p1, p2, p3)) { iLPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom, p1.x + bbox.meterLeft), p1.y); } else { iLPos = new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + bbox.meterBottom, iL.x + bbox.meterLeft), iL.y); } leftSideVertexes.Add(iLPos); if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp) { streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iLPos, way.nodes[i + 1].id)); } //1ST LINE RIGHT p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f); p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f); //2ND LINE RIGHT p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f); p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f); //INTERSECTION RIGHT Vector2 iR = new Vector2(); Vector3 iRPos; if (!Geometry.getInfiniteLineIntersection(ref iR, p0, p1, p2, p3)) { iRPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom, p1.x + bbox.meterLeft), p1.y); } else { iRPos = new Vector3(iR.x, terrain.getTerrainHeight2(iR.y + bbox.meterBottom, iR.x + bbox.meterLeft), iR.y); } rightSideVertexes.Add(iRPos); if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp) { streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iRPos, way.nodes[i + 1].id)); } //ENDING POINTS ARE ADDEDD TO NODES3D if (i == way.nodes.Count - 3) { Vector2 pointLeft1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f); leftSideVertexes.Add(new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y)); Vector2 pointRight1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f); rightSideVertexes.Add(new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y)); return; } } } }
private void generateOtherSide(float size, myTerrain terrain) { List <Vector3> otherside; List <Vector3> generatedside; TerrainInfo ti = terrain.terrainInfo; if (side == pavementSide.left) { otherside = rightSideVertexes; generatedside = leftSideVertexes; } else { otherside = leftSideVertexes; generatedside = rightSideVertexes; } if (otherside.Count == 2) { Vector3 up = Vector3.up; Vector3 forward = otherside[1] - otherside[0]; forward.y = 0.0f; Vector3 sideVec; //if (side == pavementSide.left)******************************************************* // sideVec = Vector3.Cross(up, forward).normalized; //else // sideVec = Vector3.Cross(forward, up).normalized; if (side == pavementSide.left) { sideVec = Vector3.Cross(forward, up).normalized; } else { sideVec = Vector3.Cross(up, forward).normalized; } Vector2 point1 = new Vector2(otherside[0].x, otherside[0].z) + new Vector2(sideVec.x, sideVec.z) * size; Vector2 point2 = new Vector2(otherside[1].x, otherside[1].z) + new Vector2(sideVec.x, sideVec.z) * size; if ((point1 - point2).magnitude < 6.0f) { return; } generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y)); generatedside.Add(new Vector3(point2.x, terrain.getTerrainHeight2(point2.y + ti.shiftZ, point2.x + ti.shiftX), point2.y)); } else { //Checking if side has enough length to draw a pavement float totalsize = 0.0f; for (int k = 0; k < otherside.Count - 1; k++) { totalsize += (otherside[k + 1] - otherside[k]).magnitude; } if (totalsize <= 6.0f) { return; } for (int i = 0; i < otherside.Count; i++) { Vector3 up = Vector3.up; Vector3 forward1 = otherside[i + 1] - otherside[i]; forward1.y = 0.0f; Vector3 sideVec1; //if (side == pavementSide.left)*************************************************************** // sideVec1 = Vector3.Cross(up, forward1).normalized; //else // sideVec1 = Vector3.Cross(forward1, up).normalized; if (side == pavementSide.left) { sideVec1 = Vector3.Cross(forward1, up).normalized; } else { sideVec1 = Vector3.Cross(up, forward1).normalized; } Vector3 forward2 = otherside[i + 2] - otherside[i + 1]; forward2.y = 0.0f; Vector3 sideVec2; if (side == pavementSide.left) { sideVec2 = Vector3.Cross(forward2, up).normalized; } else { sideVec2 = Vector3.Cross(up, forward2).normalized; } //START POINT WAS ADDED TO GENERATED SIDE if (i == 0) { Vector2 point1 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size; generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y)); } //MID POINTS WERE ADDED TO GENERATED SIDE //1ST LINE Vector2 p0 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size; Vector2 p1 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec1.x, sideVec1.z) * size; //2ND LINE Vector2 p2 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec2.x, sideVec2.z) * size; Vector2 p3 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size; Vector2 iL = new Vector2(); //INTERSECTION if (!Geometry.getInfiniteLineIntersection(ref iL, p0, p1, p2, p3)) { generatedside.Add(new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + ti.shiftZ, p1.x + ti.shiftX), p1.y)); } else { generatedside.Add(new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + ti.shiftZ, iL.x + ti.shiftX), iL.y)); } //ENDING POINT WAS ADDEDD TO GENERATED SIDE if (i == otherside.Count - 3) { Vector2 point1 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size; generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y)); return; } } } }
private void generateOtherSide(float size, myTerrain terrain) { List<Vector3> otherside; List<Vector3> generatedside; TerrainInfo ti = terrain.terrainInfo; if (side == pavementSide.left) { otherside = rightSideVertexes; generatedside = leftSideVertexes; } else { otherside = leftSideVertexes; generatedside = rightSideVertexes; } if (otherside.Count == 2) { Vector3 up = Vector3.up; Vector3 forward = otherside[1] - otherside[0]; forward.y = 0.0f; Vector3 sideVec; //if (side == pavementSide.left)******************************************************* // sideVec = Vector3.Cross(up, forward).normalized; //else // sideVec = Vector3.Cross(forward, up).normalized; if (side == pavementSide.left) sideVec = Vector3.Cross(forward, up).normalized; else sideVec = Vector3.Cross(up, forward).normalized; Vector2 point1 = new Vector2(otherside[0].x, otherside[0].z) + new Vector2(sideVec.x, sideVec.z) * size; Vector2 point2 = new Vector2(otherside[1].x, otherside[1].z) + new Vector2(sideVec.x, sideVec.z) * size; if ((point1 - point2).magnitude < 6.0f) return; generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y)); generatedside.Add(new Vector3(point2.x, terrain.getTerrainHeight2(point2.y + ti.shiftZ, point2.x + ti.shiftX), point2.y)); } else { //Checking if side has enough length to draw a pavement float totalsize = 0.0f; for (int k = 0; k < otherside.Count - 1; k++) { totalsize += (otherside[k + 1] - otherside[k]).magnitude; } if (totalsize <= 6.0f) return; for (int i = 0; i < otherside.Count; i++) { Vector3 up = Vector3.up; Vector3 forward1 = otherside[i + 1] - otherside[i]; forward1.y = 0.0f; Vector3 sideVec1; //if (side == pavementSide.left)*************************************************************** // sideVec1 = Vector3.Cross(up, forward1).normalized; //else // sideVec1 = Vector3.Cross(forward1, up).normalized; if (side == pavementSide.left) sideVec1 = Vector3.Cross(forward1, up).normalized; else sideVec1 = Vector3.Cross(up, forward1).normalized; Vector3 forward2 = otherside[i + 2] - otherside[i + 1]; forward2.y = 0.0f; Vector3 sideVec2; if (side == pavementSide.left) sideVec2 = Vector3.Cross(forward2, up).normalized; else sideVec2 = Vector3.Cross(up, forward2).normalized; //START POINT WAS ADDED TO GENERATED SIDE if (i == 0) { Vector2 point1 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size; generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y)); } //MID POINTS WERE ADDED TO GENERATED SIDE //1ST LINE Vector2 p0 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size; Vector2 p1 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec1.x, sideVec1.z) * size; //2ND LINE Vector2 p2 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec2.x, sideVec2.z) * size; Vector2 p3 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size; Vector2 iL = new Vector2(); //INTERSECTION if (!Geometry.getInfiniteLineIntersection(ref iL, p0, p1, p2, p3)) generatedside.Add(new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + ti.shiftZ, p1.x + ti.shiftX), p1.y)); else generatedside.Add(new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + ti.shiftZ, iL.x + ti.shiftX), iL.y)); //ENDING POINT WAS ADDEDD TO GENERATED SIDE if (i == otherside.Count - 3) { Vector2 point1 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size; generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y)); return; } } } }
//This will be used to drape Highway to Terrain Tiles Diagonally private void DiagonalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes) { TerrainInfo ti = terrain.terrainInfo; for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++) { //LEFT SIDE Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z); Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z); //RIGHT SIDE Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z); Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z); int cnt = 0; for (int k = 0, t = 1; k < ti.ColumnCount + ti.RowCount - 3; k++, t++) { //Diagonal Line Vector2 pBottom; Vector2 pTop; if (t < ti.ColumnCount) pTop = new Vector2(ti.meterPositions[0, t].y - ti.shiftX, ti.meterPositions[0, t].x - ti.shiftZ); else pTop = new Vector2(ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].x - ti.shiftZ); if (t < ti.RowCount) pBottom = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ); else pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, 1 + t - ti.RowCount].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, t + 1 - ti.RowCount].x - ti.shiftZ); //LEFT SIDE INTERSECTION Vector2 intersectleft = new Vector2(); //RIGHT SIDE INTERSECTION Vector2 intersectright = new Vector2(); bool isLeft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2); bool isRight = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2); if (isLeft && isRight) { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); cnt++; } else if (isLeft) { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude; Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio; rightSideVertexes.Insert(i + 1, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y)); cnt++; } else if (isRight) { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude; Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio; leftSideVertexes.Insert(i + 1, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y)); cnt++; } } i += cnt; } }
//This will be used to drape Highway to Terrain Tiles Horizontally private void HorizontalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes) { TerrainInfo ti = terrain.terrainInfo; for (int i = 0; i < leftSideVertexes.Count - 1; i++) { //LEFT SIDE Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z); Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z); //RIGHT SIDE Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z); Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z); Vector2 previousIntersectLeft = pointLeft1; Vector2 previousIntersectRight = pointRight1; int leftit = i + 1; int rightit = i + 1; int count = 0; for (int k = ti.bottomIndex, t = 0; k >= ti.topIndex; k--, t++) { //Horizontal Line Vector2 pLeft = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ); Vector2 pRight = new Vector2(ti.meterPositions[t, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[t, ti.ColumnCount - 1].x - ti.shiftZ); Vector2 intersectleft = new Vector2(); Vector2 intersectright = new Vector2(); bool isleft = Geometry.getLineIntersection(ref intersectleft, pLeft, pRight, pointLeft1, pointLeft2); bool isright = Geometry.getLineIntersection(ref intersectright, pLeft, pRight, pointRight1, pointRight2); if (isleft && isright) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftit++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightit++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } previousIntersectLeft = intersectleft; previousIntersectRight = intersectright; count++; } else if (isleft) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftit++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude; Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio; rightSideVertexes.Insert(rightit, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y)); count++; rightit++; previousIntersectLeft = intersectleft; previousIntersectRight = rightPointnew; } else if (isright) { if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightit++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude; Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio; leftSideVertexes.Insert(leftit, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y)); previousIntersectLeft = leftPointnew; previousIntersectRight = intersectright; count++; leftit++; } else continue; } i += count; } }
//This will be used to drape Highway to Terrain Tiles Vertically private void VerticalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes) { TerrainInfo ti = terrain.terrainInfo; for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++) { Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z); Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z); Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z); Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z); int cnt = 0; int leftiterator = i + 1; int rightiterator = i + 1; Vector2 previousIntersectLeft = pointLeft1; Vector2 previousIntersectRight = pointRight1; for (int k = ti.leftIndex, z = 0; k <= ti.rightIndex; k++, z++) { //Vertical Terrain Line Vector2 pTop = new Vector2(ti.meterPositions[0, z].y - ti.shiftX, ti.meterPositions[0, z].x - ti.shiftZ); Vector2 pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, z].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, z].x - ti.shiftZ); Vector2 intersectleft = new Vector2(); Vector2 intersectright = new Vector2(); bool isleft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2); bool isright = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2); if (isleft && isright) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftiterator++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightiterator++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } previousIntersectLeft = intersectleft; previousIntersectRight = intersectright; cnt++; } else if (isleft) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftiterator++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude; Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio; rightSideVertexes.Insert(rightiterator, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y)); previousIntersectLeft = intersectleft; previousIntersectRight = rightPointnew; rightiterator++; cnt++; } else if (isright) { if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightiterator++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude; Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio; leftSideVertexes.Insert(leftiterator, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y)); previousIntersectRight = intersectright; previousIntersectLeft = leftPointnew; leftiterator++; cnt++; } } i += cnt; } }
//This will be used to drape Highway to Terrain Tiles Horizontally private void HorizontalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes) { TerrainInfo ti = terrain.terrainInfo; for (int i = 0; i < leftSideVertexes.Count - 1; i++) { //LEFT SIDE Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z); Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z); //RIGHT SIDE Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z); Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z); Vector2 previousIntersectLeft = pointLeft1; Vector2 previousIntersectRight = pointRight1; int leftit = i + 1; int rightit = i + 1; int count = 0; for (int k = ti.bottomIndex, t = 0; k >= ti.topIndex; k--, t++) { //Horizontal Line Vector2 pLeft = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ); Vector2 pRight = new Vector2(ti.meterPositions[t, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[t, ti.ColumnCount - 1].x - ti.shiftZ); Vector2 intersectleft = new Vector2(); Vector2 intersectright = new Vector2(); bool isleft = Geometry.getLineIntersection(ref intersectleft, pLeft, pRight, pointLeft1, pointLeft2); bool isright = Geometry.getLineIntersection(ref intersectright, pLeft, pRight, pointRight1, pointRight2); if (isleft && isright) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftit++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightit++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } previousIntersectLeft = intersectleft; previousIntersectRight = intersectright; count++; } else if (isleft) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftit++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude; Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio; rightSideVertexes.Insert(rightit, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y)); count++; rightit++; previousIntersectLeft = intersectleft; previousIntersectRight = rightPointnew; } else if (isright) { if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightit++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude; Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio; leftSideVertexes.Insert(leftit, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y)); previousIntersectLeft = leftPointnew; previousIntersectRight = intersectright; count++; leftit++; } else continue; } i += count; } }
//This will be used to drape Highway to Terrain Tiles Diagonally private void DiagonalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes) { TerrainInfo ti = terrain.terrainInfo; for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++) { //LEFT SIDE Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z); Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z); //RIGHT SIDE Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z); Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z); int cnt = 0; for (int k = 0, t = 1; k < ti.ColumnCount + ti.RowCount - 3; k++, t++) { //Diagonal Line Vector2 pBottom; Vector2 pTop; if (t < ti.ColumnCount) pTop = new Vector2(ti.meterPositions[0, t].y - ti.shiftX, ti.meterPositions[0, t].x - ti.shiftZ); else pTop = new Vector2(ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].x - ti.shiftZ); if (t < ti.RowCount) pBottom = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ); else pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, 1 + t - ti.RowCount].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, t + 1 - ti.RowCount].x - ti.shiftZ); //LEFT SIDE INTERSECTION Vector2 intersectleft = new Vector2(); //RIGHT SIDE INTERSECTION Vector2 intersectright = new Vector2(); bool isLeft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2); bool isRight = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2); if (isLeft && isRight) { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); cnt++; } else if (isLeft) { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude; Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio; rightSideVertexes.Insert(i + 1, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y)); cnt++; } else if (isRight) { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude; Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio; leftSideVertexes.Insert(i + 1, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y)); cnt++; } } i += cnt; } }
//This will be used to drape Highway to Terrain Tiles Vertically private void VerticalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes) { TerrainInfo ti = terrain.terrainInfo; for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++) { Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z); Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z); Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z); Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z); int cnt = 0; int leftiterator = i + 1; int rightiterator = i + 1; Vector2 previousIntersectLeft = pointLeft1; Vector2 previousIntersectRight = pointRight1; for (int k = ti.leftIndex, z = 0; k <= ti.rightIndex; k++, z++) { //Vertical Terrain Line Vector2 pTop = new Vector2(ti.meterPositions[0, z].y - ti.shiftX, ti.meterPositions[0, z].x - ti.shiftZ); Vector2 pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, z].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, z].x - ti.shiftZ); Vector2 intersectleft = new Vector2(); Vector2 intersectright = new Vector2(); bool isleft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2); bool isright = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2); if (isleft && isright) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftiterator++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightiterator++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } previousIntersectLeft = intersectleft; previousIntersectRight = intersectright; cnt++; } else if (isleft) { if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude) { leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); leftiterator++; } else { leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y)); } float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude; Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio; rightSideVertexes.Insert(rightiterator, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y)); previousIntersectLeft = intersectleft; previousIntersectRight = rightPointnew; rightiterator++; cnt++; } else if (isright) { if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude) { rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); rightiterator++; } else { rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y)); } float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude; Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio; leftSideVertexes.Insert(leftiterator, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y)); previousIntersectRight = intersectright; previousIntersectLeft = leftPointnew; leftiterator++; cnt++; } } i += cnt; } }
//This will be used for generating initial vertexes public void generateInitial3Dway(myTerrain terrain) { leftSideVertexes = new List<Vector3>(); rightSideVertexes = new List<Vector3>(); if (way.nodes.Count == 2) { Vector3 up = new Vector3(0, 1, 0); Vector3 forward = way.nodes[1].meterPosition - way.nodes[0].meterPosition; forward.y = 0.0f; //Vector3 right = Vector3.Cross(forward ,up);********************************************** Vector3 right = Vector3.Cross(up ,forward); right = right.normalized; Vector3 left = -1 * right; //LEFT SIDE Vector2 pointLeft1 = new Vector2(way.nodes[0].meterPosition.x,way.nodes[0].meterPosition.z) + new Vector2(left.x,left.z) * (waySize /2.0f); Vector2 pointLeft2 = new Vector2(way.nodes[1].meterPosition.x,way.nodes[1].meterPosition.z) + new Vector2(left.x,left.z) * (waySize /2.0f); Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y); Vector3 pointLeft2Pos = new Vector3(pointLeft2.x, terrain.getTerrainHeight2(pointLeft2.y + bbox.meterBottom, pointLeft2.x + bbox.meterLeft), pointLeft2.y); leftSideVertexes.Add(pointLeft1Pos); leftSideVertexes.Add(pointLeft2Pos); if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp) streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft1Pos,way.nodes[0].id)); if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp) streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft2Pos, way.nodes[1].id)); //RIGHT SIDE Vector2 pointRight1 = new Vector2(way.nodes[0].meterPosition.x,way.nodes[0].meterPosition.z) + new Vector2(right.x,right.z) * (waySize /2.0f); Vector2 pointRight2 = new Vector2(way.nodes[1].meterPosition.x,way.nodes[1].meterPosition.z) + new Vector2(right.x,right.z) * (waySize /2.0f); Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y); Vector3 pointRight2Pos = new Vector3(pointRight2.x, terrain.getTerrainHeight2(pointRight2.y + bbox.meterBottom, pointRight2.x + bbox.meterLeft), pointRight2.y); rightSideVertexes.Add(pointRight1Pos); rightSideVertexes.Add(pointRight2Pos); if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp) streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight1Pos, way.nodes[0].id)); if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp) streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight2Pos, way.nodes[1].id)); } else { for (int i = 0; i < way.nodes.Count - 2; i++) { Vector3 up = new Vector3(0, 1, 0); Vector3 forward1 = way.nodes[i+1].meterPosition - way.nodes[i].meterPosition; forward1.y = 0.0f; Vector3 right1 = Vector3.Cross(up, forward1); right1 = right1.normalized; Vector3 left1 = -1 * right1; Vector3 forward2 = way.nodes[i+2].meterPosition - way.nodes[i+1].meterPosition; forward2.y = 0.0f; Vector3 right2 = Vector3.Cross(up, forward2); right2 = right2.normalized; Vector3 left2 = -1 * right2; //INITIAL POINTS ARE ADDED TO NODES3D if(i == 0) { Vector2 pointLeft1 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f); Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y); leftSideVertexes.Add(pointLeft1Pos); Vector2 pointRight1 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f); Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y); rightSideVertexes.Add(pointRight1Pos); } //1ST LINE LEFT Vector2 p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f); Vector2 p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f); //2ND LINE LEFT Vector2 p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f); Vector2 p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f); //INTERSECTION LEFT Vector2 iL = new Vector2(); Vector3 iLPos; if(!Geometry.getInfiniteLineIntersection(ref iL,p0,p1,p2,p3)) iLPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom,p1.x + bbox.meterLeft) ,p1.y); else iLPos = new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + bbox.meterBottom, iL.x + bbox.meterLeft), iL.y); leftSideVertexes.Add(iLPos); if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp) streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iLPos, way.nodes[i + 1].id)); //1ST LINE RIGHT p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f); p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f); //2ND LINE RIGHT p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f); p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f); //INTERSECTION RIGHT Vector2 iR = new Vector2(); Vector3 iRPos; if (!Geometry.getInfiniteLineIntersection(ref iR, p0, p1, p2, p3)) iRPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom, p1.x + bbox.meterLeft), p1.y); else iRPos = new Vector3(iR.x, terrain.getTerrainHeight2(iR.y + bbox.meterBottom, iR.x + bbox.meterLeft), iR.y); rightSideVertexes.Add(iRPos); if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp) streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iRPos, way.nodes[i + 1].id)); //ENDING POINTS ARE ADDEDD TO NODES3D if (i == way.nodes.Count - 3) { Vector2 pointLeft1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f); leftSideVertexes.Add(new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y)); Vector2 pointRight1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f); rightSideVertexes.Add(new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y)); return; } } } }