public override Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal) { // procurar ponto do segmento mais próximo ao centro da esfera Vector3 closest = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, Troll.KinematicData.position)); // Check if we pass through the center point Vector3 newPt; if (closest.sqrMagnitude == 0) { // Get any vector at right angles to the segment Vector3 dirn = path.EndPosition - path.StartPosition; //pode nao ser esta func TO DO Vector3 newdirn = Vector3.Cross(dirn, Vector3.Cross(dirn, Vector3.forward)); newPt = Troll.KinematicData.position + newdirn * TrollRadius * margin; } else { // Otherwise project the point out beyond the radius newPt = (Troll.KinematicData.position + (closest - Troll.KinematicData.position) * TrollRadius * margin) / closest.sqrMagnitude; } // Set up the goal and return goal.position = newPt; return goal; }
public override Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal) { if (this.chars.KinematicData.velocity.sqrMagnitude > 1.5f) { this.chars.KinematicData.velocity *= 0.01f; } return goal; /* // procurar ponto do segmento mais próximo ao centro da esfera Vector3 closest = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, chars.KinematicData.position)); // Check if we pass through the center point Vector3 newPt; float i = 1.0f; while (i < 25.0f) { for(int a = 0; a < 360; a++) { float nx = (float) (closest.sqrMagnitude * i * Math.Cos((a * (Math.PI / 180)))); float ny = (float) (closest.sqrMagnitude * i * Math.Sin((a * (Math.PI / 180)))); newPt = new Vector3(nx, closest.y,ny); if (navMeshP.IsPointOnGraph(newPt)) { goal.position = newPt; return goal; } } i = i + 0.25f; } return goal; // Set up the goal and return*/ }
//private NavMeshPathGraph navMesh; public DecomposerPersonPathCreation() { //this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; personPath = new GlobalPath(); LocalPath localPath = new LineSegmentPath(); personPath.LocalPaths.Add(localPath); }
public void CalculateLocalPathsFromPathPositions(Vector3 initialPosition) { this.Length = 0; Vector3 previousPosition = this.PathPositions[0]; LineSegmentPath lineSegment; int init; if (this.PathPositions.Count == 1) { init = 0; previousPosition = initialPosition; } else { init = 1; } for (int i = init; i < this.PathPositions.Count; i++) { if (!previousPosition.Equals(this.PathPositions[i])) { lineSegment = new LineSegmentPath(previousPosition, this.PathPositions[i], this.Length); if (lineSegment.Length > 0) { this.LocalPaths.Add(lineSegment); this.Length += lineSegment.Length; previousPosition = this.PathPositions[i]; } } } }
public override Vector3 GetPosition(float param) { int i = (int)Math.Floor(param); //HERE LineSegmentPath path = LocalPaths[i] as LineSegmentPath; return path.GetPosition(param - i); }
public override Boolean WillViolate(LineSegmentPath path) { //maybe not right func TO DO if (MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, center) < radius){ return true; } return false; }
public override float GetParam(Vector3 position, float previousParam) { int i = (int)Math.Floor(previousParam); LineSegmentPath path = LocalPaths[i] as LineSegmentPath; return i + path.GetParam(position, previousParam-i); }
public override LineSegmentPath GetPath() { LineSegmentPath segment; if (goal.hasPosition) { segment = new LineSegmentPath(this.Character.position, goal.position); } else{ segment = new LineSegmentPath(this.Character.position, this.Character.position); } return segment; }
public override Boolean WillViolate(LineSegmentPath path) { Vector3 impactPoint = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, Troll.KinematicData.position)); Vector3 direction = Troll.KinematicData.position - impactPoint; float distance = Vector3.Magnitude(direction); if(distance < TrollRadius) { // Debug.Log("VIOLATE!"); return true; } // Debug.Log("NO VIOLATE!"); return false; }
public override Vector3 GetPosition(float param) { //TODO: implement latter int localPathIndex = (int)Math.Truncate(param); if (localPathIndex + 1 < this.PathPositions.Count) { LineSegmentPath segment = new LineSegmentPath(PathPositions[localPathIndex], PathPositions[localPathIndex + 1]); return(segment.GetPosition(param)); } else { return(this.PathPositions[this.PathPositions.Count - 1]); } }
/// <summary> /// Method used to smooth a received path, using a string pulling technique /// it returns a new path, where the path positions are selected in order to provide a smoother path /// </summary> /// <param name="data"></param> /// <param name="globalPath"></param> /// <returns></returns> public static GlobalPath SmoothPath(KinematicData data, GlobalPath globalPath) { var smoothedPath = new GlobalPath { IsPartial = globalPath.IsPartial }; Vector3 currentPos = data.position; Vector3 Pnext = globalPath.PathPositions[globalPath.PathPositions.Count - 1]; smoothedPath.PathPositions.Add(Pnext); int index = globalPath.PathPositions.Count - 2; if (index <= 0) { return globalPath; } bool finish = false; while (true) { NavigationGraphNode node = globalPath.PathNodes[index]; LocalPath L = new LineSegmentPath(currentPos, Pnext); Vector3 closestPoint = GetShortestDistancePositionInEdge(node, L); if ((closestPoint - smoothedPath.PathPositions[smoothedPath.PathPositions.Count - 1]).sqrMagnitude >= (MinWidth * MinWidth)) { smoothedPath.PathPositions.Add(closestPoint); Pnext = closestPoint; } index--; if (index <= 0 || finish) { //smoothedPath.PathPositions.Reverse(); //return smoothedPath; break; } if ((closestPoint - currentPos).sqrMagnitude < MinDistanceToCharacter * MinDistanceToCharacter) { finish = true; } } smoothedPath.PathPositions.Reverse(); return smoothedPath; }
public void CalculateLocalPathsFromPathPositions(Vector3 initialPosition) { this.PathDistance = 0.0f; Vector3 previousPosition = initialPosition; for (int i = 0; i < this.PathPositions.Count; i++) { if(!previousPosition.Equals(this.PathPositions[i])) { LineSegmentPath local = new LineSegmentPath(previousPosition, this.PathPositions[i]); previousPosition = this.PathPositions[i]; this.PathDistance += Vector3.Distance(local.EndPosition, local.StartPosition); this.LocalPaths.Add(local); } } }
public override bool PathEnd(float param) { //TODO: implement latter int localPathIndex = (int)Math.Truncate(param); float decimalParam = param - localPathIndex; if (localPathIndex == this.PathPositions.Count - 2) { LineSegmentPath segment = new LineSegmentPath(PathPositions[localPathIndex], PathPositions[localPathIndex + 1]); return(segment.PathEnd(decimalParam)); } else { return(false); } }
public void CalculateLocalPathsFromPathPositions(Vector3 initialPosition) { Vector3 previousPosition = initialPosition; float currentParam = 0; for (int i = 0; i < this.PathPositions.Count; i++) { if (!previousPosition.Equals(this.PathPositions[i])) { var localPath = new LineSegmentPath(currentParam, previousPosition, this.PathPositions [i]); this.LocalPaths.Add(localPath); currentParam = localPath.EndParam; previousPosition = this.PathPositions[i]; } } this.EndParam = currentParam; this.CurrentLocalPathIndex = 0; }
public override Boolean WillViolate(LineSegmentPath path) { /* List<NavigationGraphNode> nodes = (List<NavigationGraphNode>)Utils.Reflection.GetInstanceField(typeof(RAINNavigationGraph), path, "_pathNodes"); foreach (NavigationGraphNode nvn in nodes) { if (nvn.Position.Equals((chars.KinematicData.position + chars.KinematicData.velocity * 0.8f))) { return false; } } return true;*/ if(navMeshP.IsPointOnGraph((chars.KinematicData.position + chars.KinematicData.velocity * 0.5f))) { return false; } else { return true; } }
/// <summary> /// Method used to smooth a received path, using a string pulling technique /// it returns a new path, where the path positions are selected in order to provide a smoother path /// </summary> /// <param name="data"></param> /// <param name="globalPath"></param> /// <returns></returns> public static GlobalPath SmoothPath(KinematicData data, GlobalPath globalPath) { var smoothedPath = new GlobalPath { IsPartial = globalPath.IsPartial }; Vector3 currentPos = globalPath.PathPositions[0]; Vector3 Pnext = globalPath.PathPositions[globalPath.PathPositions.Count - 1]; smoothedPath.PathPositions.Add(Pnext); int index = globalPath.PathPositions.Count - 2; if (index <= 0) { return globalPath; } while (true) { NavigationGraphNode node = globalPath.PathNodes[index]; LocalPath L = new LineSegmentPath(currentPos, Pnext); Vector3 closestPoint = GetShortestDistancePositionInEdge(node, L); if ((closestPoint - smoothedPath.PathPositions[smoothedPath.PathPositions.Count - 1]).sqrMagnitude >= (MinWidth * MinWidth)) { smoothedPath.PathPositions.Add(closestPoint); } index--; if (index <= 0) { smoothedPath.PathPositions.Reverse(); return smoothedPath; } else { Pnext = closestPoint; } } }
public override float GetParam(Vector3 position, float previousParam) { //TODO: implement latter int localPathIndex = (int)Math.Truncate(previousParam); if (localPathIndex + 2 < this.PathPositions.Count) { //Debug.Log("TRYYYYYYYYYYYYYY"); LineSegmentPath segment = new LineSegmentPath(PathPositions[localPathIndex], PathPositions[localPathIndex + 1]); LineSegmentPath segment2 = new LineSegmentPath(PathPositions[localPathIndex + 1], PathPositions[localPathIndex + 2]); float param = localPathIndex + segment.GetParam(position, previousParam); float param2 = localPathIndex + 1 + segment2.GetParam(position, previousParam); if (Math.Abs(param - previousParam) < Math.Abs(param2 - previousParam)) { return(param); } else { return(param2); } } else if (localPathIndex == this.PathPositions.Count - 2) { //Debug.Log("catchchchchch"); LineSegmentPath segment = new LineSegmentPath(PathPositions[localPathIndex], PathPositions[localPathIndex + 1]); return(localPathIndex + segment.GetParam(position, previousParam)); } else { return(previousParam); } }
public abstract Boolean WillViolate(LineSegmentPath path);
public abstract Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal);