Exemplo n.º 1
0
		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(
				MathEngine.DegreesToRadians(lon),
				MathEngine.DegreesToRadians(lat),
				MathEngine.DegreesToRadians(heading));

			Point3d v = Quaternion4d.QuaternionToEuler(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);
		}
Exemplo n.º 2
0
        public virtual void RotationYawPitchRoll(Angle yaw, Angle pitch, Angle roll)
        {
            //	this._orientation *= MathEngine.EulerToQuaternion(yaw.Radians, pitch.Radians, roll.Radians);
            //	Vector3 v = MathEngine.QuaternionToEuler(this._orientation);

            //	if(!double.IsNaN(v.Y))
            //		this._latitude.Radians = v.Y;
            //	if(!double.IsNaN(v.X))
            //		this._longitude.Radians = v.X;
            //	if(Math.Abs(roll.Radians)>Single.Epsilon)
            //		this._heading.Radians = v.Z;


            this.m_Orientation = Quaternion4d.EulerToQuaternion(yaw.Radians, pitch.Radians, roll.Radians) * this.m_Orientation;

            Point3d p = Quaternion4d.QuaternionToEuler(this.m_Orientation);

            if (!double.IsNaN(p.Y))
            {
                this._latitude.Radians = p.Y;
            }
            if (!double.IsNaN(p.X))
            {
                this._longitude.Radians = p.X;
            }
            if (Math.Abs(roll.Radians) > double.Epsilon)
            {
                this._heading.Radians = p.Z;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref= "T:WorldWind.Camera.CameraBase"/> class.
 /// </summary>
 /// <param name="radius">Planet's radius in meters</param>
 internal CameraBase(double radius)
 {
     this._worldRadius = radius;
      this._distance = 2 * _worldRadius;
      this._altitude = this._distance;
      maximumAltitude = 20 * _worldRadius;
      this.m_Orientation = Quaternion4d.RotationYawPitchRoll(0, 0, 0);
 }
Exemplo n.º 4
0
		/// <summary>
		/// Initializes a new instance of the <see cref= "T:WorldWind.Camera.WorldCamera"/> class.
		/// </summary>
		/// <param name="targetPosition"></param>
		/// <param name="radius"></param>
		public WorldCamera( Vector3 targetPosition,double radius ) : base( targetPosition, radius ) 
		{
			this._targetOrientation = m_Orientation;
			this._targetDistance = this._distance;
			this._targetAltitude = this._altitude;
			this._targetTilt = this._tilt;
			this._targetFov = this._fov;
		}
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref= "T:WorldWind.WorldCamera"/> class.
 /// </summary>
 /// <param name="targetPosition"></param>
 /// <param name="radius"></param>
 public WorldCamera(Vector3 targetPosition, double radius) : base(targetPosition, radius)
 {
     this._targetOrientation = this.m_Orientation;
     this._targetDistance    = this._distance;
     this._targetAltitude    = this._altitude;
     this._targetTilt        = this._tilt;
     this._targetFov         = this._fov;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref= "T:WorldWind.CameraBase"/> class.
 /// </summary>
 /// <param name="targetPosition"></param>
 /// <param name="radius">Planet's radius in meters</param>
 public CameraBase(Vector3 targetPosition, double radius)
 {
     this._worldRadius = radius;
     this._distance    = 2 * this._worldRadius;
     this._altitude    = this._distance;
     maximumAltitude   = 20 * this._worldRadius;
     //	this._orientation = MathEngine.EulerToQuaternion(0,0,0);
     this.m_Orientation = Quaternion4d.EulerToQuaternion(0, 0, 0);
 }
Exemplo n.º 7
0
		const int DoubleTapDelay = 3000; // Double tap max time (ms)

		/// <summary>
		/// Initializes a new instance of the <see cref= "T:WorldWind.Camera.CameraBase"/> class.
		/// </summary>
		/// <param name="targetPosition"></param>
		/// <param name="radius">Planet's radius in meters</param>
		public CameraBase( Vector3 targetPosition, double radius ) 
		{
			this._worldRadius = radius;
			this._distance = 2*_worldRadius;
			this._altitude = this._distance;
			maximumAltitude = 20 * _worldRadius;
		//	this._orientation = MathEngine.EulerToQuaternion(0,0,0);
			this.m_Orientation = Quaternion4d.EulerToQuaternion(0,0,0);
		}
Exemplo n.º 8
0
 public static Quaternion4d Squad(
     Quaternion4d q1,
     Quaternion4d a,
     Quaternion4d b,
     Quaternion4d c,
     double t)
 {
     return(Slerp(
                Slerp(q1, c, t), Slerp(a, b, t), 2 * t * (1.0 - t)));
 }
Exemplo n.º 9
0
 public override bool Equals(object obj)
 {
     if (obj is Quaternion4d)
     {
         Quaternion4d q = (Quaternion4d)obj;
         return(q == this);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Transforms a rotation in quaternion form to a set of Euler angles
        /// </summary>
        /// <returns>The rotation transformed to Euler angles, X=Yaw, Y=Pitch, Z=Roll (radians)</returns>
        public static Point3d QuaternionToEuler(Quaternion4d q)
        {
            double q0 = q.W;
            double q1 = q.X;
            double q2 = q.Y;
            double q3 = q.Z;

            double x = Math.Atan2(2 * (q2 * q3 + q0 * q1), (q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3));
            double y = Math.Asin(-2 * (q1 * q3 - q0 * q2));
            double z = Math.Atan2(2 * (q1 * q2 + q0 * q3), (q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3));

            return(new Point3d(x, y, z));
        }
Exemplo n.º 11
0
		/// <summary>
		/// Transforms a rotation in quaternion form to a set of Euler angles 
		/// </summary>
		/// <returns>The rotation transformed to Euler angles, X=Yaw, Y=Pitch, Z=Roll (radians)</returns>
		public static Point3d QuaternionToEuler(Quaternion4d q)
		{
			double q0 = q.W;
			double q1 = q.X;
			double q2 = q.Y;
			double q3 = q.Z;

			double x = Math.Atan2( 2 * (q2*q3 + q0*q1), (q0*q0 - q1*q1 - q2*q2 + q3*q3));
			double y = Math.Asin( -2 * (q1*q3 - q0*q2));
			double z = Math.Atan2( 2 * (q1*q2 + q0*q3), (q0*q0 + q1*q1 - q2*q2 - q3*q3));

			return new Point3d(x, y, z);
		}
Exemplo n.º 12
0
        public static Quaternion4d Slerp(Quaternion4d q0, Quaternion4d q1, double t)
        {
            double cosom = q0.X * q1.X + q0.Y * q1.Y + q0.Z * q1.Z + q0.W * q1.W;
            double tmp0, tmp1, tmp2, tmp3;

            if (cosom < 0.0)
            {
                cosom = -cosom;
                tmp0  = -q1.X;
                tmp1  = -q1.Y;
                tmp2  = -q1.Z;
                tmp3  = -q1.W;
            }
            else
            {
                tmp0 = q1.X;
                tmp1 = q1.Y;
                tmp2 = q1.Z;
                tmp3 = q1.W;
            }

            /* calc coeffs */
            double scale0, scale1;

            if ((1.0 - cosom)
                > double.Epsilon)
            {
                // standard case (slerp)
                double omega = Math.Acos(cosom);
                double sinom = Math.Sin(omega);
                scale0 = Math.Sin((1.0 - t) * omega) / sinom;
                scale1 = Math.Sin(t * omega) / sinom;
            }
            else
            {
                /* just lerp */
                scale0 = 1.0 - t;
                scale1 = t;
            }

            Quaternion4d q = new Quaternion4d();

            q.X = scale0 * q0.X + scale1 * tmp0;
            q.Y = scale0 * q0.Y + scale1 * tmp1;
            q.Z = scale0 * q0.Z + scale1 * tmp2;
            q.W = scale0 * q0.W + scale1 * tmp3;

            return(q);
        }
Exemplo n.º 13
0
        public static void SquadSetup(ref Quaternion4d outA, ref Quaternion4d outB, ref Quaternion4d outC, Quaternion4d q0, Quaternion4d q1, Quaternion4d q2, Quaternion4d q3)
        {
            q0 = q0 + q1;
            q0.Normalize();

            q2 = q2 + q1;
            q2.Normalize();

            q3 = q3 + q1;
            q3.Normalize();

            q1.Normalize();

            outA = q1 * Exp(-0.25 * (Ln(Exp(q1) * q2) + Ln(Exp(q1) * q0)));
            outB = q2 * Exp(-0.25 * (Ln(Exp(q2) * q3) + Ln(Exp(q2) * q1)));
            outC = q2;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Pan the camera using delta values
        /// </summary>
        /// <param name="lat">Latitude offset</param>
        /// <param name="lon">Longitude offset</param>
        public override void Pan(Angle lat, Angle lon)
        {
            if (World.Settings.cameraHasMomentum)
            {
                this._latitudeMomentum  += lat / 100;
                this._longitudeMomentum += lon / 100;
            }

            if (Angle.IsNaN(lat))
            {
                lat = this._targetLatitude;
            }
            if (Angle.IsNaN(lon))
            {
                lon = this._targetLongitude;
            }
            lat += this._targetLatitude;
            lon += this._targetLongitude;

            if (Math.Abs(lat.Radians) > Math.PI / 2 - 1e-3)
            {
                lat.Radians = Math.Sign(lat.Radians) * (Math.PI / 2 - 1e-3);
            }

            this._targetOrientation = Quaternion4d.EulerToQuaternion(
                lon.Radians,
                lat.Radians, this._targetHeading.Radians);

            Point3d v = Quaternion4d.QuaternionToEuler(this._targetOrientation);

            if (!double.IsNaN(v.Y))
            {
                this._targetLatitude.Radians  = v.Y;
                this._targetLongitude.Radians = v.X;
                this._targetHeading.Radians   = v.Z;

                if (!World.Settings.cameraSmooth)
                {
                    this._latitude     = this._targetLatitude;
                    this._longitude    = this._targetLongitude;
                    this._heading      = this._targetHeading;
                    this.m_Orientation = this._targetOrientation;
                }
            }
        }
Exemplo n.º 15
0
        public override void RotationYawPitchRoll(Angle yaw, Angle pitch, Angle roll)
        {
            this._targetOrientation = Quaternion4d.EulerToQuaternion(yaw.Radians, pitch.Radians, roll.Radians) * this._targetOrientation;

            Point3d v = Quaternion4d.QuaternionToEuler(this._targetOrientation);

            if (!double.IsNaN(v.Y))
            {
                this._targetLatitude.Radians = v.Y;
            }
            if (!double.IsNaN(v.X))
            {
                this._targetLongitude.Radians = v.X;
            }
            if (Math.Abs(roll.Radians) > double.Epsilon)
            {
                this._targetHeading.Radians = v.Z;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref= "T:WorldWind.World"/> class.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="position"></param>
        /// <param name="orientation"></param>
        /// <param name="equatorialRadius"></param>
        /// <param name="cacheDirectory"></param>
        /// <param name="terrainAccessor"></param>
        public World(string name, Point3d position, Quaternion4d orientation, double equatorialRadius,
            string cacheDirectory,
            TerrainAccessor terrainAccessor)
            : base(name, position, orientation)
        {
            this.equatorialRadius = equatorialRadius;

            this._terrainAccessor = terrainAccessor;
            this._renderableObjects = new RenderableObjectList(this.Name);
            this.MetaData.Add("CacheDirectory", cacheDirectory);

            //	this.m_WorldSurfaceRenderer = new WorldSurfaceRenderer(32, 0, this);
            this.m_projectedVectorRenderer = new ProjectedVectorRenderer("World Default ProjectedVectorRenderer", this);

            m_outerSphere = new AtmosphericScatteringSphere();
            AtmosphericScatteringSphere.m_fInnerRadius = (float)equatorialRadius;
            AtmosphericScatteringSphere.m_fOuterRadius = (float)equatorialRadius * 1.025f;

            m_outerSphere.Init((float)equatorialRadius * 1.025f);
        }
Exemplo n.º 17
0
        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 = this._targetBank.Degrees;
            }

            this._targetOrientation = Quaternion4d.EulerToQuaternion(
                MathEngine.DegreesToRadians(lon),
                MathEngine.DegreesToRadians(lat),
                MathEngine.DegreesToRadians(heading));

            Point3d v = Quaternion4d.QuaternionToEuler(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))
            {
                this.Altitude = _altitude;
            }
            this.Bank = Angle.FromDegrees(bank);
        }
Exemplo n.º 18
0
        //the below functions have not been certified to work properly
        public static Quaternion4d Exp(Quaternion4d q)
        {
            double sinom;
            double om = Math.Sqrt(q.X * q.X + q.Y * q.Y + q.Z * q.Z);

            if (Math.Abs(om) < double.Epsilon)
            {
                sinom = 1.0;
            }
            else
            {
                sinom = Math.Sin(om) / om;
            }

            q.X = q.X * sinom;
            q.Y = q.Y * sinom;
            q.Z = q.Z * sinom;
            q.W = Math.Cos(om);

            return(q);
        }
Exemplo n.º 19
0
        protected void SlerpToTargetOrientation(double percent)
        {
            double c = Quaternion4d.Dot(this.m_Orientation, this._targetOrientation);

            if (c > 1.0)
            {
                c = 1.0;
            }
            else if (c < -1.0)
            {
                c = -1.0;
            }

            this.angle = Angle.FromRadians(Math.Acos(c));

            this.m_Orientation = Quaternion4d.Slerp(this.m_Orientation, this._targetOrientation, percent);

            this._tilt     += (this._targetTilt - this._tilt) * percent;
            this._bank     += (this._targetBank - this._bank) * percent;
            this._distance += (this._targetDistance - this._distance) * percent;
            this.ComputeAltitude(this._distance + this._headZoom, this._tilt + this._headTilt, this._swivel + this._headSwivel);
            this._fov += (this._targetFov - this._fov) * percent;
        }
Exemplo n.º 20
0
        public static Quaternion4d Ln(Quaternion4d q)
        {
            double t = 0;

            double s  = Math.Sqrt(q.X * q.X + q.Y * q.Y + q.Z * q.Z);
            double om = Math.Atan2(s, q.W);

            if (Math.Abs(s) < double.Epsilon)
            {
                t = 0.0f;
            }
            else
            {
                t = om / s;
            }

            q.X = q.X * t;
            q.Y = q.Y * t;
            q.Z = q.Z * t;
            q.W = 0.0f;

            return(q);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Pan the camera using delta values
        /// </summary>
        /// <param name="lat">Latitude offset</param>
        /// <param name="lon">Longitude offset</param>
        public virtual void Pan(Angle lat, Angle lon)
        {
            if (Angle.IsNaN(lat))
            {
                lat = this._latitude;                              // should be zero (PM 2007-05)
            }
            if (Angle.IsNaN(lon))
            {
                lon = this._longitude;
            }
            lat += this._latitude;
            lon += this._longitude;

            //	this._orientation = MathEngine.EulerToQuaternion(
            //		lon.Radians,
            //		lat.Radians,
            //		_heading.Radians);

            this.m_Orientation = Quaternion4d.EulerToQuaternion(
                lon.Radians, lat.Radians, this._heading.Radians);

            Point3d p = Quaternion4d.QuaternionToEuler(this.m_Orientation);

            //	Vector3 v = MathEngine.QuaternionToEuler(this._orientation);
            //	if(!double.IsNaN(v.Y))
            //	{
            //		this._latitude.Radians = v.Y;
            //		this._longitude.Radians = v.X;
            //	}

            if (!double.IsNaN(p.Y))
            {
                this._latitude.Radians  = p.Y;
                this._longitude.Radians = p.X;
            }
        }
Exemplo n.º 22
0
        public override void RotationYawPitchRoll(Angle yaw, Angle pitch, Angle roll)
        {
            if (World.Settings.cameraHasMomentum)
            {
                this._latitudeMomentum  += pitch / 100;
                this._longitudeMomentum += yaw / 100;
                this._headingMomentum   += roll / 100;
            }

            this._targetOrientation = Quaternion4d.EulerToQuaternion(yaw.Radians, pitch.Radians, roll.Radians) * this._targetOrientation;
            Point3d v = Quaternion4d.QuaternionToEuler(this._targetOrientation);

            if (!double.IsNaN(v.Y))
            {
                this._targetLatitude.Radians  = v.Y;
                this._targetLongitude.Radians = v.X;
                if (!World.Settings.cameraTwistLock)
                {
                    this._targetHeading.Radians = v.Z;
                }
            }

            base.RotationYawPitchRoll(yaw, pitch, roll);
        }
Exemplo n.º 23
0
        public static void SquadSetup(ref Quaternion4d outA, ref Quaternion4d outB, ref Quaternion4d outC, Quaternion4d q0, Quaternion4d q1, Quaternion4d q2, Quaternion4d q3)
        {
            q0 = q0 + q1;
            q0.Normalize();

            q2 = q2 + q1;
            q2.Normalize();

            q3 = q3 + q1;
            q3.Normalize();

            q1.Normalize();

            outA = q1*Exp(-0.25*(Ln(Exp(q1)*q2) + Ln(Exp(q1)*q0)));
            outB = q2*Exp(-0.25*(Ln(Exp(q2)*q3) + Ln(Exp(q2)*q1)));
            outC = q2;
        }
Exemplo n.º 24
0
 public static Quaternion4d Squad(Quaternion4d q1, Quaternion4d a, Quaternion4d b, Quaternion4d c, double t)
 {
     return Slerp(Slerp(q1, c, t), Slerp(a, b, t), 2*t*(1.0 - t));
 }
Exemplo n.º 25
0
        public static Quaternion4d Slerp(Quaternion4d q0, Quaternion4d q1, double t)
        {
            double cosom = q0.X*q1.X + q0.Y*q1.Y + q0.Z*q1.Z + q0.W*q1.W;
            double tmp0, tmp1, tmp2, tmp3;
            if (cosom < 0.0) {
                cosom = -cosom;
                tmp0 = -q1.X;
                tmp1 = -q1.Y;
                tmp2 = -q1.Z;
                tmp3 = -q1.W;
            }
            else {
                tmp0 = q1.X;
                tmp1 = q1.Y;
                tmp2 = q1.Z;
                tmp3 = q1.W;
            }

            /* calc coeffs */
            double scale0, scale1;

            if ((1.0 - cosom)
                > double.Epsilon) {
                // standard case (slerp)
                double omega = Math.Acos(cosom);
                double sinom = Math.Sin(omega);
                scale0 = Math.Sin((1.0 - t)*omega)/sinom;
                scale1 = Math.Sin(t*omega)/sinom;
            }
            else {
                /* just lerp */
                scale0 = 1.0 - t;
                scale1 = t;
            }

            Quaternion4d q = new Quaternion4d();

            q.X = scale0*q0.X + scale1*tmp0;
            q.Y = scale0*q0.Y + scale1*tmp1;
            q.Z = scale0*q0.Z + scale1*tmp2;
            q.W = scale0*q0.W + scale1*tmp3;

            return q;
        }
Exemplo n.º 26
0
 public static double Norm2(Quaternion4d q)
 {
     return q.X*q.X + q.Y*q.Y + q.Z*q.Z + q.W*q.W;
 }
Exemplo n.º 27
0
 internal static double Norm(Quaternion4d q)
 {
     return q.X * q.X + q.Y * q.Y + q.Z * q.Z + q.W * q.W;
 }
Exemplo n.º 28
0
 internal bool EpsilonTest(Quaternion4d q)
 {
     if (Math.Abs(q.X - this.X) < Camera.CameraBase.dEpsilonTestValue &&
      Math.Abs(q.Y - this.Y) < Camera.CameraBase.dEpsilonTestValue &&
      Math.Abs(q.Z - this.Z) < Camera.CameraBase.dEpsilonTestValue &&
      Math.Abs(q.W - this.W) < 4.0*Camera.CameraBase.dEpsilonTestValue)
     return true;
      else
     return false;
 }
Exemplo n.º 29
0
        /// <summary>
        /// Pan the camera using delta values
        /// </summary>
        /// <param name="lat">Latitude offset</param>
        /// <param name="lon">Longitude offset</param>
        public virtual void Pan(Angle lat, Angle lon)
        {
            if (Angle.IsNaN(lat)) lat = this._latitude;
             if (Angle.IsNaN(lon)) lon = this._longitude;
             lat += _latitude;
             lon += _longitude;

             //	this._orientation = MathEngine.EulerToQuaternion(
             //		lon.Radians,
             //		lat.Radians,
             //		_heading.Radians);

             m_Orientation = Quaternion4d.RotationYawPitchRoll(
            lon.Radians, lat.Radians, _heading.Radians);

             Point3d p = Quaternion4d.QuaternionToEuler(m_Orientation);

             //	Vector3d v = MathEngine.QuaternionToEuler(this._orientation);
             //	if(!double.IsNaN(v.Y))
             //	{
             //		this._latitude.Radians = v.Y;
             //		this._longitude.Radians = v.X;
             //	}

             if (!double.IsNaN(p.Y))
             {
            _latitude.Radians = p.Y;
            _longitude.Radians = p.X;
             }
        }
Exemplo n.º 30
0
        public virtual void RotationYawPitchRoll(Angle yaw, Angle pitch, Angle roll)
        {
            //	this._orientation *= MathEngine.EulerToQuaternion(yaw.Radians, pitch.Radians, roll.Radians);
             //	Vector3 v = MathEngine.QuaternionToEuler(this._orientation);

             //	if(!double.IsNaN(v.Y))
             //		this._latitude.Radians = v.Y;
             //	if(!double.IsNaN(v.X))
             //		this._longitude.Radians = v.X;
             //	if(Math.Abs(roll.Radians)>Single.Epsilon)
             //		this._heading.Radians = v.Z;

             m_Orientation = Quaternion4d.RotationYawPitchRoll(yaw.Radians, pitch.Radians, roll.Radians) * m_Orientation;

             Point3d p = Quaternion4d.QuaternionToEuler(m_Orientation);
             if (!double.IsNaN(p.Y))
            _latitude.Radians = p.Y;
             if (!double.IsNaN(p.X))
            _longitude.Radians = p.X;
             if (Math.Abs(roll.Radians) > double.Epsilon)
            _heading.Radians = p.Z;
        }
Exemplo n.º 31
0
        /// <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.RotationYawPitchRoll(
            MathEngine.DegreesToRadians(lon),
            MathEngine.DegreesToRadians(lat),
            MathEngine.DegreesToRadians(heading));

             Point3d p = Quaternion4d.QuaternionToEuler(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);
        }
Exemplo n.º 32
0
 public static double Dot(Quaternion4d a, Quaternion4d b)
 {
     return(a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W);
 }
Exemplo n.º 33
0
 public static double Abs(Quaternion4d q)
 {
     return(Math.Sqrt(Norm2(q)));
 }
Exemplo n.º 34
0
 public static double Norm2(Quaternion4d q)
 {
     return(q.X * q.X + q.Y * q.Y + q.Z * q.Z + q.W * q.W);
 }
Exemplo n.º 35
0
 public static double Abs(Quaternion4d q)
 {
     return Math.Sqrt(Norm2(q));
 }
Exemplo n.º 36
0
 public static double Dot(Quaternion4d a, Quaternion4d b)
 {
     return a.X*b.X + a.Y*b.Y + a.Z*b.Z + a.W*b.W;
 }
Exemplo n.º 37
0
		public override void RotationYawPitchRoll(Angle yaw, Angle pitch, Angle roll)
		{
			_targetOrientation = Quaternion4d.EulerToQuaternion(yaw.Radians, pitch.Radians, roll.Radians) * _targetOrientation;
			
			Point3d v = Quaternion4d.QuaternionToEuler(_targetOrientation);
			if(!double.IsNaN(v.Y))
				this._targetLatitude.Radians = v.Y;
			if(!double.IsNaN(v.X))
				this._targetLongitude.Radians = v.X;
			if(Math.Abs(roll.Radians)>double.Epsilon)
				this._targetHeading.Radians = v.Z;
		}
Exemplo n.º 38
0
        public virtual void Update(Device device)
        {
            this.viewPort = device.Viewport;

            Point3d p = Quaternion4d.QuaternionToEuler(this.m_Orientation);

            if (!double.IsNaN(p.Y))
            {
                this._latitude.Radians = p.Y;
            }
            if (!double.IsNaN(p.X))
            {
                this._longitude.Radians = p.X;
            }
            if (!double.IsNaN(p.Z))
            {
                this._heading.Radians = p.Z;
            }

            // Compute matrices
            this.ComputeProjectionMatrix(this.viewPort);
            this.ComputeViewMatrix();
            device.SetTransform(TransformState.Projection, this.m_ProjectionMatrix);
            device.SetTransform(TransformState.View, this.m_ViewMatrix);
            device.SetTransform(TransformState.World, this.m_WorldMatrix);

            this.ViewFrustum.Update(
                Matrix.Multiply(this.m_absoluteWorldMatrix,
                                Matrix.Multiply(this.m_absoluteViewMatrix, this.m_absoluteProjectionMatrix)));

            // Old view range (used in quadtile logic)
            double factor = (this._altitude) / this._worldRadius;

            if (factor > 1)
            {
                this.viewRange = Angle.FromRadians(Math.PI);
            }
            else
            {
                this.viewRange = Angle.FromRadians(Math.Abs(Math.Asin((this._altitude) / this._worldRadius)) * 2);
            }

            // True view range
            if (factor < 1)
            {
                this.trueViewRange = Angle.FromRadians(Math.Abs(Math.Asin((this._distance + this._headZoom) / this._worldRadius)) * 2);
            }
            else
            {
                this.trueViewRange = Angle.FromRadians(Math.PI);
            }

            World.Settings.cameraAltitudeMeters = this.Altitude;
            World.Settings.cameraLatitude       = this._latitude;
            World.Settings.cameraLongitude      = this._longitude;
            World.Settings.cameraHeading        = this._heading;
            World.Settings.cameraTilt           = this._tilt;
            World.Settings.cameraSwivel         = this._swivel;

            if (World.Settings.cameraHeadTracking != this._headTracking)
            {
                this._headTracking = World.Settings.cameraHeadTracking;

                if (!this._headTracking)
                {
                    this._headTilt   = Angle.Zero;
                    this._headSwivel = Angle.Zero;
                    this._headZoom   = 0.0;
                    World.Settings.cameraHeadTilt   = this._headTilt;
                    World.Settings.cameraHeadSwivel = this._headSwivel;
                    World.Settings.cameraHeadZoom   = this._headZoom;
                }
            }

            if (this._headTracking)
            {
                World.Settings.cameraHeadTilt   = this._headTilt;
                World.Settings.cameraHeadSwivel = this._headSwivel;
                World.Settings.cameraHeadZoom   = this._headZoom;
            }
        }
Exemplo n.º 39
0
        //the below functions have not been certified to work properly
        public static Quaternion4d Exp(Quaternion4d q)
        {
            double sinom;
            double om = Math.Sqrt(q.X*q.X + q.Y*q.Y + q.Z*q.Z);

            if (Math.Abs(om)
                < double.Epsilon) {
                sinom = 1.0;
            }
            else {
                sinom = Math.Sin(om)/om;
            }

            q.X = q.X*sinom;
            q.Y = q.Y*sinom;
            q.Z = q.Z*sinom;
            q.W = Math.Cos(om);

            return q;
        }
Exemplo n.º 40
0
 internal static double Abs(Quaternion4d q)
 {
     return Math.Sqrt(Norm(q));
 }
Exemplo n.º 41
0
        public static Quaternion4d Ln(Quaternion4d q)
        {
            double t = 0;

            double s = Math.Sqrt(q.X*q.X + q.Y*q.Y + q.Z*q.Z);
            double om = Math.Atan2(s, q.W);

            if (Math.Abs(s)
                < double.Epsilon) {
                t = 0.0f;
            }
            else {
                t = om/s;
            }

            q.X = q.X*t;
            q.Y = q.Y*t;
            q.Z = q.Z*t;
            q.W = 0.0f;

            return q;
        }