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]); }
/// <summary> /// Sets camera position. /// </summary> /// <param name="lat">Latitude in decimal degrees</param> /// <param name="lon">Longitude in decimal degrees</param> /// <param name="heading">Heading in decimal degrees</param> /// <param name="_altitude">Altitude above ground level in meters</param> /// <param name="tilt">Tilt in decimal degrees</param> /// <param name="bank">Camera bank (roll) in decimal degrees</param> public virtual void SetPosition(double lat, double lon, double heading, double _altitude, double tilt, double bank) { if (double.IsNaN(lat)) { lat = this._latitude.Degrees; } if (double.IsNaN(lon)) { lon = this._longitude.Degrees; } if (double.IsNaN(heading)) { heading = this._heading.Degrees; } if (double.IsNaN(bank)) { bank = this._bank.Degrees; } m_Orientation = Quaternion4d.EulerToQuaternion( SMath.DegreesToRadians(lon), SMath.DegreesToRadians(lat), SMath.DegreesToRadians(heading)); Vector3d p = Quaternion4d.QuaternionToEulerV3D(m_Orientation); _latitude.Radians = p.Y; _longitude.Radians = p.X; _heading.Radians = p.Z; if (!double.IsNaN(tilt)) { Tilt = Angle.FromDegrees(tilt); } if (!double.IsNaN(_altitude)) { this.Altitude = _altitude; } this.Bank = Angle.FromDegrees(bank); }
public override void SetPosition(double lat, double lon, double heading, double _altitude, double tilt, double bank) { if (double.IsNaN(lat)) { lat = this._latitude.Degrees; } if (double.IsNaN(lon)) { lon = this._longitude.Degrees; } if (double.IsNaN(heading)) { heading = this._heading.Degrees; } if (double.IsNaN(bank)) { bank = _targetBank.Degrees; } this._targetOrientation = Quaternion4d.EulerToQuaternion( SMath.DegreesToRadians(lon), SMath.DegreesToRadians(lat), SMath.DegreesToRadians(heading)); Vector3d v = Quaternion4d.QuaternionToEulerV3D(this._targetOrientation); this._targetLatitude.Radians = v.Y; this._targetLongitude.Radians = v.X; this._targetHeading.Radians = v.Z; if (!double.IsNaN(tilt)) { this.Tilt = Angle.FromDegrees(tilt); } if (!double.IsNaN(_altitude)) { Altitude = _altitude; } this.Bank = Angle.FromDegrees(bank); }
private void InitWorld() { Vector3 v = SMath.SphericalToCartesian(startlatitude, startlongitude, World.EarthRadius); v.Z = (float)startAltitude * 1.0f; Quaternion4d q = Quaternion4d.EulerToQuaternion(SMath.DegreesToRadians(startlongitude), SMath.DegreesToRadians(startlatitude), 0); Quaternion qz = Quaternion.RotationAxis(new Vector3(0, 0, 1), (float)SMath.DegreesToRadians(startlatitude)); //q.W = qz.W; //q.X = qz.X; //q.Y = qz.Y; //q.Z = qz.Z; //TerrainTileService terrainTileService = new TerrainTileService("http://worldwind25.arc.nasa.gov/tile/tile.aspx", "100", 20, 150, "bil", 8, Path.Combine(EarthSetting.CachePath, "Earth\\TerrainAccessor\\SRTM")); TerrainTileService terrainTileService = new TerrainTileService("http://worldwind25.arc.nasa.gov/tile/tile.aspx", "100", 1, 150, "bil", 6, @"D:\空间数据\重庆H48\bil29107"); TerrainAccessor terrainAccessor = new NltTerrainAccessor("Earth", -180, -90, 180, 90, terrainTileService, null); World _world = new World("Earth", new Vector3d(0, 0, 0), q, this.worldViewer1, terrainAccessor); this.worldViewer1.CurrentWorld = _world; this.worldViewer1.ResetSize(); }