public void drawCityRoads (Vector3 a, Vector3 b){ // Vector2 aa = new Vector2 (a.x * heightMapSize/terrainSize, a.z * heightMapSize/terrainSize); // Vector2 bb = new Vector2 (b.x * heightMapSize/terrainSize, b.z * heightMapSize/terrainSize); List<Vector2> roadMesh = new List<Vector2> (); Vector2 aa = new Vector2 (a.x, a.z); Vector2 bb = new Vector2 (b.x, b.z); if (Mathf.Abs(aa.x-bb.x)<0.2f) { float leftx = aa.x - 5f; float rightx = aa.x + 5f; float ny = Mathf.Min (aa.y, bb.y)-5f; float maxy = Mathf.Max (aa.y, bb.y)+5f; while (ny<maxy) { roadMesh.Add (new Vector2 (leftx, ny)); roadMesh.Add (new Vector2 (rightx, ny)); ny += 5f; } roadMesh.Add (new Vector2 (leftx, maxy)); roadMesh.Add (new Vector2 (rightx, maxy)); } if (Mathf.Abs(bb.y - aa.y)<0.2f) { float lefty = aa.y - 5f; float righty = aa.y + 5f; float nx = Mathf.Min (aa.x, bb.x)-5f; float maxx = Mathf.Max (aa.x, bb.x)+5f; while (nx<maxx) { roadMesh.Add (new Vector2 (nx, righty)); roadMesh.Add (new Vector2 (nx, lefty)); //Debug.DrawLine(new Vector3(nx,1000f,righty),new Vector3(nx,1000f,lefty),Color.red,350.0f); nx += 5f; } roadMesh.Add (new Vector2 (maxx, righty)); roadMesh.Add (new Vector2 (maxx, lefty)); } PathGenerator2 pathGenerator = new PathGenerator2 (); pathGenerator.texture = roadTexture; pathGenerator.height = 0.5f; pathGenerator.generate (roadMesh); }
public void generate2(Vector2[] points,int volume, float dist) { if (points.Length >= 4) { // throw new ArgumentException("CatmullRomSpline requires at least 4 points", "points"); List<Vector2> splinePoints = new List<Vector2> (); for (int i = 0; i < points.Length - 3; i++) { float dist2 = Mathf.Pow ((points [i + 1].x - points [i + 2].x), 2) + Mathf.Pow ((points [i + 1].y - points [i + 2].y), 2); dist2 = Mathf.Pow (dist2, 0.5f); int numPoints = Mathf.Max ((int)(dist2 / dist), 1); for (int j = 0; j< numPoints; j++) { splinePoints.Add (pointOnCurve (points [i], points [i + 1], points [i + 2], points [i + 3], (1f / numPoints) * j)); } } splinePoints.Add (points [points.Length - 2]); Vector2[] edgePoints = edgePointsOnCurve (splinePoints.ToArray (), volume); PathGenerator2 pathGenerator = new PathGenerator2(); pathGenerator.pathShader = pathShader; pathGenerator.texture = roadTexture; pathGenerator.height = 0.5f; pathGenerator.generate (new List<Vector2>(edgePoints)); } }
public void Generate(Spline[] points, float dist) { if (points.Length >= 4) { // throw new ArgumentException("CatmullRomSpline requires at least 4 points", "points"); List<Spline> splinePoints = new List<Spline> (); for (int i = 0; i < points.Length - 3; i++) { float dist2 = Mathf.Pow ((points [i + 1].point.x - points [i + 2].point.x), 2) + Mathf.Pow ((points [i + 1].point.y - points [i + 2].point.y), 2); dist2 = Mathf.Pow (dist2, 0.5f); int numPoints = Mathf.Max((int)(dist2 / dist),1); for (int j = 0; j< numPoints; j++) { Spline sp = new Spline (); sp.point = pointOnCurve (points [i].point, points [i + 1].point, points [i + 2].point, points [i + 3].point, (1f/numPoints) * j); sp.volume = ((float )(points [i + 2].volume - points [i + 1].volume) * j / numPoints) + points [i + 1].volume; splinePoints.Add (sp); } } Spline spl = new Spline (); spl.point = points [points.Length - 2].point; spl.volume = points [points.Length - 2].volume; splinePoints.Add (spl); Vector2[] edgePoints = edgePointsOnCurve (splinePoints.ToArray ()); // Vector2[]edgePoints=new Vector2[splinePoints.Count]; // for (int i=0; i<splinePoints.Count;i++) // { // edgePoints[i]=splinePoints[i].point; // } // Vector2[]edgePoints=new Vector2[points.Length]; // for (int i=0; i<points.Length;i++) // { // edgePoints[i]=points[i].point; // } for (int i=0; i<edgePoints.Length; i++){ edgePoints[i].x *= (float)terrainSize / heightMapSize; edgePoints[i].y *= (float)terrainSize / heightMapSize; } PathGenerator2 pathGenerator = new PathGenerator2(); pathGenerator.pathShader = pathShader; pathGenerator.texture = riverTexture; pathGenerator.height = 0.3f; pathGenerator.generate (new List<Vector2>(edgePoints)); // for(int i=1;i<edgePoints.Length;i++) // { // // float beginY= edgePoints[i].x;// * terrainSize / heightMapSize;// - terrainSize/2; // float beginX = edgePoints[i].y;// * terrainSize / heightMapSize;//- terrainSize/2; // float endY = edgePoints[i-1].x;// * terrainSize / heightMapSize;//-terrainSize/2; // float endX = edgePoints[i-1].y;// * terrainSize / heightMapSize;//- terrainSize/2; // // Debug.DrawLine (new Vector3 (beginX, Terrain.activeTerrain.SampleHeight(new Vector3(beginX,0.0f,beginY)) + 10.0f, beginY), new Vector3 (endX, Terrain.activeTerrain.SampleHeight(new Vector3(endX, 0.0f, endY))+10.0f, endY), Color.red, 1000.0f); // } } }