Example #1
0
        public virtual void ResetCacheForCurrentView(WorldWind.Camera.CameraBase camera)
        {
            //                      if (!ImageStore.IsDownloadableLayer)
            //                              return;

            ArrayList deletionList = new ArrayList();

            //reset "root" tiles that intersect current view
            lock (m_topmostTiles.SyncRoot)
            {
                foreach (long key in m_topmostTiles.Keys)
                {
                    QuadTile qt = (QuadTile)m_topmostTiles[key];
                    if (camera.ViewFrustum.Intersects(qt.BoundingBox))
                    {
                        qt.ResetCache();
                        deletionList.Add(key);
                    }
                }

                foreach (long deletionKey in deletionList)
                {
                    m_topmostTiles.Remove(deletionKey);
                }
            }
        }
Example #2
0
		/// <summary>
		/// Construct a new worldwind uri from camera position.
		/// </summary>
		public WorldWindUri(string worldName, CameraBase camera )
		{
			_world = worldName;
			_latitude=camera.Latitude;
			_longitude=camera.Longitude;
			_altitude=camera.Altitude;
			if (Math.Abs(camera.Heading.Degrees)>0.1)
				_direction = camera.Heading;
			if (Math.Abs(camera.Tilt.Degrees)>0.1)
				_tilt = camera.Tilt;
			if (Math.Abs(camera.Bank.Degrees)>0.1)
				_bank = camera.Bank;
		}
Example #3
0
		/// <summary>
		/// Calculate the screen area (pixels) covered by the bottom of the bounding box.
		/// </summary>
		public float CalcRelativeScreenArea(CameraBase camera)
		{
			Vector3 a = camera.Project(corners[0]);
			Vector3 b = camera.Project(corners[2]);
			Vector3 c = camera.Project(corners[6]);
			Vector3 d = camera.Project(corners[4]);

			Vector3 ab = Vector3.Subtract(b,a);
			Vector3 ac = Vector3.Subtract(c,a);
			Vector3 ad = Vector3.Subtract(d,a);

			float tri1SqArea = Vector3.Cross(ab,ac).LengthSq(); 
			float tri2SqArea = Vector3.Cross(ad,ac).LengthSq(); 
			// Real area = (sqrt(tri1SqArea)+sqrt(tri2SqArea))/2 but we're only interested in relative size
			return tri1SqArea + tri2SqArea; 
		}
Example #4
0
        public virtual void AddToDownloadQueue(CameraBase camera, GeoSpatialDownloadRequest newRequest)
        {
            QuadTile key = newRequest.QuadTile;
            key.WaitingForDownload = true;
            lock (m_downloadRequests.SyncRoot)
            {
                if (m_downloadRequests.Contains(key))
                    return;

                m_downloadRequests.Add(key, newRequest);

                if (m_downloadRequests.Count >= m_maxQueueSize)
                {
                    //remove spatially farthest request
                    GeoSpatialDownloadRequest farthestRequest = null;
                    Angle curDistance = Angle.Zero;
                    Angle farthestDistance = Angle.Zero;
                    foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values)
                    {
                        curDistance = MathEngine.SphericalDistance(
                                        curRequest.QuadTile.CenterLatitude,
                                        curRequest.QuadTile.CenterLongitude,
                                        camera.Latitude,
                                        camera.Longitude);

                        if (curDistance > farthestDistance)
                        {
                            farthestRequest = curRequest;
                            farthestDistance = curDistance;
                        }
                    }

                    farthestRequest.Dispose();
                    farthestRequest.QuadTile.DownloadRequest = null;
                    m_downloadRequests.Remove(farthestRequest.QuadTile);
                }
            }

            ServiceDownloadQueue();
        }
