public static NearestPointStrict ( Vector3 lineStart, Vector3 lineEnd, Vector3 point ) : Vector3 | ||
lineStart | Vector3 | |
lineEnd | Vector3 | |
point | Vector3 | |
Résultat | Vector3 |
public Vector3 GetMovementVector(Vector3 point) { if (this.vectorPath == null || this.vectorPath.Count == 0) { return(Vector3.zero); } if (this.vectorPath.Count == 1) { return(this.vectorPath[0] - point); } float num = float.PositiveInfinity; int num2 = 0; for (int i = 0; i < this.vectorPath.Count - 1; i++) { Vector3 a = AstarMath.NearestPointStrict(this.vectorPath[i], this.vectorPath[i + 1], point); float sqrMagnitude = (a - point).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; num2 = i; } } return(this.vectorPath[num2 + 1] - point); }
//Movement stuff /** Returns in which direction to move from a point on the path. * A simple and quite slow (well, compared to more optimized algorithms) algorithm first finds the closest path segment (from #vectorPath) and then returns * the direction to the next point from there. The direction is not normalized. * \returns Direction to move from a \a point, returns Vector3.zero if #vectorPath is null or has a length of 0 */ public Vector3 GetMovementVector(Vector3 point) { if (vectorPath == null || vectorPath.Count == 0) { return(Vector3.zero); } if (vectorPath.Count == 1) { return(vectorPath[0] - point); } float minDist = float.PositiveInfinity; //Mathf.Infinity; int minSegment = 0; for (int i = 0; i < vectorPath.Count - 1; i++) { Vector3 closest = AstarMath.NearestPointStrict(vectorPath[i], vectorPath[i + 1], point); float dist = (closest - point).sqrMagnitude; if (dist < minDist) { minDist = dist; minSegment = i; } } return(vectorPath[minSegment + 1] - point); }
public override void Apply(Path _p, ModifierData source) { ABPath aBPath = _p as ABPath; if (aBPath == null) { return; } if (aBPath.vectorPath.get_Count() == 0) { return; } if (aBPath.vectorPath.get_Count() < 2 && !this.addPoints) { aBPath.vectorPath.Add(aBPath.vectorPath.get_Item(0)); } VInt3 vInt = VInt3.zero; VInt3 vInt2 = VInt3.zero; if (this.exactStartPoint == StartEndModifier.Exactness.Original) { vInt = this.GetClampedPoint(aBPath.path.get_Item(0).position, aBPath.originalStartPoint, aBPath.path.get_Item(0)); } else if (this.exactStartPoint == StartEndModifier.Exactness.ClosestOnNode) { vInt = this.GetClampedPoint(aBPath.path.get_Item(0).position, aBPath.startPoint, aBPath.path.get_Item(0)); } else if (this.exactStartPoint == StartEndModifier.Exactness.Interpolate) { vInt = this.GetClampedPoint(aBPath.path.get_Item(0).position, aBPath.originalStartPoint, aBPath.path.get_Item(0)); VInt3 position = aBPath.path.get_Item(0).position; VInt3 position2 = aBPath.path.get_Item((1 < aBPath.path.get_Count()) ? 1 : 0).position; vInt = AstarMath.NearestPointStrict(ref position, ref position2, ref vInt); } else { vInt = aBPath.path.get_Item(0).position; } if (this.exactEndPoint == StartEndModifier.Exactness.Original) { vInt2 = this.GetClampedPoint(aBPath.path.get_Item(aBPath.path.get_Count() - 1).position, aBPath.originalEndPoint, aBPath.path.get_Item(aBPath.path.get_Count() - 1)); } else if (this.exactEndPoint == StartEndModifier.Exactness.ClosestOnNode) { vInt2 = this.GetClampedPoint(aBPath.path.get_Item(aBPath.path.get_Count() - 1).position, aBPath.endPoint, aBPath.path.get_Item(aBPath.path.get_Count() - 1)); } else if (this.exactEndPoint == StartEndModifier.Exactness.Interpolate) { vInt2 = this.GetClampedPoint(aBPath.path.get_Item(aBPath.path.get_Count() - 1).position, aBPath.originalEndPoint, aBPath.path.get_Item(aBPath.path.get_Count() - 1)); VInt3 position3 = aBPath.path.get_Item(aBPath.path.get_Count() - 1).position; VInt3 position4 = aBPath.path.get_Item((aBPath.path.get_Count() - 2 >= 0) ? (aBPath.path.get_Count() - 2) : 0).position; vInt2 = AstarMath.NearestPointStrict(ref position3, ref position4, ref vInt2); } else { vInt2 = aBPath.path.get_Item(aBPath.path.get_Count() - 1).position; } if (!this.addPoints) { aBPath.vectorPath.set_Item(0, vInt); aBPath.vectorPath.set_Item(aBPath.vectorPath.get_Count() - 1, vInt2); } else { if (this.exactStartPoint != StartEndModifier.Exactness.SnapToNode) { aBPath.vectorPath.Insert(0, vInt); } if (this.exactEndPoint != StartEndModifier.Exactness.SnapToNode) { aBPath.vectorPath.Add(vInt2); } } }
protected virtual void Update() { RichAI.deltaTime = Mathf.Min(Time.smoothDeltaTime * 2f, Time.deltaTime); if (this.rp != null) { RichPathPart currentPart = this.rp.GetCurrentPart(); RichFunnel richFunnel = currentPart as RichFunnel; if (richFunnel != null) { Vector3 vector = this.UpdateTarget(richFunnel); if (Time.frameCount % 5 == 0) { this.wallBuffer.Clear(); richFunnel.FindWalls(this.wallBuffer, this.wallDist); } int num = 0; Vector3 vector2 = this.buffer[num]; Vector3 vector3 = vector2 - vector; vector3.y = 0f; bool flag = Vector3.Dot(vector3, this.currentTargetDirection) < 0f; if (flag && this.buffer.Count - num > 1) { num++; vector2 = this.buffer[num]; } if (vector2 != this.lastTargetPoint) { this.currentTargetDirection = vector2 - vector; this.currentTargetDirection.y = 0f; this.currentTargetDirection.Normalize(); this.lastTargetPoint = vector2; } vector3 = vector2 - vector; vector3.y = 0f; float magnitude = vector3.magnitude; this.distanceToWaypoint = magnitude; vector3 = ((magnitude != 0f) ? (vector3 / magnitude) : Vector3.zero); Vector3 vector4 = vector3; Vector3 vector5 = Vector3.zero; if (this.wallForce > 0f && this.wallDist > 0f) { float num2 = 0f; float num3 = 0f; for (int i = 0; i < this.wallBuffer.Count; i += 2) { Vector3 vector6 = AstarMath.NearestPointStrict(this.wallBuffer[i], this.wallBuffer[i + 1], this.tr.position); float sqrMagnitude = (vector6 - vector).sqrMagnitude; if (sqrMagnitude <= this.wallDist * this.wallDist) { Vector3 normalized = (this.wallBuffer[i + 1] - this.wallBuffer[i]).normalized; float num4 = Vector3.Dot(vector3, normalized) * (1f - Math.Max(0f, 2f * (sqrMagnitude / (this.wallDist * this.wallDist)) - 1f)); if (num4 > 0f) { num3 = Math.Max(num3, num4); } else { num2 = Math.Max(num2, -num4); } } } Vector3 vector7 = Vector3.Cross(Vector3.up, vector3); vector5 = vector7 * (num3 - num2); } bool flag2 = this.lastCorner && this.buffer.Count - num == 1; if (flag2) { if (this.slowdownTime < 0.001f) { this.slowdownTime = 0.001f; } Vector3 vector8 = vector2 - vector; vector8.y = 0f; if (this.preciseSlowdown) { vector3 = (6f * vector8 - 4f * this.slowdownTime * this.velocity) / (this.slowdownTime * this.slowdownTime); } else { vector3 = 2f * (vector8 - this.slowdownTime * this.velocity) / (this.slowdownTime * this.slowdownTime); } vector3 = Vector3.ClampMagnitude(vector3, this.acceleration); vector5 *= Math.Min(magnitude / 0.5f, 1f); if (magnitude < this.endReachedDistance) { this.NextPart(); } } else { vector3 *= this.acceleration; } this.velocity += (vector3 + vector5 * this.wallForce) * RichAI.deltaTime; if (this.slowWhenNotFacingTarget) { float num5 = (Vector3.Dot(vector4, this.tr.forward) + 0.5f) * 0.6666667f; float num6 = Mathf.Sqrt(this.velocity.x * this.velocity.x + this.velocity.z * this.velocity.z); float y = this.velocity.y; this.velocity.y = 0f; float num7 = Mathf.Min(num6, this.maxSpeed * Mathf.Max(num5, 0.2f)); this.velocity = Vector3.Lerp(this.tr.forward * num7, this.velocity.normalized * num7, Mathf.Clamp((!flag2) ? 0f : (magnitude * 2f), 0.5f, 1f)); this.velocity.y = y; } else { float num8 = Mathf.Sqrt(this.velocity.x * this.velocity.x + this.velocity.z * this.velocity.z); num8 = this.maxSpeed / num8; if (num8 < 1f) { this.velocity.x = this.velocity.x * num8; this.velocity.z = this.velocity.z * num8; } } if (flag2) { Vector3 trotdir = Vector3.Lerp(this.velocity, this.currentTargetDirection, Math.Max(1f - magnitude * 2f, 0f)); this.RotateTowards(trotdir); } else { this.RotateTowards(this.velocity); } this.velocity += RichAI.deltaTime * this.gravity; if (this.rvoController != null && this.rvoController.enabled) { this.tr.position = vector; this.rvoController.Move(this.velocity); } else if (this.controller != null && this.controller.enabled) { this.tr.position = vector; this.controller.Move(this.velocity * RichAI.deltaTime); } else { float y2 = vector.y; vector += this.velocity * RichAI.deltaTime; vector = this.RaycastPosition(vector, y2); this.tr.position = vector; } } else if (this.rvoController != null && this.rvoController.enabled) { this.rvoController.Move(Vector3.zero); } if (currentPart is RichSpecial) { RichSpecial rs = currentPart as RichSpecial; if (!this.traversingSpecialPath) { base.StartCoroutine(this.TraverseSpecial(rs)); } } } else if (this.rvoController != null && this.rvoController.enabled) { this.rvoController.Move(Vector3.zero); } else if (!(this.controller != null) || !this.controller.enabled) { this.tr.position = this.RaycastPosition(this.tr.position, this.tr.position.y); } }
public static float DistancePointSegmentStrict(Vector3 a, Vector3 b, Vector3 p) { Vector3 a2 = AstarMath.NearestPointStrict(a, b, p); return((a2 - p).sqrMagnitude); }
/** Update is called once per frame */ protected virtual void Update() { deltaTime = Mathf.Min(Time.smoothDeltaTime * 2, Time.deltaTime); if (rp != null) { //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch(); //w.Start(); RichPathPart pt = rp.GetCurrentPart(); RichFunnel fn = pt as RichFunnel; if (fn != null) { //Clear buffers for reuse Vector3 position = UpdateTarget(fn); //tr.position = ps; //Only get walls every 5th frame to save on performance if (Time.frameCount % 5 == 0) { wallBuffer.Clear(); fn.FindWalls(wallBuffer, wallDist); } /*for (int i=0;i<wallBuffer.Count;i+=2) { * Debug.DrawLine (wallBuffer[i],wallBuffer[i+1],Color.magenta); * }*/ //Pick next waypoint if current is reached int tgIndex = 0; /*if (buffer.Count > 1) { * if ((buffer[tgIndex]-tr.position).sqrMagnitude < pickNextWaypointDist*pickNextWaypointDist) { * tgIndex++; * } * }*/ //Target point Vector3 tg = buffer[tgIndex]; Vector3 dir = tg - position; dir.y = 0; bool passedTarget = Vector3.Dot(dir, currentTargetDirection) < 0; //Check if passed target in another way if (passedTarget && buffer.Count - tgIndex > 1) { tgIndex++; tg = buffer[tgIndex]; } if (tg != lastTargetPoint) { currentTargetDirection = (tg - position); currentTargetDirection.y = 0; currentTargetDirection.Normalize(); lastTargetPoint = tg; //Debug.DrawRay (tr.position, Vector3.down*2,Color.blue,0.2f); } //Direction to target dir = (tg - position); dir.y = 0; float magn = dir.magnitude; //Write out for other scripts to read distanceToWaypoint = magn; //Normalize dir = magn == 0 ? Vector3.zero : dir / magn; Vector3 normdir = dir; Vector3 force = Vector3.zero; if (wallForce > 0 && wallDist > 0) { float wLeft = 0; float wRight = 0; for (int i = 0; i < wallBuffer.Count; i += 2) { Vector3 closest = AstarMath.NearestPointStrict(wallBuffer[i], wallBuffer[i + 1], tr.position); float dist = (closest - position).sqrMagnitude; if (dist > wallDist * wallDist) { continue; } Vector3 tang = (wallBuffer[i + 1] - wallBuffer[i]).normalized; //Using the fact that all walls are laid out clockwise (seeing from inside) //Then left and right (ish) can be figured out like this float dot = Vector3.Dot(dir, tang) * (1 - System.Math.Max(0, (2 * (dist / (wallDist * wallDist)) - 1))); if (dot > 0) { wRight = System.Math.Max(wRight, dot); } else { wLeft = System.Math.Max(wLeft, -dot); } } Vector3 norm = Vector3.Cross(Vector3.up, dir); force = norm * (wRight - wLeft); //Debug.DrawRay (tr.position, force, Color.cyan); } //Is the endpoint of the path (part) the current target point bool endPointIsTarget = lastCorner && buffer.Count - tgIndex == 1; if (endPointIsTarget) { //Use 2nd or 3rd degree motion equation to figure out acceleration to reach target in "exact" [slowdownTime] seconds //Clamp to avoid divide by zero if (slowdownTime < 0.001f) { slowdownTime = 0.001f; } Vector3 diff = tg - position; diff.y = 0; if (preciseSlowdown) { //{ t = slowdownTime //{ diff = vt + at^2/2 + qt^3/6 //{ 0 = at + qt^2/2 //{ solve for a dir = (6 * diff - 4 * slowdownTime * velocity) / (slowdownTime * slowdownTime); } else { dir = 2 * (diff - slowdownTime * velocity) / (slowdownTime * slowdownTime); } dir = Vector3.ClampMagnitude(dir, acceleration); force *= System.Math.Min(magn / 0.5f, 1); if (magn < endReachedDistance) { //END REACHED NextPart(); } } else { dir *= acceleration; } //Debug.DrawRay (tr.position+Vector3.up, dir*3, Color.blue); velocity += (dir + force * wallForce) * deltaTime; if (slowWhenNotFacingTarget) { float dot = (Vector3.Dot(normdir, tr.forward) + 0.5f) * (1.0f / 1.5f); //velocity = Vector3.ClampMagnitude (velocity, maxSpeed * Mathf.Max (dot, 0.2f) ); float xzmagn = Mathf.Sqrt(velocity.x * velocity.x + velocity.z * velocity.z); float prevy = velocity.y; velocity.y = 0; float mg = Mathf.Min(xzmagn, maxSpeed * Mathf.Max(dot, 0.2f)); velocity = Vector3.Lerp(tr.forward * mg, velocity.normalized * mg, Mathf.Clamp(endPointIsTarget ? (magn * 2) : 0, 0.5f, 1.0f)); velocity.y = prevy; } else { // Clamp magnitude on the XZ axes float xzmagn = Mathf.Sqrt(velocity.x * velocity.x + velocity.z * velocity.z); xzmagn = maxSpeed / xzmagn; if (xzmagn < 1) { velocity.x *= xzmagn; velocity.z *= xzmagn; //Vector3.ClampMagnitude (velocity, maxSpeed); } } //Debug.DrawLine (tr.position, tg, lastCorner ? Color.red : Color.green); if (endPointIsTarget) { Vector3 trotdir = Vector3.Lerp(velocity, currentTargetDirection, System.Math.Max(1 - magn * 2, 0)); RotateTowards(trotdir); } else { RotateTowards(velocity); } //Applied after rotation to enable proper checks on if velocity is zero velocity += deltaTime * gravity; if (rvoController != null && rvoController.enabled) { //Use RVOController tr.position = position; rvoController.Move(velocity); } else if (controller != null && controller.enabled) { //Use CharacterController tr.position = position; controller.Move(velocity * deltaTime); } else { //Use Transform float lasty = position.y; position += velocity * deltaTime; position = RaycastPosition(position, lasty); tr.position = position; } } else { if (rvoController != null && rvoController.enabled) { //Use RVOController rvoController.Move(Vector3.zero); } } if (pt is RichSpecial) { RichSpecial rs = pt as RichSpecial; if (!traversingSpecialPath) { StartCoroutine(TraverseSpecial(rs)); } } //w.Stop(); //Debug.Log ((w.Elapsed.TotalMilliseconds*1000)); } else { if (rvoController != null && rvoController.enabled) { //Use RVOController rvoController.Move(Vector3.zero); } else if (controller != null && controller.enabled) { } else { tr.position = RaycastPosition(tr.position, tr.position.y); } } }
public override void Apply(Path _p, ModifierData source) { ABPath path = _p as ABPath; if ((path != null) && (path.vectorPath.Count != 0)) { if ((path.vectorPath.Count < 2) && !this.addPoints) { path.vectorPath.Add(path.vectorPath[0]); } VInt3 zero = VInt3.zero; VInt3 point = VInt3.zero; if (this.exactStartPoint == Exactness.Original) { zero = this.GetClampedPoint(path.path[0].position, path.originalStartPoint, path.path[0]); } else if (this.exactStartPoint == Exactness.ClosestOnNode) { zero = this.GetClampedPoint(path.path[0].position, path.startPoint, path.path[0]); } else if (this.exactStartPoint == Exactness.Interpolate) { zero = this.GetClampedPoint(path.path[0].position, path.originalStartPoint, path.path[0]); VInt3 position = path.path[0].position; VInt3 lineEnd = path.path[(1 < path.path.Count) ? 1 : 0].position; zero = AstarMath.NearestPointStrict(ref position, ref lineEnd, ref zero); } else { zero = path.path[0].position; } if (this.exactEndPoint == Exactness.Original) { point = this.GetClampedPoint(path.path[path.path.Count - 1].position, path.originalEndPoint, path.path[path.path.Count - 1]); } else if (this.exactEndPoint == Exactness.ClosestOnNode) { point = this.GetClampedPoint(path.path[path.path.Count - 1].position, path.endPoint, path.path[path.path.Count - 1]); } else if (this.exactEndPoint == Exactness.Interpolate) { point = this.GetClampedPoint(path.path[path.path.Count - 1].position, path.originalEndPoint, path.path[path.path.Count - 1]); VInt3 lineStart = path.path[path.path.Count - 1].position; VInt3 num6 = path.path[((path.path.Count - 2) >= 0) ? (path.path.Count - 2) : 0].position; point = AstarMath.NearestPointStrict(ref lineStart, ref num6, ref point); } else { point = path.path[path.path.Count - 1].position; } if (!this.addPoints) { path.vectorPath[0] = zero; path.vectorPath[path.vectorPath.Count - 1] = point; } else { if (this.exactStartPoint != Exactness.SnapToNode) { path.vectorPath.Insert(0, zero); } if (this.exactEndPoint != Exactness.SnapToNode) { path.vectorPath.Add(point); } } } }
// Token: 0x060006F4 RID: 1780 RVA: 0x00044120 File Offset: 0x00042520 public override void Apply(Path _p, ModifierData source) { ABPath abpath = _p as ABPath; if (abpath == null) { return; } if (abpath.vectorPath.Count == 0) { return; } if (abpath.vectorPath.Count < 2 && !this.addPoints) { abpath.vectorPath.Add(abpath.vectorPath[0]); } Vector3 vector = Vector3.zero; Vector3 vector2 = Vector3.zero; if (this.exactStartPoint == StartEndModifier.Exactness.Original) { vector = this.GetClampedPoint((Vector3)abpath.path[0].position, abpath.originalStartPoint, abpath.path[0]); } else if (this.exactStartPoint == StartEndModifier.Exactness.ClosestOnNode) { vector = this.GetClampedPoint((Vector3)abpath.path[0].position, abpath.startPoint, abpath.path[0]); } else if (this.exactStartPoint == StartEndModifier.Exactness.Interpolate) { vector = this.GetClampedPoint((Vector3)abpath.path[0].position, abpath.originalStartPoint, abpath.path[0]); vector = AstarMath.NearestPointStrict((Vector3)abpath.path[0].position, (Vector3)abpath.path[(1 < abpath.path.Count) ? 1 : 0].position, vector); } else { vector = (Vector3)abpath.path[0].position; } if (this.exactEndPoint == StartEndModifier.Exactness.Original) { vector2 = this.GetClampedPoint((Vector3)abpath.path[abpath.path.Count - 1].position, abpath.originalEndPoint, abpath.path[abpath.path.Count - 1]); } else if (this.exactEndPoint == StartEndModifier.Exactness.ClosestOnNode) { vector2 = this.GetClampedPoint((Vector3)abpath.path[abpath.path.Count - 1].position, abpath.endPoint, abpath.path[abpath.path.Count - 1]); } else if (this.exactEndPoint == StartEndModifier.Exactness.Interpolate) { vector2 = this.GetClampedPoint((Vector3)abpath.path[abpath.path.Count - 1].position, abpath.originalEndPoint, abpath.path[abpath.path.Count - 1]); vector2 = AstarMath.NearestPointStrict((Vector3)abpath.path[abpath.path.Count - 1].position, (Vector3)abpath.path[(abpath.path.Count - 2 >= 0) ? (abpath.path.Count - 2) : 0].position, vector2); } else { vector2 = (Vector3)abpath.path[abpath.path.Count - 1].position; } if (!this.addPoints) { abpath.vectorPath[0] = vector; abpath.vectorPath[abpath.vectorPath.Count - 1] = vector2; } else { if (this.exactStartPoint != StartEndModifier.Exactness.SnapToNode) { abpath.vectorPath.Insert(0, vector); } if (this.exactEndPoint != StartEndModifier.Exactness.SnapToNode) { abpath.vectorPath.Add(vector2); } } }
/*public override void ApplyOriginal (Path p) { * * if (exactStartPoint) { * pStart = GetClampedPoint (p.path[0].position, p.originalStartPoint, p.path[0]); * * if (!addPoints) { * p.startPoint = pStart; * } * } * * if (exactEndPoint) { * pEnd = GetClampedPoint (p.path[p.path.Length-1].position, p.originalEndPoint, p.path[p.path.Length-1]); * * if (!addPoints) { * p.endPoint = pEnd; * } * } * }*/ public override void Apply(Path _p, ModifierData source) { ABPath p = _p as ABPath; //Only for ABPaths if (p == null) { return; } if (p.vectorPath.Count == 0) { return; } else if (p.vectorPath.Count < 2 && !addPoints) { //Vector3[] arr = new Vector3[2]; //arr[0] = p.vectorPath[0]; //arr[1] = p.vectorPath[0]; //p.vectorPath = arr; p.vectorPath.Add(p.vectorPath[0]); } //Debug.DrawRay (p.originalEndPoint,Vector3.up,Color.red); //Debug.DrawRay (p.startPoint,Vector3.up,Color.red); //Debug.DrawRay (p.endPoint,Vector3.up,Color.green); Vector3 pStart = Vector3.zero, pEnd = Vector3.zero; if (exactStartPoint == Exactness.Original) { pStart = GetClampedPoint((Vector3)p.path[0].position, p.originalStartPoint, p.path[0]); } else if (exactStartPoint == Exactness.ClosestOnNode) { pStart = GetClampedPoint((Vector3)p.path[0].position, p.startPoint, p.path[0]); } else if (exactStartPoint == Exactness.Interpolate) { pStart = GetClampedPoint((Vector3)p.path[0].position, p.originalStartPoint, p.path[0]); pStart = AstarMath.NearestPointStrict((Vector3)p.path[0].position, (Vector3)p.path[1 >= p.path.Count?0:1].position, pStart); } else { pStart = (Vector3)p.path[0].position; } if (exactEndPoint == Exactness.Original) { pEnd = GetClampedPoint((Vector3)p.path[p.path.Count - 1].position, p.originalEndPoint, p.path[p.path.Count - 1]); } else if (exactEndPoint == Exactness.ClosestOnNode) { pEnd = GetClampedPoint((Vector3)p.path[p.path.Count - 1].position, p.endPoint, p.path[p.path.Count - 1]); } else if (exactEndPoint == Exactness.Interpolate) { pEnd = GetClampedPoint((Vector3)p.path[p.path.Count - 1].position, p.originalEndPoint, p.path[p.path.Count - 1]); pEnd = AstarMath.NearestPointStrict((Vector3)p.path[p.path.Count - 1].position, (Vector3)p.path[p.path.Count - 2 < 0?0:p.path.Count - 2].position, pEnd); } else { pEnd = (Vector3)p.path[p.path.Count - 1].position; } if (!addPoints) { //p.vectorPath[0] = p.startPoint; //p.vectorPath[p.vectorPath.Length-1] = p.endPoint; //Debug.DrawLine (p.vectorPath[0],pStart,Color.green); //Debug.DrawLine (p.vectorPath[p.vectorPath.Length-1],pEnd,Color.green); p.vectorPath[0] = pStart; p.vectorPath[p.vectorPath.Count - 1] = pEnd; } else { //Vector3[] newPath = new Vector3[p.vectorPath.Length+(exactStartPoint != Exactness.SnapToNode ? 1 : 0) + (exactEndPoint != Exactness.SnapToNode ? 1 : 0)]; if (exactStartPoint != Exactness.SnapToNode) { //newPath[0] = pStart; p.vectorPath.Insert(0, pStart); } if (exactEndPoint != Exactness.SnapToNode) { //newPath[newPath.Length-1] = pEnd; p.vectorPath.Add(pEnd); } /*int offset = exactStartPoint != Exactness.SnapToNode ? 1 : 0; * for (int i=0;i<p.vectorPath.Length;i++) { * newPath[i+offset] = p.vectorPath[i]; * } * p.vectorPath = newPath;*/ } }
public static long DistancePointSegmentStrict(VInt3 a, VInt3 b, VInt3 p) { VInt3 lhs = AstarMath.NearestPointStrict(ref a, ref b, ref p); return((lhs - p).sqrMagnitudeLong); }
public static VInt3 NearestPointStrict(VInt3 lineStart, VInt3 lineEnd, VInt3 point) { return(AstarMath.NearestPointStrict(ref lineStart, ref lineEnd, ref point)); }
public override void Apply(Path _p, ModifierData source) { var p = _p as ABPath; //Only for ABPaths if (p == null) { return; } if (p.vectorPath.Count == 0) { return; } if (p.vectorPath.Count == 1 && !addPoints) { // Duplicate first point p.vectorPath.Add(p.vectorPath[0]); } Vector3 pStart = Vector3.zero; Vector3 pEnd = Vector3.zero; switch (exactStartPoint) { case Exactness.Original: pStart = GetClampedPoint((Vector3)p.path[0].position, p.originalStartPoint, p.path[0]); break; case Exactness.ClosestOnNode: pStart = GetClampedPoint((Vector3)p.path[0].position, p.startPoint, p.path[0]); break; case Exactness.SnapToNode: pStart = (Vector3)p.path[0].position; break; case Exactness.Interpolate: pStart = GetClampedPoint((Vector3)p.path[0].position, p.originalStartPoint, p.path[0]); pStart = AstarMath.NearestPointStrict((Vector3)p.path[0].position, (Vector3)p.path[1 >= p.path.Count?0:1].position, pStart); break; } switch (exactEndPoint) { case Exactness.Original: pEnd = GetClampedPoint((Vector3)p.path[p.path.Count - 1].position, p.originalEndPoint, p.path[p.path.Count - 1]); break; case Exactness.ClosestOnNode: pEnd = GetClampedPoint((Vector3)p.path[p.path.Count - 1].position, p.endPoint, p.path[p.path.Count - 1]); break; case Exactness.SnapToNode: pEnd = (Vector3)p.path[p.path.Count - 1].position; break; case Exactness.Interpolate: pEnd = GetClampedPoint((Vector3)p.path[p.path.Count - 1].position, p.originalEndPoint, p.path[p.path.Count - 1]); pEnd = AstarMath.NearestPointStrict((Vector3)p.path[p.path.Count - 1].position, (Vector3)p.path[p.path.Count - 2 < 0?0:p.path.Count - 2].position, pEnd); break; } if (!addPoints) { p.vectorPath[0] = pStart; p.vectorPath[p.vectorPath.Count - 1] = pEnd; } else { if (exactStartPoint != Exactness.SnapToNode) { p.vectorPath.Insert(0, pStart); } if (exactEndPoint != Exactness.SnapToNode) { p.vectorPath.Add(pEnd); } } }