Exemple #1
0
        // ** Begin
        public static void DrawMPC3D(RenderContext renderContext, float opacity, Vector3d centerPoint)
        {
            double zoom      = renderContext.ViewCamera.Zoom;
            double distAlpha = ((Math.Log(Math.Max(1, zoom)) / Math.Log(4)) - 15.5) * 90;

            int alpha = Math.Min(255, Math.Max(0, (int)distAlpha));



            if (alpha > 254)
            {
                return;
            }


            if (mpcVertexBuffer == null)
            {
                if (starTexture == null)
                {
                    starTexture = Planets.LoadPlanetTexture(URLHelpers.singleton.engineAssetUrl("StarProfileAlpha.png"));
                }
                for (int i = 0; i < 7; i++)
                {
                    mpcBlendStates[i] = BlendState.Create(false, 1000);
                }

                if (!initBegun)
                {
                    StartInit();
                    initBegun = true;
                }
                return;
            }

            Matrix3d offset   = Matrix3d.Translation(Vector3d.Negate(centerPoint));
            Matrix3d world    = Matrix3d.MultiplyMatrix(renderContext.World, offset);
            Matrix3d matrixWV = Matrix3d.MultiplyMatrix(world, renderContext.View);

            Vector3d cam = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.InvertMatrix(renderContext.World));

            //todo star profile texture

            if (mpcVertexBuffer != null)
            {
                for (int i = 0; i < 7; i++)
                {
                    // mpcBlendStates[i].TargetState = ((Properties.Settings.Default.MinorPlanetsFilter & (int)Math.Pow(2, i)) != 0);
                    mpcBlendStates[i].TargetState = true;

                    if (mpcBlendStates[i].State)
                    {
                        KeplerPointSpriteShader.Use(renderContext, matrixWV, mpcVertexBuffer[i].VertexBuffer, starTexture.Texture2d, Colors.White,
                                                    opacity * mpcBlendStates[i].Opacity, false,
                                                    (float)(SpaceTimeController.JNow - KeplerVertex.baseDate), 0, renderContext.CameraPosition, 200f, .1f);

                        renderContext.gl.drawArrays(GL.POINTS, 0, mpcVertexBuffer[i].Count);
                    }
                }
            }
        }
Exemple #2
0
        private GlyphCache(int height)
        {
            cellHeight = height;
            texture    = Planets.LoadPlanetTexture("/webclient/images/glyphs1.png");

            webFile = new WebFile("/webclient/images/glyphs1.xml");
            webFile.OnStateChange = GlyphXmlReady;
            webFile.Send();
        }
