private float3 GetWorldPosition(int index, float fractionAlongPath) { float3 p0, p1, p2, p3; GetSplineSectionInternal(index, out p0, out p1, out p2, out p3); return(CatmullRom.GetPosition(p0, p1, p2, p3, fractionAlongPath) + new float3(transform.position)); }
private void CatmullRomTest(MyVector3 posA, MyVector3 posB, MyVector3 handleA, MyVector3 handleB) { CatmullRom catmullRomCurve = new CatmullRom(posA, posB, handleA, handleB); //Store the interpolated values so we later can display them List <Vector3> positions = new List <Vector3>(); List <Vector3> tangents = new List <Vector3>(); List <float> tValues = new List <float>(); //Loop between 0 and 1 in steps, where 1 step is minimum //So if steps is 5 then the line will be cut in 5 sections int steps = 5; float stepSize = 1f / (float)steps; float t = 0f; //+1 becuase wa also have to include the first point for (int i = 0; i < steps + 1; i++) { //Debug.Log(t); MyVector3 interpolatedPos = CatmullRom.GetPosition(posA, posB, handleA, handleB, t); positions.Add(interpolatedPos.ToVector3()); MyVector3 interpolatedTangent = CatmullRom.GetTangent(posA, posB, handleA, handleB, t); tangents.Add(interpolatedTangent.ToVector3()); tValues.Add(t); t += stepSize; } List <InterpolationTransform> transforms = InterpolationTransform.GetTransforms_RotationMinimisingFrame(catmullRomCurve, tValues, MyVector3.Up); //Display //DisplayInterpolation.DisplayCurve(positions, useRandomColor: true); DisplayInterpolation.DisplayCurve(positions, Color.black); //The actual curve for comparison DisplayInterpolation.DisplayCurve(catmullRomCurve, Color.gray); //The control points //The start and end values and the handle points DisplayInterpolation.DisplayHandle(handleA.ToVector3(), posA.ToVector3()); DisplayInterpolation.DisplayHandle(handleB.ToVector3(), posB.ToVector3()); //Other stuff //DisplayInterpolation.DisplayDirections(positions, tangents, 1f, Color.blue); DisplayInterpolation.DisplayOrientations(transforms, 1f); }
public void Execute(ref VehiclePathing p, ref VehicleTargetPosition pos, [ReadOnly] ref VehiclePhysicsState physicsState) { var rs = RoadSections[p.RoadIndex]; float3 c0 = CatmullRom.GetPosition(rs.p0, rs.p1, rs.p2, rs.p3, p.curvePos); float3 c1 = CatmullRom.GetTangent(rs.p0, rs.p1, rs.p2, rs.p3, p.curvePos); float3 c2 = CatmullRom.GetConcavity(rs.p0, rs.p1, rs.p2, rs.p3, p.curvePos); float curveSpeed = length(c1); pos.IdealPosition = c0; pos.IdealSpeed = p.speed; if (lengthsq(physicsState.Position - c0) < kMaxTetherSquared) { p.curvePos += Constants.VehicleSpeedFudge / rs.arcLength * p.speed / curveSpeed * DeltaTimeSeconds; } }