Esempio n. 1
0
        public static void QueueThread()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false);
            bool fileOnly = fileOnlyThreadID == Thread.CurrentThread.ManagedThreadId;
            while (running)
            {
                if (queue.Count < 1)
                {
                    System.Threading.Thread.Sleep(50);
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                }

                double minDistance = 1000000000000000000;
                bool overlayTile = false;
                long maxKey = 0;
                int level = 1000;

                queueMutex.WaitOne();
                foreach (Tile t in queue.Values )
                {

                    if (!t.RequestPending ) // && t.InViewFrustum)
                    {
                        Vector3d vectTemp = new Vector3d(t.SphereCenter);

                        vectTemp.TransformCoordinate(Earth3d.WorldMatrix);

                        if (Earth3d.MainWindow.Space)
                        {
                            vectTemp.Subtract(new Vector3d(0.0f, 0.0f, -1.0f));
                        }
                        else
                        {
                            vectTemp.Subtract(Earth3d.MainWindow.RenderContext11.CameraPosition);
                        }

                        double distTemp = Math.Max(0,vectTemp.Length()-t.SphereRadius);

                        bool thisIsOverlay = (t.Dataset.Projection == ProjectionType.Tangent) || (t.Dataset.Projection == ProjectionType.SkyImage);
                        if (distTemp < minDistance && (!overlayTile || thisIsOverlay))
                        {

                            Tile test = (Tile)queue[t.Key];

                            if (!test.FileChecked)
                            {

                                test.FileExists = File.Exists(test.FileName);
                                test.FileChecked = true;
                                if (test.Volitile)
                                {
                                    test.FileExists = false;
                                }
                            }

                            if (test.FileExists || (!test.FileExists && !fileOnly))
                            {
                                minDistance = distTemp;
                                maxKey = t.Key;
                                level = t.Level;
                                overlayTile = thisIsOverlay;
                            }
                        }
                    }

                }
                if (maxKey != 0)
                {
                    Tile workTile = (Tile)queue[maxKey];
                    workTile.RequestPending = true;
                    TileCache.RequestCount++;
                    queueMutex.ReleaseMutex();
                    TileCache.GetTileFromWeb(workTile, true);
                    queueMutex.WaitOne();
                    TileCache.RequestCount--;
                    workTile.RequestPending = false;
                    queue.Remove(workTile.Key);
                }

                queueMutex.ReleaseMutex();
            }
            return;
        }
Esempio n. 2
0
        public virtual bool IsTileInFrustum(PlaneD[]frustum)
        {
            InViewFrustum = false;
            Vector3d center = sphereCenter;

            if (this.Level < 2 && (dataset.Projection == ProjectionType.Mercator || dataset.Projection == ProjectionType.Toast))
            {
                return true;
            }

            Vector4d centerV4 = new Vector4d(center.X , center.Y , center.Z , 1f);
            Vector3d length = new Vector3d(sphereRadius, 0, 0);

            double rad = length.Length();
            for (int i = 0; i < 6; i++)
            {
                if (frustum[i].Dot(centerV4) + rad < 0)
                {
                    return false;
                }
            }
            InViewFrustum = true;

            return true;
        }
        // Get the radius in pixels of a sphere with the specified center and radius
        // The sphere center should be a point in camera space
        private static double ProjectedSizeInPixels(RenderContext11 renderContext, Vector3d center, double radius)
        {
            Matrix3d projection = renderContext.Projection;
            SharpDX.Direct3D11.Viewport viewport = renderContext.ViewPort;

            double distance = center.Length();

            // Calculate pixelsPerUnit which is the number of pixels covered
            // by an object 1 AU at the distance of the planet center from
            // the camera. This calculation works regardless of the projection
            // type.
            double viewportHeight = viewport.Height;
            double p11 = projection.M11;
            double p34 = projection.M34;
            double p44 = projection.M44;
            double w = Math.Abs(p34) * distance + p44;
            double pixelsPerUnit = (p11 / w) * viewportHeight;

            return radius * pixelsPerUnit;
        }
Esempio n. 4
0
        public static Vector3d MidPointByLength(Vector3d left, Vector3d right)
        {
            var result = new Vector3d((left.X + right.X) / 2, (left.Y + right.Y) / 2, (left.Z + right.Z) / 2);
            result.Normalize();

            result.Multiply(left.Length());
            return result;
        }