Exemple #3
0
        private GlyphCache(int height)
        {
            cellHeight = height;
            texture    = Planets.LoadPlanetTexture(URLHelpers.singleton.engineAssetUrl("glyphs1.png"));

            webFile = new WebFile(URLHelpers.singleton.engineAssetUrl("glyphs1.xml"));
            webFile.OnStateChange = GlyphXmlReady;
            webFile.Send();
        }
        public static void DrawCosmos3D(RenderContext renderContext, float opacity)
        {
            GL     device    = renderContext.gl;
            double zoom      = renderContext.ViewCamera.Zoom;
            double distAlpha = ((Math.Log(Math.Max(1, zoom)) / Math.Log(4)) - 15.5) * 90;

            int alpha = Math.Min(255, Math.Max(0, (int)distAlpha));

            if (alpha < 3)
            {
                return;
            }

            InitCosmosVertexBuffer();

            if (galaxyTextures == null)
            {
                if (largeSet)
                {
                    galaxyTextures = new Texture[256];
                    for (int i = 0; i < 256; i++)
                    {
                        string num = i.ToString();

                        while (num.Length < 4)
                        {
                            num = "0" + num;
                        }


                        string name = string.Format("http://cdn.worldwidetelescope.org/webclient/images/gal_{0}.jpg", num);

                        galaxyTextures[i] = Planets.LoadPlanetTexture(name);
                    }
                }
            }

            if (cosmosReady)
            {
                int count = 256;
                for (int i = 0; i < count; i++)
                {
                    //cosmosSprites[i].MinPointSize = 1;
                    cosmosSprites[i].DrawTextured(renderContext, galaxyTextures[i], (alpha * opacity) / 255.0f);
                    // cosmosSprites[i].Draw(renderContext,  (alpha * opacity) / 255.0f, false);
                }
            }
        }
        //const double jBase = 2455198.0;
        void InitBuffer(RenderContext renderContext)
        {
            if (!init)
            {
                if (renderContext.gl == null)
                {
                    starProfile = (ImageElement)Document.CreateElement("img");
                    starProfile.AddEventListener("load", delegate(ElementEvent e)
                    {
                        imageReady = true;
                    }, false);

                    starProfile.Src = "/webclient/images/StarProfileAlpha.png";

                    worldList       = new Vector3d[points.Count];
                    transformedList = new Vector3d[points.Count];

                    int index = 0;
                    foreach (Vector3d pnt in points)
                    {
                        // todo filter by date
                        DataItem item = new DataItem();
                        item.Location          = pnt;
                        item.Tranformed        = new Vector3d();
                        item.Size              = sizes[index];
                        item.Color             = colors[index];
                        worldList[index]       = item.Location;
                        transformedList[index] = item.Tranformed;
                        items.Add(item);
                        index++;
                    }
                }
                else
                {
                    if (pointBuffers.Count == 0)
                    {
                        if (starTexture == null)
                        {
                            starTexture = Planets.LoadPlanetTexture("/webclient/images/StarProfileAlpha.png");
                        }

                        int count = this.points.Count;

                        TimeSeriesPointVertexBuffer pointBuffer = null;
                        TimeSeriesPointVertex[]     pointList   = null;

                        int countLeft = count;
                        int index     = 0;
                        int counter   = 0;
                        foreach (Vector3d point in points)
                        {
                            if (counter >= 100000 || pointList == null)
                            {
                                if (pointBuffer != null)
                                {
                                    pointBuffer.Unlock();
                                }
                                int thisCount = Math.Min(100000, countLeft);

                                countLeft  -= thisCount;
                                pointBuffer = new TimeSeriesPointVertexBuffer(thisCount);

                                pointList = (TimeSeriesPointVertex[])pointBuffer.Lock(); // Lock the buffer (which will return our structs)

                                pointBuffers.Add(pointBuffer);
                                pointBufferCounts.Add(thisCount);
                                counter = 0;
                            }
                            pointList[counter]           = new TimeSeriesPointVertex();
                            pointList[counter].Position  = point;
                            pointList[counter].PointSize = sizes[index];
                            pointList[counter].Tu        = (float)(dates[index].StartDate);
                            pointList[counter].Tv        = (float)(dates[index].EndDate);
                            pointList[counter].Color     = colors[index];
                            index++;
                            counter++;
                        }

                        if (pointBuffer != null)
                        {
                            pointBuffer.Unlock();
                        }
                    }
                }

                init = true;
            }
        }
        private static void CreateGalaxyImage(RenderContext renderContext)
        {
            if (milkyWayImage == null)
            {
                milkyWayImage = Planets.LoadPlanetTexture("http://cdn.worldwidetelescope.org/webclient/images/milkywaybar.jpg");
            }


            int subdivs = 50;

            double lat, lng;

            int    index  = 0;
            double latMin = 64;
            double latMax = -64;
            double lngMin = -64;
            double lngMax = 64;

            //// Create a vertex buffer
            galaxyImageVertexBuffer = new PositionTextureVertexBuffer((subdivs + 1) * (subdivs + 1));
            PositionTexture[] verts = (PositionTexture[])galaxyImageVertexBuffer.Lock();

            int      x1, y1;
            double   latDegrees  = latMax - latMin;
            double   lngDegrees  = lngMax - lngMin;
            double   scaleFactor = 60800000.0;
            double   ecliptic    = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;
            Vector3d point;

            double textureStepX = 1.0f / subdivs;
            double textureStepY = 1.0f / subdivs;

            for (y1 = 0; y1 <= subdivs; y1++)
            {
                if (y1 != subdivs)
                {
                    lat = latMax - (textureStepY * latDegrees * (double)y1);
                }
                else
                {
                    lat = latMin;
                }

                for (x1 = 0; x1 <= subdivs; x1++)
                {
                    if (x1 != subdivs)
                    {
                        lng = lngMin + (textureStepX * lngDegrees * (double)x1);
                    }
                    else
                    {
                        lng = lngMax;
                    }
                    index = y1 * (subdivs + 1) + x1;
                    point = Vector3d.Create(lng * scaleFactor, 0, (lat - 28) * scaleFactor);
                    point.RotateY(213.0 / 180 * Math.PI);
                    point.RotateZ((-62.87175) / 180 * Math.PI);
                    point.RotateY((-192.8595083) / 180 * Math.PI);
                    point.RotateX(ecliptic);
                    verts[index] = PositionTexture.CreatePosRaw(point, (float)(1f - x1 * textureStepX), (float)(/*1f - */ (y1 * textureStepY)));
                    //verts[index].Position = point;
                    //verts[index].Tu = (float)(1f - x1 * textureStepX);
                    //verts[index].Tv = (float)(/*1f - */(y1 * textureStepY));
                }
            }
            galaxyImageVertexBuffer.Unlock();
            galaxyImageTriangleCount = (subdivs) * (subdivs) * 2;
            Uint16Array ui16array = new Uint16Array(subdivs * subdivs * 6);

            UInt16[] indexArray = (UInt16[])(object)ui16array;

            for (y1 = 0; y1 < subdivs; y1++)
            {
                for (x1 = 0; x1 < subdivs; x1++)
                {
                    index = (y1 * subdivs * 6) + 6 * x1;
                    // First triangle in quad
                    indexArray[index]     = (ushort)(y1 * (subdivs + 1) + x1);
                    indexArray[index + 2] = (ushort)((y1 + 1) * (subdivs + 1) + x1);
                    indexArray[index + 1] = (ushort)(y1 * (subdivs + 1) + (x1 + 1));

                    // Second triangle in quad
                    indexArray[index + 3] = (ushort)(y1 * (subdivs + 1) + (x1 + 1));
                    indexArray[index + 5] = (ushort)((y1 + 1) * (subdivs + 1) + x1);
                    indexArray[index + 4] = (ushort)((y1 + 1) * (subdivs + 1) + (x1 + 1));
                }
            }
            galaxyImageIndexBuffer = Tile.PrepDevice.createBuffer();
            Tile.PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, galaxyImageIndexBuffer);
            Tile.PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
        }