Example #5
0
        protected void RemoveInvisibleTiles(CameraBase camera)
        {
            ArrayList deletionList = new ArrayList();

            lock (m_topmostTiles.SyncRoot)
            {
                foreach (long key in m_topmostTiles.Keys)
                {
                    QuadTile qt = (QuadTile)m_topmostTiles[key];
                    if (!camera.ViewFrustum.Intersects(qt.BoundingBox))
                        deletionList.Add(key);
                }

                foreach (long deleteThis in deletionList)
                {
                    QuadTile qt = (QuadTile)m_topmostTiles[deleteThis];
                    if (qt != null)
                    {
                        m_topmostTiles.Remove(deleteThis);
                        qt.Dispose();
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// used as delegate for the "Object Mode" -axis mapping, moving the earth
        /// </summary>
        private static void ObjectMode()
        {
            long delta = 1;
            if (s_stopWatch.IsRunning)
            {
                delta = s_stopWatch.ElapsedMilliseconds;

                //ToDo: remove following two lines;
                //just a performance improvement for 3DxWare Version < 6.1.8.
                if (delta < s_TheSensor.Period)
                    return;

                s_stopWatch.Stop();

                if (delta > (10 * s_TheSensor.Period))
                    return;
            }

            //get data from the Input Device
            TDconnexion.C3DxVector TranslVector = s_TheSensor.Translation as TDconnexion.C3DxVector;
            TDconnexion.C3DxRotation AngleAxis = s_TheSensor.Rotation as TDconnexion.C3DxRotation;

            double dNormTime = (double)delta / s_TheSensor.Period;
            TranslVector *= dNormTime;
            AngleAxis *= dNormTime;

            //0- event sent when cap released
            if ((AngleAxis.Angle == 0)
                && (TranslVector.X == 0)
                && (TranslVector.Y == 0)
                && (TranslVector.Z == 0)
                )
            {
                s_stopWatch.Stop();
                return;
            }
            s_TheCamera = s_WW.DrawArgs.WorldCamera;
            //set CameraSmooth to false to disable movement after releasing the cap
            bool bBackUpSmooth = World.Settings.CameraSmooth;
            World.Settings.CameraSmooth = false;

            //// Tilt////////////////////////////
            s_TheCamera.Tilt -= Angle.FromRadians(AngleAxis.X * AngleAxis.Angle * WorldSettings.CameraRotationSpeed / NormTilt);

            //// Heading/////////////////////////
            double dHeading = -AngleAxis.Y * AngleAxis.Angle * WorldSettings.CameraRotationSpeed / NormHeading;

            //// Distance///////////////////////
            s_TheCamera.TargetDistance *= (1 + TranslVector.Y / NormDistance);

            double factor = (s_TheCamera.Altitude) / (-NormLatLon * s_WW.CurrentWorld.EquatorialRadius);

             Quaternion4d Orientation
                = Quaternion4d.RotationYawPitchRoll(s_TheCamera.Longitude.Radians + (TranslVector.X * factor)
                                                 , s_TheCamera.Latitude.Radians + (TranslVector.Z * factor)
                                                 , dHeading);

             s_TheCamera.CurrentOrientation = Orientation;
             s_Position = Quaternion4d.QuaternionToEuler(Orientation);

             s_WW.SetViewPosition(Angle.FromRadians(s_Position.Y).Degrees
                                      , Angle.FromRadians(s_Position.X).Degrees
                                      , s_TheCamera.Altitude);

            World.Settings.CameraSmooth = bBackUpSmooth;

            s_stopWatch.Reset();
            s_stopWatch.Start();
        }
Example #7
0
        /// <summary>
        /// used as delegate for the "Camera Mode" -axis mapping, moving the Camera/Yourself
        /// </summary>
        private static void CameraMode()
        {
            long delta = 1;
            if (s_stopWatch.IsRunning)
            {
                delta = s_stopWatch.ElapsedMilliseconds;

                //ToDo: remove just a performance improvement for 3DxWare Version < 6.1.8
                if (delta < s_TheSensor.Period)
                    return;

                s_stopWatch.Stop();

                if (delta > (10 * s_TheSensor.Period))
                    return;
                //Console.WriteLine(delta.ToString());
                //Debug.Print(delta.ToString());
            }

            //get data from the Input Device
            TDconnexion.C3DxVector TranslVector = s_TheSensor.Translation as TDconnexion.C3DxVector;
            TDconnexion.C3DxRotation AngleAxis = s_TheSensor.Rotation as TDconnexion.C3DxRotation;

            double dNormTime = (double)delta / s_TheSensor.Period;
            TranslVector *= dNormTime;
            AngleAxis *= dNormTime;

            //0- event sent when cap released
            if ((AngleAxis.Angle == 0)
                && (TranslVector.X == 0)
                && (TranslVector.Y == 0)
                && (TranslVector.Z == 0)
                )
            {
                s_dLastHeight = s_TheCamera.Altitude;
                s_dDeltaHeight = 0;
                s_stopWatch.Stop();
                return;
            }

            s_TheCamera = s_WW.DrawArgs.WorldCamera;

            //set CameraSmooth to false to disable movement after releasing the cap
            bool bBackUpSmooth = World.Settings.CameraSmooth;
            World.Settings.CameraSmooth = false;

            //variables to move the earth via Quaternion4d
            double dRadius = s_TheCamera.WorldRadius;
            double dAltitude = s_TheCamera.Altitude;         //height above sealevel of the camera
            Angle rTilt = s_TheCamera.Tilt;                  //angle between line [center of earth ... crosshairs] and line [crosshairs ... camera]
            double dDeltaLatitude = 0;                       //change of Latitude
            double dDeltaLongitude = 0;                      //change of Longitude
            double dSinus = Math.Sin(rTilt.Radians);
            double dLength = dAltitude + dRadius;            //distance earth center - camera
            double dSinusLaw = dSinus / dLength;               //const of law of sines
            double dAlpha = rTilt.Radians - Math.Asin(dRadius * dSinusLaw); //angle between crosshairs and intersection of line [camera ... center of earth] and earth- face

            //////////////////////////////////////////////////////////////////////////////
            /// Tilt, camera position == center of rotation -> adjust latitude/distance///
            //////////////////////////////////////////////////////////////////////////////
            double dDeltaTiltRad = AngleAxis.X * AngleAxis.Angle * WorldSettings.CameraRotationSpeed / NormTilt; //150000.0;
            if (Math.Abs(dDeltaTiltRad) > double.Epsilon)
            {
                rTilt += Angle.FromRadians(dDeltaTiltRad);
                if (rTilt.Degrees > 85.0)
                    rTilt.Degrees = 85.0;

                if (Math.Abs(rTilt.Radians) > double.Epsilon)
                {
                    dSinus = Math.Sin(rTilt.Radians);
                    dSinusLaw = dSinus / dLength;
                    dDeltaLatitude = -dAlpha;
                    dAlpha = rTilt.Radians - Math.Asin(dRadius * dSinusLaw); // == dAlpha after Tilt
                    dDeltaLatitude += dAlpha;
                }
            }

            ///////////////////////////////////////////////////////////////////////////////////////
            /// Camera height: change Distance and Position (Tilt != 0) in order to move radial ///
            ///////////////////////////////////////////////////////////////////////////////////////
            bool bPosOK = false;
            if (s_dDeltaHeight < -double.Epsilon)
            {
                if (dAltitude < (s_dLastHeight + (s_dDeltaHeight * 0.5)))
                    bPosOK = true;
            }
            else if (s_dDeltaHeight > double.Epsilon)
            {
                if (dAltitude > (s_dLastHeight + (s_dDeltaHeight * 0.5)))
                    bPosOK = true;
            }
            else
                bPosOK = true;

            s_dLastHeight = dAltitude;
            s_dDeltaHeight = TranslVector.Z * dAltitude / NormDistance; //50000.0;

            if (Math.Abs(dSinus) > double.Epsilon)
            {
                dAltitude += s_dDeltaHeight;

                if (bPosOK)
                {
                    dLength = dAltitude + dRadius;
                    if (rTilt.Degrees < 85.0)
                    {
                        double dTilt = Math.Asin(dLength * dSinusLaw); //==new tilt
                        if (Angle.FromRadians(dTilt).Degrees <= 85.0)
                        {
                            dDeltaLatitude += dTilt - rTilt.Radians;
                            rTilt.Radians = dTilt;
                        }
                        else
                            rTilt.Degrees = 85.0;
                    }
                    else
                    {//only change latitude, tilt is fixed Tilt = 85.0
                        dDeltaLatitude += Math.Asin(dRadius * dSinusLaw);
                        dSinusLaw = dSinus / dLength;
                        dDeltaLatitude -= Math.Asin(dRadius * dSinusLaw);
                    }
                }
            }
            else
                dAltitude += s_dDeltaHeight;

            s_TheCamera.Tilt = rTilt;
            s_TheCamera.TargetDistance = DDxCpteDist(dAltitude, s_TheCamera.Tilt, dRadius);

            ///////////////////////////////////////////////////////////////////////////////////////
            /// Latitude/Longitude                                                              ///
            ///////////////////////////////////////////////////////////////////////////////////////
            double factor = s_TheCamera.Altitude / (s_WW.CurrentWorld.EquatorialRadius * NormLatLon);//50000.0);
            dDeltaLatitude += TranslVector.Y * factor;
            dDeltaLongitude += TranslVector.X * factor;

            ///////////////////////////////////////////////////////////////////////////////////////
            /// Heading                                                                         ///
            ///////////////////////////////////////////////////////////////////////////////////////
            double dHeading = -AngleAxis.Z * AngleAxis.Angle * WorldSettings.CameraRotationSpeed / NormHeading; // 250000.0;

            ///////////////////////////////////////////////////////////////////////////////////////
            /// set the new View/Camera - position                                              ///
            ///////////////////////////////////////////////////////////////////////////////////////
            Quaternion4d TiltQuat
               = Quaternion4d.RotationYawPitchRoll(0
                                                , -dAlpha
                                                , 0);

            Quaternion4d TiltQuatInv
               = Quaternion4d.RotationYawPitchRoll(0
                                                , dAlpha
                                                , 0);

            Quaternion4d SpMoQuat
               = Quaternion4d.RotationYawPitchRoll(dDeltaLongitude
                                                , dDeltaLatitude
                                                , dHeading);

            Quaternion4d OrientNew = TiltQuatInv * SpMoQuat * TiltQuat;
            OrientNew *= s_TheCamera.CurrentOrientation;
            s_TheCamera.CurrentOrientation = OrientNew;

            s_Position = Quaternion4d.QuaternionToEuler(OrientNew);
            s_TheCamera.Heading = Angle.FromRadians(s_Position.Z);
            s_WW.SetViewPosition(Angle.FromRadians(s_Position.Y).Degrees
                                     , Angle.FromRadians(s_Position.X).Degrees
                                     , dAltitude);

            World.Settings.CameraSmooth = bBackUpSmooth;
            s_stopWatch.Reset();
            s_stopWatch.Start();
        }
Example #8
0
        public override void Unload()
        {
            if (m_TheInputDevice != null)
                m_TheInputDevice.Disconnect();

            if ((m_KeyEventHandler != null) && (s_TheKeyBoard != null))
                s_TheKeyBoard.KeyboardEventDOWN -= m_KeyEventHandler;
            if ((m_SensorEventHandler != null) && (s_TheSensor != null))
                s_TheSensor.SensorInput -= m_SensorEventHandler;

            m_KeyEventHandler = null;
            m_SensorEventHandler = null;
            s_TheSensor = null;
            s_TheCamera = null;

            s_dLastHeight = 0;
            s_dDeltaHeight = 0;
            s_stopWatch = null;  //check event interval of the input device
            s_TheCamera = null;
            s_WW = null;

            if (m_TheInputDevice != null)
                m_TheInputDevice.Release();

            m_TheInputDevice = null;

            // Clean up, remove menu item
            // JBTODO: m_app.MenuStrip.Items.Remove(menuItem);
            base.Unload();
        }
Example #9
0
        public override void Load()
        {
            base.Load();

            // Add our plugin to the World Wind Tools menu
            menuItem = new System.Windows.Forms.ToolStripMenuItem();
            menuItem.Text = "3Dconnexion Input Device";
            menuItem.Click += new System.EventHandler(menuItem_Click);
            s_stopWatch = new Stopwatch();
            s_WW = m_Application.WorldWindow;

            s_TheCamera = s_WW.DrawArgs.WorldCamera;

            m_TheInputDevice = new TDconnexion.TDxDeviceWrapper();
            if (m_TheInputDevice != null)
            {
                    if (m_TheInputDevice.InitializationSuccessful)
                    {
                        // JBTODO: m_app.MenuStrip.Items.Add(menuItem);

                        s_TheSensor = m_TheInputDevice.Sensor;
                        s_TheKeyBoard = m_TheInputDevice.Keyboard;
                        s_Position = new Point3d();
                        SetCameraMode();
                        m_KeyEventHandler = new TDconnexion.TDxKeyboardEvent(KeyboardEventHandler);
                        s_TheKeyBoard.KeyboardEventDOWN += m_KeyEventHandler;
                        m_TheInputDevice.Connect();
                    }
                    else
                    {
                        m_TheInputDevice = null;
                    }
            }
        }
Example #10
0
 private bool IsInViewFrustum(CameraBase camera, MyChart c)
 {
     if (c.Position
         == Vector3.Empty) {
         c.Position = MathEngine.SphericalToCartesian(c.Latitude, c.Longitude, camera.WorldRadius);
     }
     return camera.ViewFrustum.ContainsPoint(c.Position);
 }
Example #11
0
        public virtual void ResetCacheForCurrentView(CameraBase camera)
        {
            if (!ImageStore.IsDownloadableLayer) {
                return;
            }

            ArrayList deletionList = new ArrayList();
            //reset "root" tiles that intersect current view
            lock (m_topmostTiles.SyncRoot) {
                foreach (long key in m_topmostTiles.Keys) {
                    QuadTile qt = (QuadTile) m_topmostTiles[key];
                    if (camera.ViewFrustum.Intersects(qt.BoundingBox)) {
                        qt.ResetCache();
                        deletionList.Add(key);
                    }
                }

                foreach (long deletionKey in deletionList) {
                    m_topmostTiles.Remove(deletionKey);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Render view from right eye
        /// </summary>
        void RenderRightEye(DrawArgs drawArgs, Texture t, CameraBase camera)
        {
            Device device = drawArgs.device;
            using (Surface outputSurface = t.GetSurfaceLevel(0))
            {
                // Render to our texture
                Surface backBuffer = device.GetRenderTarget(0);
                device.SetRenderTarget(0, outputSurface);

                // Clear
                System.Drawing.Color backgroundColor = System.Drawing.Color.Black;
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, backgroundColor, 1.0f, 0);

                // Render world
                worldWin.CurrentWorld.Render(drawArgs);

                // Restore our original back buffer and world transform
                device.SetRenderTarget(0, backBuffer);

            }
        }
Example #13
0
 /// <summary>
 /// determine whether this chart item is in visuble.
 /// </summary>
 /// <param name="camera"></param>
 /// <returns></returns>
 private bool IsInViewFrustum(CameraBase camera)
 {
     if (base.Position
         == Vector3.Empty) {
         base.position = MathEngine.SphericalToCartesian(this.latitude, this.longitude, camera.WorldRadius);
     }
     return camera.ViewFrustum.ContainsPoint(base.Position);
 }