internal static void UpdateCamera(Train Train, int Car)
{
int i = Car;
int j = Train.DriverCar;
double dx = Train.Cars[i].FrontAxle.Follower.WorldPosition.X - Train.Cars[i].RearAxle.Follower.WorldPosition.X;
double dy = Train.Cars[i].FrontAxle.Follower.WorldPosition.Y - Train.Cars[i].RearAxle.Follower.WorldPosition.Y;
double dz = Train.Cars[i].FrontAxle.Follower.WorldPosition.Z - Train.Cars[i].RearAxle.Follower.WorldPosition.Z;
double t = 1.0 / Math.Sqrt(dx * dx + dy * dy + dz * dz);
dx *= t; dy *= t; dz *= t;
double ux = Train.Cars[i].Up.X;
double uy = Train.Cars[i].Up.Y;
double uz = Train.Cars[i].Up.Z;
double sx = dz * uy - dy * uz;
double sy = dx * uz - dz * ux;
double sz = dy * ux - dx * uy;
double rx = 0.5 * (Train.Cars[i].FrontAxle.Follower.WorldPosition.X + Train.Cars[i].RearAxle.Follower.WorldPosition.X);
double ry = 0.5 * (Train.Cars[i].FrontAxle.Follower.WorldPosition.Y + Train.Cars[i].RearAxle.Follower.WorldPosition.Y);
double rz = 0.5 * (Train.Cars[i].FrontAxle.Follower.WorldPosition.Z + Train.Cars[i].RearAxle.Follower.WorldPosition.Z);
double cx = rx + sx * Train.Cars[j].DriverX + ux * Train.Cars[j].DriverY + dx * Train.Cars[j].DriverZ;
double cy = ry + sy * Train.Cars[j].DriverX + uy * Train.Cars[j].DriverY + dy * Train.Cars[j].DriverZ;
double cz = rz + sz * Train.Cars[j].DriverX + uz * Train.Cars[j].DriverY + dz * Train.Cars[j].DriverZ;
World.CameraTrackFollower.WorldPosition = new Vector3(cx, cy, cz);
World.CameraTrackFollower.WorldDirection = new Vector3(dx, dy, dz);
World.CameraTrackFollower.WorldUp = new Vector3(ux, uy, uz);
World.CameraTrackFollower.WorldSide = new Vector3(sx, sy, sz);
double f = (Train.Cars[i].DriverZ - Train.Cars[i].RearAxlePosition) / (Train.Cars[i].FrontAxlePosition - Train.Cars[i].RearAxlePosition);
double tp = (1.0 - f) * Train.Cars[i].RearAxle.Follower.TrackPosition + f * Train.Cars[i].FrontAxle.Follower.TrackPosition;
TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, tp, false, false);
}