public override void Update(GameTime gameTime) { // momentanten Zeitpunkt aktualisieren current += (float)gameTime.ElapsedGameTime.TotalSeconds; // maximalen Zeitpunkt der Waypoints ermitteln total = Waypoints.Last().Item3; // wenn aktueller Zeitpunkt größer dem Maximum -> bei 0 beginnen if (current > total) { current = current % total; } // aktuellen Waypoint ermitteln int index = GetWaypointIndex(current); Waypoint last = GetWaypoint(index - 1); Waypoint begin = GetWaypoint(index); Waypoint end = GetWaypoint(index + 1); // Start- und End-Tangente ermitteln Vector3 beginTangent = GetTangent(index, Tension, Bias, Continuity); Vector3 endTangent = GetTangent(index + 1, Tension, Bias, -Continuity); float t0 = last.Item3; float t1 = begin.Item3; // wenn vorangegangener Wegpunkt der letzte war, Zeitpunkt für Interpolation anpassen if (t0 > t1) { t0 -= total; } // Verhältnis von aktuellem Zeitpunkt zu Zeitspanne zw. zwei Wegpunkten berechnen float amount = (current - t0) / (t1 - t0); // Position zwischen Wegpunkten mit Kochanek-Bartels interpolieren Camera.Position = Vector3.Hermite(begin.Item1, beginTangent, end.Item1, endTangent, amount); // Camera-LookAt Vektor mit Quaternion Slerp interpolieren Camera.Look(Vector3.Transform(Vector3.Forward, Quaternion.Slerp(begin.Item2, end.Item2, amount))); //Camera.LookAt(Vector3.Up); base.Update(gameTime); }
public override void Update(GameTime gameTime) { current += (float)gameTime.ElapsedGameTime.TotalSeconds; total = Waypoints.Last().Item3; if (current > total) { current = current % total; } int index = GetWaypointIndex(current); Waypoint last = GetWaypoint(index - 1); Waypoint begin = GetWaypoint(index); Waypoint end = GetWaypoint(index + 1); Vector3 beginTangent = GetTangent(index, Tension, Bias, Continuity); Vector3 endTangent = GetTangent(index + 1, Tension, Bias, -Continuity); float t0 = last.Item3; float t1 = begin.Item3; if (t0 > t1) { t0 -= total; } float amount = (current - t0) / (t1 - t0); Camera.Position = Vector3.Hermite(begin.Item1, beginTangent, end.Item1, endTangent, amount); Camera.Look(Vector3.Transform(Vector3.Forward, Quaternion.Slerp(begin.Item2, end.Item2, amount))); //Camera.LookAt(Vector3.Up); base.Update(gameTime); }