private Vector2 GetDir(OrthoBasis basis, bool useMajor, Vector2 previousDir) { Vector2 dir = (useMajor ? basis.Major : basis.Minor); if (previousDir == Vector2.zero || Vector2.Dot(previousDir, dir) >= 0.0f) { return(dir); } return(-dir); }
public OrthoBasis GetBasis(Vertex pos) { if (cachedBases.ContainsKey(pos)) { return(cachedBases[pos]); } else { OrthoBasis b = GetBasisP(pos.Pos); cachedBases.Add(pos, b); return(b); } }
public OrthoBasis GetBasisP(Vector2 pos) { //Get surface data. float height; Vector3 surfNorm; GetSurfaceData(pos, out height, out surfNorm); //Get the weight scale for each basis based on its distance. if (tempDists.Length < RoadOrthoBases.Count) { tempDists = new float[RoadOrthoBases.Count]; } for (int i = 0; i < RoadOrthoBases.Count; ++i) { tempDists[i] = pos.Distance(RoadOrthoBases[i].Center) / Mathf.Max(0.0001f, RoadOrthoBases[i].Importance); } float invSum = 1.0f / tempDists.Sum(); //Now calculate the weighted average of the ortho bases. OrthoBasis ob = new OrthoBasis(Vector2.zero, Vector2.zero); for (int i = 0; i < RoadOrthoBases.Count; ++i) { float weight = 1.0f - (tempDists[i] * invSum); //Edge-case. if (RoadOrthoBases.Count == 1) { weight = 1.0f; } OrthoBasis tempOB = RoadOrthoBases[i].GetOrthoBasis(pos, height, surfNorm); ob.Major += tempOB.Major * weight; ob.Minor += tempOB.Minor * weight; } return(ob); }