public void Update(float interpolationParameter) { var pos = CubicHermiteSpline.CatmullRomSplineLoop(wayPoints, interpolationParameter); movingObject.MinX = pos.X; movingObject.MinY = pos.Y; }
static public CubicHermiteSpline FromFile(string filename) { string[] data; try { data = File.ReadAllLines(filename); } catch { Console.WriteLine($"ERROR! Failed to open file {filename}"); return(null); } CubicHermiteSpline spline = new CubicHermiteSpline(); int count = int.Parse(data[0], NumberStyles.Any); spline.count = count; spline.args = new double[count]; spline.values = new double[count]; spline.derivatives = new double[count]; for (int i = 0; i < count; i++) { string[] tokens = data[i + 1].Split(' ', StringSplitOptions.RemoveEmptyEntries); double arg = double.Parse(tokens[1], NumberStyles.Any, CultureInfo.InvariantCulture); double value = double.Parse(tokens[0], NumberStyles.Any, CultureInfo.InvariantCulture); spline.args[i] = arg; spline.values[i] = value; } spline.CalculateDerivatives(); return(spline); }
public void Render(IReadOnlyList <Vector2> points, int selectedPoint, float truckPos) { GL.Clear(ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); GL.Ortho(-windowAspect, windowAspect, -1, 1, 0, 1); shaderRoad.Activate(); texSand.Activate(); DrawLineStrip(points); texSand.Deactivate(); shaderRoad.Deactivate(); GL.Color3(Color.Red); GL.PointSize(15.0f); DrawPoints(points); if (-1 != selectedPoint) { GL.Color3(Color.Blue); GL.PointSize(25.0f); DrawPoint(points[selectedPoint]); } var pos = CubicHermiteSpline.CatmullRomSpline(points, truckPos); GL.Color3(Color.White); //GL.Color3(Color.Green); //GL.PointSize(25.0f); shaderTruck.Activate(); texTruck.Activate(); DrawTools.DrawTexturedRect(Box2DExtensions.CreateFromCenterSize(pos.X, pos.Y, 0.1f, 0.1f), Box2D.BOX01); texTruck.Deactivate(); shaderTruck.Deactivate(); //DrawPoint(pos); }