public virtual void ComputeViewMatrix() { double lat1 = _latitude.Degrees; double lon1 = _longitude.Degrees; EyeDiff.X = SMath.DegreesToRadians(_latitude.Degrees - lat1); EyeDiff.Y = SMath.DegreesToRadians(_longitude.Degrees - lon1); ReferenceCenter = SMath.SphericalToCartesianV3D( _latitude.Degrees, _longitude.Degrees, WorldRadius); if (World.Settings.Project == Projection.OrthoGraghics) { //lat1 = 0; //lon1 = 0; EyeDiff.X = 0; EyeDiff.Y = 0; } Vector3d defaultPosition = SMath.SphericalToCartesianV3D(lat1, lon1, _worldRadius); m_ViewMatrix = Matrix4d.LookAtRH( defaultPosition, Vector3d.Empty, cameraUpVector); //TODO JHJ 这是干什么的 有什么用 m_ViewMatrix *= Matrix4d.Translation(0, 0, _worldRadius); m_ViewMatrix *= Matrix4d.RotationYawPitchRoll(-EyeDiff.Y, EyeDiff.X, 0); m_ViewMatrix *= Matrix4d.Translation(0, 0, -_worldRadius); m_ViewMatrix *= Matrix4d.RotationYawPitchRoll( 0, -_tilt.Radians, this._heading.Radians); m_ViewMatrix *= Matrix4d.Translation(0, 0, (-this._distance)); if (World.Settings.Project == Projection.Perspective) { m_ViewMatrix *= Matrix4d.RotationZ(this._bank.Radians); } else { m_ViewMatrix *= Matrix4d.RotationZ(this._bank.Radians); } // Extract camera position Matrix4d cam = Matrix4d.Invert(m_ViewMatrix); _position = new Vector3d(cam[3, 0], cam[3, 1], cam[3, 2]); }
public static Vector3d GetGeocentricPosition(System.DateTime utcDateTime) { if (World.Settings.SunSynchedWithTime) { // Sun synched with time and date double JD = getJulianDay(utcDateTime); double T = (JD - 2451545.0) / 36525; // number of Julian centuries since Jan 1, 2000, 12 UT double k = Math.PI / 180.0; double M = 357.52910 + 35999.05030 * T - 0.0001559 * T * T - 0.00000048 * T * T * T; // mean anomaly, degree double L0 = 280.46645 + 36000.76983 * T + 0.0003032 * T * T; // mean longitude, degree double DL = (1.914600 - 0.004817 * T - 0.000014 * T * T) * Math.Sin(k * M) + (0.019993 - 0.000101 * T) * Math.Sin(k * 2 * M) + 0.000290 * Math.Sin(k * 3 * M); double L = L0 + DL; // true longitude, degree L = L % 360; // obliquity eps of ecliptic: double eps = 23.0 + 26.0 / 60.0 + 21.448 / 3600.0 - (46.8150 * T + 0.00059 * T * T - 0.001813 * T * T * T) / 3600; double X = Math.Cos(k * L); double Y = Math.Cos(k * eps) * Math.Sin(k * L); double Z = Math.Sin(k * eps) * Math.Sin(k * L); double R = Math.Sqrt(1.0 - Z * Z); double dec = (180 / Math.PI) * Math.Atan(Z / R); // in degrees double RA = (24 / Math.PI) * Math.Atan(Y / (X + R)); // in hours double theta0 = 280.46061837 + 360.98564736629 * (JD - 2451545.0) + 0.000387933 * T * T - T * T * T / 38710000.0; // Greenwich Sidereal Time theta0 = theta0 % 360; RA *= 15; // convert from hours to degrees double tau = theta0 - RA; Vector3d pos = SMath.SphericalToCartesianV3D( -dec, -(tau - 180), 1); return(pos); } else { // Fixed sun heading and elevation double worldRadius = 6378137; // Earth meter Vector3 position = SMath.SphericalToCartesian(DrawArgs.Instance.WorldCamera.Latitude.Degrees, DrawArgs.Instance.WorldCamera.Longitude.Degrees, worldRadius); return(GetGeocentricPosition(position, Angle.FromRadians(World.Settings.SunHeading), Angle.FromRadians(World.Settings.SunElevation), World.Settings.SunDistance)); } }
public void Update(double south, double north, double west, double east, double radius1, double radius2) { double scale = radius2 / radius1; SMath.SphericalToCartesianV3D(south, west, radius1, ref this.corners[0]); this.corners[1] = this.corners[0]; this.corners[1].scale(scale); SMath.SphericalToCartesianV3D(south, east, radius1, ref this.corners[2]); this.corners[3] = this.corners[2]; this.corners[3].scale(scale); SMath.SphericalToCartesianV3D(north, west, radius1, ref this.corners[4]); this.corners[5] = this.corners[4]; this.corners[5].scale(scale); SMath.SphericalToCartesianV3D(north, east, radius1, ref this.corners[6]); this.corners[7] = this.corners[6]; this.corners[7].scale(scale); ComputeBoundSphere(); }