示例#1
0
        public void Draw(RenderContext renderContext)
        {
            if (!imageReady)
            {
                return;
            }

            renderContext.Device.Save();

            renderContext.WVP.ProjectArrayToScreen(worldList, transformedList);
            CanvasContext2D ctx = renderContext.Device;
            ctx.Alpha = .4;

            double width = renderContext.Width;
            double height = renderContext.Height;

            Vector3d viewPoint = Vector3d.MakeCopy(renderContext.ViewPoint);

            double scaleFactor = renderContext.FovScale/100;
            foreach (DataItem item in items)
            {
               // if (Vector3d.Dot(viewPoint, item.Location) < 0)
                if (item.Tranformed.Z < 1)
                {
                    double x = item.Tranformed.X;
                    double y = item.Tranformed.Y;
                    double size = 4*item.Size / scaleFactor;
                    double half = size / 2;
                    if (x > -half && x < width + half && y > -half && y < height + half)
                    {
                        ctx.DrawImage(starProfile, x - size / 2, y - size / 2, size, size);

                        //ctx.BeginPath();
                        //ctx.FillStyle = "rgb(200,0,0)";
                        //ctx.Arc(x, y, size, 0, Math.PI * 2, true);
                        //ctx.Fill();
                    }
                }

            }

            renderContext.Device.Restore();
        }
示例#2
0
        public static void DrawPointPlanet(RenderContext renderContext, Vector3d location, double size, Color color, bool zOrder)
        {
            size = Math.Max(2, size);

            Vector3d center = (Vector3d)location;

            double rad = size/2;

            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);
            if (screenSpacePnt.Z < 0)
            {
                return;
            }
            if (!zOrder)
            {
                if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, (Vector3d)center) < .55)
                {
                    return;
                }
            }
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                //ctx.Alpha = opacity;
                ctx.BeginPath();
                ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                ctx.LineWidth = 1;
                ctx.FillStyle = color.ToString();
                if (true)
                {
                    ctx.Fill();
                }
                ctx.Alpha = 1.0;
                ctx.StrokeStyle = color.ToString();
                ctx.Stroke();

                ctx.Restore();
            }
            //device.RenderState.Lighting = false;
            //StarVertex[] vert = new StarVertex[1];
            //vert[0] = new StarVertex(location.Vector3, size, color.ToArgb());
            //device.RenderState.PointSpriteEnable = true;
            //device.RenderState.PointScaleEnable = true;
            //device.RenderState.PointScaleA = 100;
            //device.RenderState.PointScaleB = 0;
            //device.RenderState.PointScaleC = 0;
            //device.RenderState.ZBufferEnable = zOrder;
            //device.SetTexture(0, Grids.StarProfile);
            ////device.SetTexture(0, null);

            //device.VertexFormat = VertexFormats.Position | VertexFormats.PointSize | VertexFormats.Diffuse;

            ////          device.RenderState.CullMode = Cull.None;
            //device.RenderState.AlphaBlendEnable = true;
            //device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha;
            //device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha;

            //device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
            //device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            //device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            //device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            //device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            //device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            //device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;

            //device.TextureState[1].ColorOperation = TextureOperation.Modulate;
            //device.TextureState[1].ColorArgument1 = TextureArgument.Current;
            //device.TextureState[1].ColorArgument2 = TextureArgument.Constant;
            //device.TextureState[1].AlphaOperation = TextureOperation.Modulate;
            //device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
            //device.TextureState[1].AlphaArgument2 = TextureArgument.Constant;

            //device.TextureState[1].ConstantColor = Color.FromArgb(255, 255, 255, 255);

            //device.DrawUserPrimitives(PrimitiveType.PointList, 1, vert);

            //device.RenderState.PointSpriteEnable = false;
            //device.RenderState.PointScaleEnable = false;
        }
示例#3
0
        public static bool DrawPlanets(RenderContext renderContext, float opacity)
        {
            if (planetTextures == null)
            {
                LoadPlanetTextures();
            }

            // Get Moon Phase
            double elong = GeocentricElongation(planetLocations[9].RA, planetLocations[9].Dec, planetLocations[0].RA, planetLocations[0].Dec);
            double raDif = planetLocations[9].RA - planetLocations[0].RA;
            if (planetLocations[9].RA < planetLocations[0].RA)
            {
                raDif += 24;
            }
            double phaseAngle = PhaseAngle(elong, planetLocations[9].Distance, planetLocations[0].Distance);
            double limbAngle = PositionAngle(planetLocations[9].RA, planetLocations[9].Dec, planetLocations[0].RA, planetLocations[0].Dec);

            if (raDif < 12)
            {
                phaseAngle += 180;
            }

            // Check for solar eclipse

            double dista = (Math.Abs(planetLocations[9].RA - planetLocations[0].RA) * 15) * Math.Cos(Coordinates.DegreesToRadians(planetLocations[0].Dec));
            double distb = Math.Abs(planetLocations[9].Dec - planetLocations[0].Dec);
            double sunMoonDist = Math.Sqrt(dista * dista + distb * distb);

            bool eclipse = false;
            double coronaOpacity = 0;

            //if (sunMoonDist < .014 && planetScales[9] > planetScales[0])

            double moonEffect = (planetScales[9] / 2 - sunMoonDist);

            int darkLimb = Math.Min(32, (int)(sunMoonDist * 32));

            if (moonEffect > (planetScales[0] / 4))
            {

                eclipse = true;
                //coronaOpacity = Math.Min(1.0, Math.Abs((sunMoonDist-.014)/.007));
                coronaOpacity = Math.Min(1.0, (moonEffect - (planetScales[0] / 2)) / .001);
                DrawPlanet(renderContext, 18, coronaOpacity);

            }

            //            Earth3d.MainWindow.Text = phaseAngle.ToString() + ", " + raDif.ToString();

            //            for (int i = 0; i < planetDrawOrder.Count; i++)

            foreach( double key in planetDrawOrder.Keys)
            {
                int planetId = planetDrawOrder[key];

                //if (planetId == 9)
                //{
                //    DrawPlanetPhase(canvas, planetId, phaseAngle, limbAngle, darkLimb);
                //}
                //else
                {
                    DrawPlanet(renderContext, planetId, 1);
                }

            }

            return true;
        }
示例#4
0
        private static void DrawSingleOrbit(RenderContext renderContext, Color eclipticColor, int id, Vector3d centerPoint, double startAngle, Vector3d planetNow, float opacity)
        {
            if (opacity < .01)
            {
                return;
            }

            if (renderContext.gl == null)
            {
                int count = orbitalSampleRate;
                bool planetDropped = false;

                Vector3d viewPoint = renderContext.ViewPoint;

                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();

                ctx.StrokeStyle = eclipticColor.ToString();
                ctx.LineWidth = 2;
                ctx.Alpha = 1;
                Vector3d point = new Vector3d();
                Vector3d pointTest = new Vector3d();

                Vector3d lastPoint = new Vector3d();
                bool firstPoint = true;
                Matrix3d translate = Matrix3d.Translation(Vector3d.Negate(centerPoint));
                Matrix3d mat = Matrix3d.MultiplyMatrix(translate, renderContext.WVP);
                Matrix3d matWV = Matrix3d.MultiplyMatrix(translate, renderContext.WV);

                for (int i = 0; i < count; i ++)
                {
                    Vector3d pnt = orbits[id][i];

                    double angle = (Math.Atan2(orbits[id][i].Z, orbits[id][i].X) + Math.PI * 2 - startAngle) % (Math.PI * 2);
                    int alpha = (int)((angle) / (Math.PI * 2) * 255);

                    double alphaD = (double)alpha / 255.0;

                    if (alpha < 2 && !planetDropped)
                    {
                        pnt = planetNow;
                        alphaD = 1.0;

                    }

                    pointTest = matWV.Transform(pnt);
                    point = mat.Transform(pnt);

                    if (pointTest.Z > 0)
                    {

                        if (firstPoint)
                        {

                            firstPoint = false;
                        }
                        else
                        {
                            // if (Vector3d.Dot(pnt, viewPoint) > .60)
                            {
                                ctx.BeginPath();
                                ctx.Alpha = alphaD * opacity;
                                ctx.MoveTo(lastPoint.X, lastPoint.Y);
                                ctx.LineTo(point.X, point.Y);
                                ctx.Stroke();
                            }
                        }
                    }

                    lastPoint = point;
                }

                ctx.Restore();
            }
            else
            {
                //todo add webgl method of drawing
            }
        }
示例#5
0
        public void DrawLines(RenderContext renderContext, float opacity)
        {
            if (linePoints.Count < 2 || opacity <= 0)
            {
                return;
            }
            if (renderContext.gl == null)
            {
                //todo draw with HTML5
            }
            else
            {
                InitLineBuffer();
                //Matrix3d savedWorld = renderContext.World;
                //Matrix3d savedView = renderContext.View;
                //if (localCenter != Vector3d.Empty)
                //{
                //    usingLocalCenter = true;
                //    Vector3d temp = localCenter;
                //    if (UseNonRotatingFrame)
                //    {
                //        renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBaseNonRotating * Matrix3d.Translation(-renderContext.CameraPosition);
                //    }
                //    else
                //    {
                //        renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBase * Matrix3d.Translation(-renderContext.CameraPosition);
                //    }
                //    renderContext.View = Matrix3d.Translation(renderContext.CameraPosition) * renderContext.ViewBase;
                //}

                //DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);

                //renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList;


                //LineShaderNormalDates11.Constants.JNow = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
                //LineShaderNormalDates11.Constants.Sky = Sky ? 1 : 0;
                //LineShaderNormalDates11.Constants.ShowFarSide = ShowFarSide ? 1 : 0;
                //if (TimeSeries)
                //{
                //    LineShaderNormalDates11.Constants.Decay = (float)Decay;
                //}
                //else
                //{
                //    LineShaderNormalDates11.Constants.Decay = 0;
                //}

                //LineShaderNormalDates11.Constants.Opacity = opacity;
                //LineShaderNormalDates11.Constants.CameraPosition = new SharpDX.Vector4(Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311, 1);
                //SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
                //mat.Transpose();

                //LineShaderNormalDates11.Constants.WorldViewProjection = mat;

                //LineShaderNormalDates11.Use(renderContext.devContext);

                //renderContext.DepthStencilMode = DepthBuffered ? DepthStencilMode.ZReadWrite : DepthStencilMode.Off;

                foreach (TimeSeriesLineVertexBuffer lineBuffer in lineBuffers)
                {
                    LineShaderNormalDates.Use(renderContext, lineBuffer.VertexBuffer, Color.FromArgb(255, 255, 255, 255), zBuffer, (float)JNow, TimeSeries ? (float)Decay : 0);
                    renderContext.gl.drawArrays(GL.LINES, 0, lineBuffer.Count);
                }

                //renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;

                //if (usingLocalCenter)
                //{
                //    renderContext.World = savedWorld;
                //    renderContext.View = savedView;
                //}
            }
        }
示例#6
0
        internal static void Draw(RenderContext renderContext, float opacity, bool astronomical, string referenceFrame, bool nested, bool cosmos)
        {
            if (!AllMaps.ContainsKey(referenceFrame))
            {
                return;
            }

            LayerMap thisMap = AllMaps[referenceFrame];

            if (!thisMap.Enabled || (thisMap.ChildMaps.Count == 0 && thisMap.Layers.Count == 0 && !(thisMap.Frame.ShowAsPoint || thisMap.Frame.ShowOrbitPath)))
            {
                return;
            }
            if (TourPlayer.Playing)
            {
                TourPlayer player = (TourPlayer)WWTControl.Singleton.uiController;
                if (player != null)
                {
                    TourDocument tour = player.Tour;
                    if (tour.CurrentTourStop != null)
                    {
                        player.UpdateTweenPosition(-1);
                        tour.CurrentTourStop.UpdateLayerOpacity();

                        foreach (Guid key in tour.CurrentTourStop.Layers.Keys)
                        {
                            LayerInfo info = tour.CurrentTourStop.Layers[key];

                            if (LayerList.ContainsKey(info.ID))
                            {
                                LayerList[info.ID].Opacity = info.FrameOpacity;
                                LayerList[info.ID].SetParams(info.FrameParams);
                            }
                        }
                    }
                }
            }

            Matrix3d matOld = renderContext.World;
            Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating;
            double oldNominalRadius = renderContext.NominalRadius;
            if (thisMap.Frame.Reference == ReferenceFrames.Custom)
            {
                thisMap.ComputeFrame(renderContext);
                if (thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Orbital && thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Trajectory)
                //if (true)
                {
                    renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.World);
                }
                else
                {
                    renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.WorldBaseNonRotating);

                }
                renderContext.NominalRadius = thisMap.Frame.MeanRadius;
            }

            if (thisMap.Frame.ShowAsPoint)
            {

                // todo Draw point planet...
                // Planets.DrawPointPlanet(renderContext.Device, new Vector3d(0, 0, 0), (float).2, thisMap.Frame.RepresentativeColor, true);

            }

            for (int pass = 0; pass < 2; pass++)
            {
                foreach (Layer layer in AllMaps[referenceFrame].Layers)
                {
                    if ((pass == 0 && layer is ImageSetLayer) || (pass == 1 && !(layer is ImageSetLayer)))
                    {
                        if (layer.Enabled) // && astronomical == layer.Astronomical)
                        {
                            double layerStart = SpaceTimeController.UtcToJulian(layer.StartTime);
                            double layerEnd = SpaceTimeController.UtcToJulian(layer.EndTime);
                            double fadeIn = SpaceTimeController.UtcToJulian(layer.StartTime) - ((layer.FadeType == FadeType.FadeIn || layer.FadeType == FadeType.Both) ? (layer.FadeSpan / 864000000) : 0);
                            double fadeOut = SpaceTimeController.UtcToJulian(layer.EndTime) + ((layer.FadeType == FadeType.FadeOut || layer.FadeType == FadeType.Both) ? (layer.FadeSpan / 864000000) : 0);

                            if (SpaceTimeController.JNow > fadeIn && SpaceTimeController.JNow < fadeOut)
                            {
                                float fadeOpacity = 1;
                                if (SpaceTimeController.JNow < layerStart)
                                {
                                    fadeOpacity = (float)((SpaceTimeController.JNow - fadeIn) / (layer.FadeSpan / 864000000));
                                }

                                if (SpaceTimeController.JNow > layerEnd)
                                {
                                    fadeOpacity = (float)((fadeOut - SpaceTimeController.JNow) / (layer.FadeSpan / 864000000));
                                }
                                layer.Astronomical = astronomical;
                                //if (thisMap.Frame.Reference == ReferenceFrames.Sky)
                                //{
                                //    layer.Astronomical = true;
                                //}
                                layer.Draw(renderContext, opacity * fadeOpacity, cosmos);
                            }
                        }
                    }
                }
            }
            if (nested)
            {
                foreach (string key in AllMaps[referenceFrame].ChildMaps.Keys)
                {
                    LayerMap map = AllMaps[referenceFrame].ChildMaps[key];
                    if (map.Frame.ShowOrbitPath && Settings.Active.SolarSystemOrbits)
                    {
                        if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Orbital)
                        {
                            if (map.Frame.Orbit == null)
                            {
                                map.Frame.Orbit = new Orbit(map.Frame.Elements, 360, map.Frame.RepresentativeColor, 1, (float)renderContext.NominalRadius);
                            }
                            Matrix3d matSaved = renderContext.World;
                            renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.WorldBaseNonRotating);

                            map.Frame.Orbit.Draw3D(renderContext, 1f * .25f, Vector3d.Create(0, 0, 0));
                            renderContext.World = matSaved;
                        }
                        else if (map.Frame.ReferenceFrameType == ReferenceFrameTypes.Trajectory)
                        {
                            //todo add trajectories back
                            //if (map.Frame.trajectoryLines == null)
                            //{
                            //    map.Frame.trajectoryLines = new LineList(renderContext.Device);
                            //    map.Frame.trajectoryLines.ShowFarSide = true;
                            //    map.Frame.trajectoryLines.UseNonRotatingFrame = true;

                            //    int count = map.Frame.Trajectory.Count - 1;
                            //    for (int i = 0; i < count; i++)
                            //    {
                            //        Vector3d pos1 = map.Frame.Trajectory[i].Position;
                            //        Vector3d pos2 = map.Frame.Trajectory[i + 1].Position;
                            //        pos1.Multiply(1 / renderContext.NominalRadius);
                            //        pos2.Multiply(1 / renderContext.NominalRadius);
                            //        map.Frame.trajectoryLines.AddLine(pos1, pos2, map.Frame.RepresentativeColor, new Dates());
                            //    }
                            //}
                            //Matrix3D matSaved = renderContext.World;
                            //renderContext.World = thisMap.Frame.WorldMatrix * renderContext.WorldBaseNonRotating;

                            //map.Frame.trajectoryLines.DrawLines(renderContext, Earth3d.MainWindow.showMinorOrbits.Opacity * .25f);
                            //renderContext.World = matSaved;
                        }
                    }

                    if ((map.Frame.Reference == ReferenceFrames.Custom || map.Frame.Reference == ReferenceFrames.Identity))
                    {
                        Draw(renderContext, opacity, astronomical, map.Name, nested, cosmos);
                    }
                }
            }
            renderContext.NominalRadius = oldNominalRadius;
            renderContext.World = matOld;
            renderContext.WorldBaseNonRotating = matOldNonRotating;
        }
示例#7
0
 public override bool Draw(RenderContext renderContext, float opacity, bool flat)
 {
     return base.Draw(renderContext, opacity, false);
 }
 protected virtual bool PrepVertexBuffer(RenderContext renderContext, float opacity)
 {
     return true;
 }
示例#9
0
 public virtual bool PreDraw(RenderContext renderContext, float opacity)
 {
     return(true);
 }
示例#10
0
 public virtual bool Draw(RenderContext renderContext, float opacity, bool flat)
 {
     return(true);
 }
示例#11
0
        public void Draw(RenderContext renderContext, float opacity, bool cull)
        {
            InitBuffer(renderContext);



            if (renderContext.gl == null)
            {
                if (!imageReady)
                {
                    return;
                }
                renderContext.Device.Save();

                renderContext.WVP.ProjectArrayToScreen(worldList, transformedList);
                CanvasContext2D ctx = renderContext.Device;
                ctx.Alpha = .4;

                double width  = renderContext.Width;
                double height = renderContext.Height;

                Vector3d viewPoint = Vector3d.MakeCopy(renderContext.ViewPoint);

                double scaleFactor = renderContext.FovScale / 100;
                foreach (DataItem item in items)
                {
                    // todo filter by date

                    // if (Vector3d.Dot(viewPoint, item.Location) < 0)
                    if (item.Tranformed.Z < 1)
                    {
                        double x    = item.Tranformed.X;
                        double y    = item.Tranformed.Y;
                        double size = .1 * item.Size / scaleFactor;
                        double half = size / 2;
                        if (x > -half && x < width + half && y > -half && y < height + half)
                        {
                            //ctx.DrawImage(starProfile, x - size / 2, y - size / 2, size, size);

                            ctx.BeginPath();
                            // ctx.FillStyle = "rgb(200,0,0)";
                            ctx.FillStyle = item.Color.ToFormat();
                            ctx.Arc(x, y, size, 0, Math.PI * 2, true);
                            ctx.Fill();
                        }
                    }
                }

                renderContext.Device.Restore();
            }
            else
            {
                Vector3d zero   = new Vector3d();
                Matrix3d matInv = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View);
                matInv.Invert();
                Vector3d cam = Vector3d.TransformCoordinate(zero, matInv);

                foreach (TimeSeriesPointVertexBuffer pointBuffer in pointBuffers)
                {
                    TimeSeriesPointSpriteShader.Use(
                        renderContext, pointBuffer.VertexBuffer, starTexture.Texture2d,
                        Color.FromArgb(255 * opacity, 255, 255, 255), DepthBuffered, (float)(this.JNow),
                        this.TimeSeries ? (float)Decay : 0, cam, (float)(scale * (renderContext.Height / 960)), MinSize, ShowFarSide, Sky
                        );

                    renderContext.gl.drawArrays(GL.POINTS, 0, pointBuffer.Count);
                }

                // renderContext.gl.disable(0x8642);
            }
        }
示例#12
0
        //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 = URLHelpers.singleton.engineAssetUrl("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(URLHelpers.singleton.engineAssetUrl("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;
            }
        }
示例#13
0
 public PointList(RenderContext device)
 {
     this.device = device;
 }
示例#14
0
        public void Draw(RenderContext renderContext, float opacity, CullMode cull)
        {
            if (trianglePoints.Count < 1 && !dataToDraw)
            {
                return;
            }



            //renderContext.DepthStencilMode = DepthBuffered ? (WriteZbuffer ? DepthStencilMode.ZReadWrite : DepthStencilMode.ZReadOnly) : DepthStencilMode.Off;

            //renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            //switch (cull)
            //{
            //    case CullMode.Clockwise:
            //        renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
            //        break;
            //    case CullMode.CounterClockwise:
            //        renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);
            //        break;
            //    case CullMode.None:
            //        renderContext.setRasterizerState(TriangleCullMode.Off);
            //        break;
            //    default:
            //        break;
            //}


            //if (AutoTime)
            //{
            //    DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);
            //    LineShaderNormalDates.Constants.JNow = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
            //}
            //else
            //{
            //    LineShaderNormalDates.Constants.JNow = (float)JNow;
            //}

            //LineShaderNormalDates.Constants.Sky = 0;
            //LineShaderNormalDates.Constants.ShowFarSide = ShowFarSide ? 1 : 0;
            //if (TimeSeries)
            //{
            //    LineShaderNormalDates.Constants.Decay = (float)Decay;
            //}
            //else
            //{
            //    LineShaderNormalDates.Constants.Decay = 0;
            //}
            //LineShaderNormalDates.Constants.Opacity = opacity;
            //LineShaderNormalDates.Constants.CameraPosition = new SharpDX.Vector4(Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311, 1);

            //SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            //mat.Transpose();

            //LineShaderNormalDates.Constants.WorldViewProjection = mat;

            //LineShaderNormalDates.Use(renderContext.devContext);

            //foreach (TimeSeriesLineVertexBuffer vertBuffer in triangleBuffers)
            //{
            //    renderContext.SetVertexBuffer(vertBuffer);
            //    renderContext.devContext.Draw(vertBuffer.Count, 0);
            //}

            if (renderContext.gl == null)
            {
                //todo implement HTML5 version
            }
            else
            {
                InitTriangleBuffer();
                foreach (TimeSeriesLineVertexBuffer triBuffer in triangleBuffers)
                {
                    LineShaderNormalDates.Use(renderContext, triBuffer.VertexBuffer, Color.FromArgb(255, 255, 255, 255), DepthBuffered, (float)JNow, TimeSeries ? (float)Decay : 0);
                    renderContext.gl.drawArrays(GL.TRIANGLES, 0, triBuffer.Count);
                }
            }
        }
示例#15
0
        public static void InitPlanetResources(RenderContext renderContext)
        {
            //            OrbitsMutex.WaitOne();
            //            try
            //            {
            //                if (planetTexturesMaps == null)
            //                {
            //                    LoadPlanetTextureMaps(device);
            //                }
            //                if (sphereIndexBuffers == null)
            //                {
            //                    InitSphere(device);
            //                }

            //                if (ringsVertexBuffer == null)
            //                {
            //                    InitRings(device);
            //                }
            //            }
            //            finally
            //            {
            //                OrbitsMutex.ReleaseMutex();
            //            }
        }
示例#16
0
        private void DrawCrosshairs(RenderContext context)
        {
            if (context.gl == null)
            {

                CanvasContext2D ctx = context.Device;
                ctx.Save();
                ctx.BeginPath();
                ctx.StrokeStyle = Settings.Current.CrosshairsColor;
                ctx.LineWidth = 2;

                double x = context.Width / 2, y = context.Height / 2;
                double halfLength = 5;

                ctx.MoveTo(x, y + halfLength);
                ctx.LineTo(x, y - halfLength);
                ctx.MoveTo(x + halfLength, y);
                ctx.LineTo(x - halfLength, y);

                ctx.Stroke();
                ctx.Restore();
            }
        }
示例#17
0
 public override bool Draw(RenderContext renderContext, float opacity, bool flat)
 {
     return(base.Draw(renderContext, opacity, false));
 }
示例#18
0
 public virtual bool Draw(RenderContext renderContext, float opacity, bool flat)
 {
     return true;
 }
示例#19
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                "    precision highp float;                                                              \n" +
                "    uniform vec4 lineColor;                                                             \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        gl_FragColor = lineColor * vColor;                                              \n" +
                "    }                                                                                   \n";


            String vertexShaderText =
                "    attribute vec3 aVertexPosition;                                                     \n" +
                "    attribute vec4 aVertexColor;                                                        \n" +
                "    attribute vec2 aTime;                                                               \n" +
                "    uniform mat4 uMVMatrix;                                                             \n" +
                "    uniform mat4 uPMatrix;                                                              \n" +
                "    uniform float jNow;                                                                 \n" +
                "    uniform float decay;                                                                \n" +
                "                                                                                        \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "                                                                                        \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);                \n" +
                "        float dAlpha = 1.0;                                                             \n" +
                "        if ( decay > 0.0)                                                               \n" +
                "        {                                                                               \n" +
                "             dAlpha = 1.0 - ((jNow - aTime.y) / decay);                                 \n " +
                "             if (dAlpha > 1.0 )                                                         \n" +
                "             {                                                                          \n" +
                "                  dAlpha = 1.0;                                                         \n" +
                "             }                                                                          \n" +
                "        }                                                                               \n" +
                "     if (jNow < aTime.x && decay > 0.0)                                                 \n" +
                "     {                                                                                  \n" +
                //"         vColor = vec4(0.0, 0.0, 0.0, 0.0);                                             \n" +
                "         vColor = vec4(1, 1, 1, 1);                                                    \n" +
                "     }                                                                                  \n" +
                "     else                                                                               \n" +
                "     {                                                                                  \n" +
                "        vColor = vec4(aVertexColor.r, aVertexColor.g, aVertexColor.b, dAlpha * aVertexColor.a);          \n" +
                //"         vColor = vec4(1, 1, 1, 1);                                                    \n" +

                "     }                                                                                  \n" +
                "    }                                                                                   \n" +
                "                                                                                        \n";


            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1 = gl.getShaderParameter(vert, GL.COMPILE_STATUS);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc      = gl.getAttribLocation(prog, "aVertexPosition");
            colorLoc     = gl.getAttribLocation(prog, "aVertexColor");
            timeLoc      = gl.getAttribLocation(prog, "aTime");
            lineColorLoc = gl.getUniformLocation(prog, "lineColor");
            projMatLoc   = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc     = gl.getUniformLocation(prog, "uMVMatrix");
            jNowLoc      = gl.getUniformLocation(prog, "jNow");
            decayLoc     = gl.getUniformLocation(prog, "decay");

            gl.enable(GL.BLEND);
            gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            initialized = true;
        }
示例#20
0
        // ** Begin
        public void Draw3D(RenderContext renderContext, float opacity, Vector3d centerPoint)
        {
            //    Device device = renderContext.Device;
            //    double zoom = Earth3d.MainWindow.ZoomFactor;
            //    double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 15.5) * 90;
            //    //double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 14) * 30 + 24;

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

            //    if (alpha > 254)
            //    {
            //        return;
            //    }

            //    if (orbitVertexBuffer == null)
            //    {
            //        KeplerShader.MakeVertexShader(device);
            //        InitVertexBuffer(renderContext.Device);
            //        return;
            //    }
            //    //device.DrawUserPrimitives(PrimitiveType.LineList, segments, points);

            //    //       Matrix savedWorld = device.Transform.World;

            //    //        Matrix offset = Matrix.Translation(-centerPoint.Vector3);

            //    //  device.Transform.World = device.Transform.World * offset;
            //    Vector3 cam = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;

            //    double M = elements.n * (SpaceTimeController.JNow - elements.T) * 0.01745329251994;
            //    double F = 1;
            //    if (M < 0)
            //    {
            //        F = -1;
            //    }
            //    M = Math.Abs(M) / (2 * Math.PI);
            //    M = (M - (int)(M)) * 2 * Math.PI * F;

            //    KeplerShader.UseShader(device, SpaceTimeController.JNow, cam, opacity, (float)M);

            //    device.RenderState.PointSpriteEnable = true;
            //    device.RenderState.PointScaleEnable = true;

            //    device.RenderState.PointScaleA = 0;
            //    device.RenderState.PointScaleB = 0;
            //    device.RenderState.PointScaleC = 100f;
            //    device.RenderState.ZBufferEnable = true;
            //    device.RenderState.ZBufferWriteEnable = false;
            //    device.SetTexture(0, null);

            //    device.SetStreamSource(0, orbitVertexBuffer, 0);
            //    device.VertexFormat = KeplerVertex.Format;

            //    device.RenderState.CullMode = Cull.None;
            //    device.RenderState.AlphaBlendEnable = true;
            //    device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha;
            //    device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha;

            //    //device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.One;

            //    device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
            //    device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            //    device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            //    device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            //    device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            //    device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            //    device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;

            //    device.TextureState[1].ColorOperation = TextureOperation.SelectArg1;
            //    device.TextureState[1].ColorArgument1 = TextureArgument.Current;
            //    device.TextureState[1].ColorArgument2 = TextureArgument.Constant;
            //    device.TextureState[1].AlphaOperation = TextureOperation.Modulate;
            //    device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
            //    device.TextureState[1].AlphaArgument2 = TextureArgument.Constant;

            //    device.TextureState[2].ColorOperation = TextureOperation.Disable;
            //    device.TextureState[2].AlphaOperation = TextureOperation.Disable;

            //    device.TextureState[1].ConstantColor = Color.FromArgb(255 - alpha, 255 - alpha, 255 - alpha, 255 - alpha);

            //    device.DrawPrimitives(PrimitiveType.LineStrip, 0, segmentCount - 1);
            //    device.VertexShader = null;
            //    device.RenderState.ZBufferWriteEnable = true;
            //    device.RenderState.PointSpriteEnable = false;
            //    device.RenderState.PointScaleEnable = false;
            //    // device.Transform.World = savedWorld;
        }
示例#21
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                "    precision mediump float;                                                            \n" +
                "    uniform vec4 lineColor;                                                             \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "    uniform sampler2D uSampler;                                                         \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        vec4 texColor;                                                                  \n" +
                "        texColor = texture2D(uSampler, gl_PointCoord);                                  \n" +
                "                                                                                        \n" +
                "                                                                                        \n" +
                "        gl_FragColor = lineColor * vColor * texColor;                                   \n" +
                "    }                                                                                   \n";


            String vertexShaderText =
                "    attribute vec3 aVertexPosition;                                                     \n" +
                "    attribute vec4 aVertexColor;                                                        \n" +
                "    attribute vec2 aTime;                                                               \n" +
                "    attribute float aPointSize;                                                         \n" +
                "    uniform mat4 uMVMatrix;                                                             \n" +
                "    uniform mat4 uPMatrix;                                                              \n" +
                "    uniform float jNow;                                                                 \n" +
                "    uniform vec3 cameraPosition;                                                        \n" +
                "    uniform float decay;                                                                \n" +
                "    uniform float scale;                                                                \n" +
                "                                                                                        \n" +
                "    varying lowp vec4 vColor;                                                           \n" +
                "                                                                                        \n" +
                "    void main(void)                                                                     \n" +
                "    {                                                                                   \n" +
                "        float dist = distance(aVertexPosition, cameraPosition);                                \n" +
                "        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);                \n" +
                "        float dAlpha = 1.0;                                                             \n" +
                "        if ( decay > 0.0)                                                               \n" +
                "        {                                                                               \n" +
                "             dAlpha = 1.0 - ((jNow - aTime.y) / decay);                                 \n " +
                "             if (dAlpha > 1.0 )                                                         \n" +
                "             {                                                                          \n" +
                "                  dAlpha = 1.0;                                                         \n" +
                "             }                                                                          \n" +
                "        }                                                                               \n" +
                "        if (jNow < aTime.x && decay > 0.0)                                              \n" +
                "        {                                                                               \n" +
                "            vColor = vec4(0.0, 0.0, 0.0, 0.0);                                          \n" +
                "        }                                                                               \n" +
                "        else                                                                            \n" +
                "        {                                                                               \n" +
                "           vColor = vec4(aVertexColor.r, aVertexColor.g, aVertexColor.b, dAlpha);       \n" +
                // "           vColor = vec4(1,1,1,1);       \n" +

                "        }                                                                               \n" +
                "        gl_PointSize = max(2.0, (scale * ( aPointSize ) / dist));                     \n" +
                "    }                                                                                   \n" +
                "                                                                                        \n";


            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1          = gl.getShaderParameter(vert, GL.COMPILE_STATUS);
            object compilationLog = gl.getShaderInfoLog(vert);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc      = gl.getAttribLocation(prog, "aVertexPosition");
            colorLoc     = gl.getAttribLocation(prog, "aVertexColor");
            pointSizeLoc = gl.getAttribLocation(prog, "aPointSize");
            timeLoc      = gl.getAttribLocation(prog, "aTime");
            projMatLoc   = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc     = gl.getUniformLocation(prog, "uMVMatrix");
            sampLoc      = gl.getUniformLocation(prog, "uSampler");
            jNowLoc      = gl.getUniformLocation(prog, "jNow");
            decayLoc     = gl.getUniformLocation(prog, "decay");
            lineColorLoc = gl.getUniformLocation(prog, "lineColor");
            cameraPosLoc = gl.getUniformLocation(prog, "cameraPosition");
            scaleLoc     = gl.getUniformLocation(prog, "scale");
            gl.enable(GL.BLEND);

            initialized = true;
        }
示例#22
0
        public void ComputeFrame(RenderContext renderContext)
        {
            if (Frame.Reference == ReferenceFrames.Custom)
            {
                Frame.ComputeFrame(renderContext);

            }
        }
示例#23
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                " precision mediump float;                                                                \n" +
                "                                                                                         \n" +
                "   varying lowp vec4 vColor;                                                             \n" +
                "                                                                                         \n" +
                "   void main(void) {                                                                     \n" +
                "   gl_FragColor =  vColor;  \n" +
                //                     "   gl_FragColor = vec4(1,1,1,1);  \n" +
                "   }                                                                                     \n";


            String vertexShaderText =
                "     attribute vec3 aVertexPosition;                                              \n" +
                //     "     attribute vec2 aTextureCoord;                                                \n" +
                "     attribute lowp vec4 aColor;                                                \n" +
                "                                                                                  \n" +
                "     uniform mat4 uMVMatrix;                                                      \n" +
                "     uniform mat4 uPMatrix;                                                       \n" +
                "                                                                                  \n" +
                "     varying vec2 vTextureCoord;                                                  \n" +
                "     varying vec4 vColor;                                                         \n" +
                "                                                                                  \n" +
                "                                                                                  \n" +
                "     void main(void) {                                                            \n" +
                "         gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);         \n" +
                //   "         vTextureCoord = aTextureCoord;                                           \n" +
                "         vColor = aColor;                                                         \n" +
                "     }                                                                            \n" +
                "                                                                                  \n";

            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1 = gl.getShaderParameter(vert, GL.COMPILE_STATUS);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc    = gl.getAttribLocation(prog, "aVertexPosition");
            colorLoc   = gl.getAttribLocation(prog, "aColor");
            projMatLoc = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc   = gl.getUniformLocation(prog, "uMVMatrix");

            gl.disable(GL.DEPTH_TEST);
            gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            initialized = true;
        }
示例#24
0
 private static void DrawPlanetPhase(RenderContext renderContext, int planetID, double phase, double angle, int dark)
 {
 }
示例#25
0
        public static void Init(RenderContext renderContext)
        {
            GL gl = renderContext.gl;

            String fragShaderText =
                " precision mediump float;                                                              \n" +
                "                                                                                       \n" +
                "   varying vec2 vTextureCoord;                                                         \n" +
                "                                                                                       \n" +
                "   uniform sampler2D uSampler;                                                         \n" +
                "                                                                                       \n" +
                "   void main(void) {                                                                   \n" +
                "   gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));         \n" +
                "   }                                                                                   \n";


            String vertexShaderText =
                "     attribute vec3 aVertexPosition;                                              \n" +
                "     attribute vec2 aTextureCoord;                                                \n" +
                "                                                                                  \n" +
                "     uniform mat4 uMVMatrix;                                                      \n" +
                "     uniform mat4 uPMatrix;                                                       \n" +
                "                                                                                  \n" +
                "     varying vec2 vTextureCoord;                                                  \n" +
                "                                                                                  \n" +
                "                                                                                  \n" +
                "     void main(void) {                                                            \n" +
                "         gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);         \n" +
                "         vTextureCoord = aTextureCoord;                                           \n" +
                "     }                                                                            \n" +
                "                                                                                  \n";

            frag = gl.createShader(GL.FRAGMENT_SHADER);
            gl.shaderSource(frag, fragShaderText);
            gl.compileShader(frag);

            object stat = gl.getShaderParameter(frag, GL.COMPILE_STATUS);


            vert = gl.createShader(GL.VERTEX_SHADER);
            gl.shaderSource(vert, vertexShaderText);
            gl.compileShader(vert);
            object stat1 = gl.getShaderParameter(vert, GL.COMPILE_STATUS);

            prog = gl.createProgram();

            gl.attachShader(prog, vert);
            gl.attachShader(prog, frag);
            gl.linkProgram(prog);
            object errcode = gl.getProgramParameter(prog, GL.LINK_STATUS);


            gl.useProgram(prog);

            vertLoc    = gl.getAttribLocation(prog, "aVertexPosition");
            textureLoc = gl.getAttribLocation(prog, "aTextureCoord");
            projMatLoc = gl.getUniformLocation(prog, "uPMatrix");
            mvMatLoc   = gl.getUniformLocation(prog, "uMVMatrix");
            sampLoc    = gl.getUniformLocation(prog, "uSampler");

            Tile.uvMultiple = 1;
            Tile.DemEnabled = true;

            gl.enable(GL.BLEND);
            gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
            initialized = true;
        }
示例#26
0
        //        static BitmapImage PlanetShadow;
        static void DrawSphere(RenderContext renderContext, int planetID)
        {
            string planetName = GetNameFrom3dId(planetID);
            Imageset planet = WWTControl.Singleton.GetImagesetByName(planetName);

            if (planet == null)
            {
                planet = WWTControl.Singleton.GetImagesetByName("Bing Maps Aerial");
            }

            if (planet != null)
            {
                renderContext.DrawImageSet(planet, 100);
                if (planetID == (int)SolarSystemObjects.Earth)
                {
                    // todo clouds   Earth3d.MainWindow.DrawCloudsNoCheck();
                }
                return;

            }
        }
示例#27
0
        //private Vector3d GetTragectoryPoint(double jNow, out Vector3d vector)
        //{
        //int min = 0;
        //int max = Trajectory.Count - 1;

        //Vector3d point =  new Vector3d();

        //vector = new Vector3d();

        //int current = max / 2;

        //bool found = false;

        //while (!found)
        //{
        //    if (current < 1)
        //    {
        //        vector = Trajectory[0].Position - Trajectory[1].Position;
        //        return Trajectory[0].Position;
        //    }


        //    if (current == Trajectory.Count - 1)
        //    {
        //        vector = Trajectory[current - 1].Position - Trajectory[current].Position;
        //        return Trajectory[current].Position;
        //    }

        //    if ((Trajectory[current-1].Time <= jNow) && (Trajectory[current].Time > jNow))
        //    {
        //        double denominator = Trajectory[current].Time -Trajectory[current-1].Time;
        //        double numerator = jNow - Trajectory[current - 1].Time;
        //        double tween = numerator / denominator;
        //        vector = Trajectory[current - 1].Position - Trajectory[current].Position;
        //        point = Vector3d.Lerp(Trajectory[current - 1].Position, Trajectory[current].Position, tween);
        //        return point;
        //    }

        //    if (Trajectory[current].Time < jNow)
        //    {
        //        int next = current + ( max - current + 1) / 2;
        //        min = current;
        //        current = next;
        //    }
        //    else
        //    if (Trajectory[current - 1].Time > jNow)
        //    {
        //        int next = current - ( current - min + 1) / 2;
        //        max = current;
        //        current = next;
        //    }
        //}

        //return point;
        //}

        private void ComputeOrbital(RenderContext renderContext)
        {
            EOE      ee    = Elements;
            Vector3d point = ELL.CalculateRectangularJD(SpaceTimeController.JNow, ee);

            MeanAnomoly = ee.meanAnnomolyOut;
            Vector3d pointInstantLater = ELL.CalculateRectangular(ee, MeanAnomoly + .001);

            Vector3d direction = Vector3d.SubtractVectors(point, pointInstantLater);

            Vector3d up = point.Copy();

            up.Normalize();
            direction.Normalize();

            double dist        = point.Length();
            double scaleFactor = 1.0;

            switch (SemiMajorAxisUnits)
            {
            case AltUnits.Meters:
                scaleFactor = 1.0;
                break;

            case AltUnits.Feet:
                scaleFactor = 1.0 / 3.2808399;
                break;

            case AltUnits.Inches:
                scaleFactor = (1.0 / 3.2808399) / 12;
                break;

            case AltUnits.Miles:
                scaleFactor = 1609.344;
                break;

            case AltUnits.Kilometers:
                scaleFactor = 1000;
                break;

            case AltUnits.AstronomicalUnits:
                scaleFactor = UiTools.KilometersPerAu * 1000;
                break;

            case AltUnits.LightYears:
                scaleFactor = UiTools.AuPerLightYear * UiTools.KilometersPerAu * 1000;
                break;

            case AltUnits.Parsecs:
                scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000;
                break;

            case AltUnits.MegaParsecs:
                scaleFactor = UiTools.AuPerParsec * UiTools.KilometersPerAu * 1000 * 1000000;
                break;

            case AltUnits.Custom:
                scaleFactor = 1;
                break;

            default:
                break;
            }
            scaleFactor *= 1 / renderContext.NominalRadius;


            Matrix3d look = Matrix3d.LookAtLH(Vector3d.Create(0, 0, 0), direction, up);

            look.Invert();

            WorldMatrix = Matrix3d.Identity;
            WorldMatrix.Translate(Translation);

            double localScale = (1 / renderContext.NominalRadius) * Scale * MeanRadius;

            WorldMatrix.Scale(Vector3d.Create(localScale, localScale, localScale));

            //Matrix3d mat = Matrix3d.MultiplyMatrix(Matrix3d.MultiplyMatrix(Matrix3d.RotationY(Heading / 180.0 * Math.PI), Matrix3d.RotationX(Pitch / 180.0 * Math.PI)),Matrix3d.RotationZ(Roll / 180.0 * Math.PI));

            WorldMatrix.Multiply(Matrix3d.RotationYawPitchRoll((float)((Heading) / 180.0 * Math.PI), (float)(Pitch / 180.0 * Math.PI), (float)(Roll / 180.0 * Math.PI)));

            if (RotationalPeriod != 0)
            {
                double rotationCurrent = (((SpaceTimeController.JNow - this.ZeroRotationDate) / RotationalPeriod) * Math.PI * 2) % (Math.PI * 2);
                WorldMatrix.Multiply(Matrix3d.RotationX(-rotationCurrent));
            }

            point = Vector3d.Scale(point, scaleFactor);

            WorldMatrix.Translate(point);

            if (StationKeeping)
            {
                WorldMatrix = Matrix3d.MultiplyMatrix(look, WorldMatrix);
            }
        }
示例#28
0
        public static bool DrawPlanets3D(RenderContext renderContext, float opacity, Vector3d centerPoint)
        {
            InitPlanetResources(renderContext);

            double distss = UiTools.SolarSystemToMeters(renderContext.SolarSystemCameraDistance);

            float moonFade = (float)Math.Min(1, Math.Max(Util.Log10(distss) - 7.3, 0));

            float fade = (float)Math.Min(1, Math.Max(Util.Log10(distss) - 8.6, 0));

            if (Settings.Active.SolarSystemOrbits && fade > 0)
            {

                for (int ii = 1; ii < 10; ii++)
                {
                    int id = ii;

                    if (ii == 9)
                    {
                        id = 19;
                    }

                    double angle = Math.Atan2(planet3dLocations[id].Z, planet3dLocations[id].X);

                    DrawSingleOrbit(renderContext, planetColors[id], id, centerPoint, angle, planet3dLocations[id], fade);
                }

            }

            drawOrder.Clear();

            Vector3d camera = renderContext.CameraPosition.Copy();
            for (int planetId = 0; planetId < 14; planetId++)
            {
                if (!planetLocations[planetId].Eclipsed)
                {
                    Vector3d distVector = Vector3d.SubtractVectors(camera,Vector3d.SubtractVectors(planet3dLocations[planetId],centerPoint));

                    if (!drawOrder.ContainsKey(distVector.Length()))
                    {
                        drawOrder[distVector.Length()] = planetId;
                    }
                }
            }

            Vector3d distVectorEarth = Vector3d.SubtractVectors(camera, Vector3d.SubtractVectors(planet3dLocations[(int)SolarSystemObjects.Earth], centerPoint));
            if (!drawOrder.ContainsKey(distVectorEarth.Length()))
            {
                drawOrder[distVectorEarth.Length()] = (int)SolarSystemObjects.Earth;
            }

            //for (int planetId = 0; planetId < 14; planetId++)
            //{
            //    if (!planetLocations[planetId].Eclipsed)
            //    {
            //        DrawPlanet3d( renderContext, planetId, centerPoint);
            //    }
            //}
             //   DrawPlanet3d(renderContext, (int)SolarSystemObjects.Earth, centerPoint);

            foreach (double key in drawOrder.Keys)
            {
                int planetId = drawOrder[key];
                DrawPlanet3d(renderContext, planetId, centerPoint);
            }

            return true;
        }
        public override bool CreateGeometry(RenderContext renderContext)
        {
            base.CreateGeometry(renderContext);

            if (GeometryCreated)
            {
                return(true);
            }

            Bitmap bmp = null;

            if (dataset.WcsImage != null)
            {
                WcsImage wcsImage = dataset.WcsImage as WcsImage;
                bmp       = wcsImage.GetBitmap();
                texture2d = bmp.GetTexture();

                if (bmp.Height != wcsImage.SizeY)
                {
                    PixelCenterY += bmp.Height - wcsImage.SizeY;
                }
            }

            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }


            ComputeMatrix();

            if (bmp != null && renderContext.gl != null)
            {
                Height = bmp.Height;
                Width  = bmp.Width;
            }
            else
            {
                Height = texture.NaturalHeight;
                Width  = texture.NaturalWidth;
            }
            double latMin = 0 + (ScaleY * (Height - PixelCenterY));
            double latMax = 0 - (ScaleY * PixelCenterY);
            double lngMin = 0 + (ScaleX * PixelCenterX);
            double lngMax = 0 - (ScaleX * (Width - PixelCenterX));


            TopLeft     = GeoTo3dTan(latMin, lngMin);
            BottomRight = GeoTo3dTan(latMax, lngMax);
            TopRight    = GeoTo3dTan(latMin, lngMax);
            BottomLeft  = GeoTo3dTan(latMax, lngMin);



            Vector3d topCenter    = Vector3d.Lerp(TopLeft, TopRight, .5f);
            Vector3d bottomCenter = Vector3d.Lerp(BottomLeft, BottomRight, .5f);
            Vector3d center       = Vector3d.Lerp(topCenter, bottomCenter, .5f);
            Vector3d rightCenter  = Vector3d.Lerp(TopRight, BottomRight, .5f);
            Vector3d leftCenter   = Vector3d.Lerp(TopLeft, BottomLeft, .5f);


            if (renderContext.gl == null)
            {
                vertexList = new List <PositionTexture>();

                vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height));

                childTriangleList = new List <Triangle>();

                if (dataset.BottomsUp)
                {
                    childTriangleList.Add(Triangle.Create(0, 1, 2));
                    childTriangleList.Add(Triangle.Create(2, 1, 3));
                }
                else
                {
                    childTriangleList.Add(Triangle.Create(0, 2, 1));
                    childTriangleList.Add(Triangle.Create(2, 3, 1));
                }

                int count = 3;
                while (count-- > 1)
                {
                    List <Triangle> newList = new List <Triangle>();
                    foreach (Triangle tri in childTriangleList)
                    {
                        tri.SubDivide(newList, vertexList);
                    }
                    childTriangleList = newList;
                }

                double miter = .6 / (Width / 256);
                foreach (Triangle tri in childTriangleList)
                {
                    PositionTexture p1 = vertexList[tri.A];
                    PositionTexture p2 = vertexList[tri.B];
                    PositionTexture p3 = vertexList[tri.C];


                    RenderTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, texture, Level, miter));
                }
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }
示例#30
0
        public static void DrawSaturnsRings(RenderContext renderContext, bool front, double distance)
        {
            if (RingsTriangleLists[0] == null)
            {
                ringImage =  (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)ringImage;

                //texture.AddEventListener("load", delegate(ElementEvent e)
                //{
                //    texReady = true;
                //    Downloading = false;
                //    errored = false;
                //    ReadyToRender = texReady && (DemReady || !demTile);
                //    RequestPending = false;
                //    TileCache.RemoveFromQueue(this.Key, true);
                //    MakeTexture();
                //}, false);

                //texture.AddEventListener("error", delegate(ElementEvent e)
                //{
                //    Downloading = false;
                //    ReadyToRender = false;
                //    errored = true;
                //    RequestPending = false;
                //    TileCache.RemoveFromQueue(this.Key, true);
                //}, false);

                xdomimg.crossOrigin = "anonymous";
                ringImage.Src = "/webclient/images/saturnringsshadow.png";

                RingsTriangleLists[0] = new List<RenderTriangle>();
                RingsTriangleLists[1] = new List<RenderTriangle>();

                double ringSize = 2.25;

                Vector3d TopLeft = Vector3d.Create(-ringSize, 0, -ringSize);
                Vector3d TopRight = Vector3d.Create(ringSize, 0, -ringSize);
                Vector3d BottomLeft = Vector3d.Create(-ringSize, 0, ringSize);
                Vector3d BottomRight = Vector3d.Create(ringSize, 0, ringSize);
                Vector3d center = Vector3d.Create(0, 0, 0);
                Vector3d leftCenter = Vector3d.Create(-ringSize, 0, 0);
                Vector3d topCenter = Vector3d.Create(0, 0, -ringSize);
                Vector3d bottomCenter = Vector3d.Create(0, 0, ringSize);
                Vector3d rightCenter = Vector3d.Create(ringSize, 0, 0);

                int level = 6;
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(TopLeft, 0, 0, 1024, 1024), PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), ringImage, level));
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, 0.5, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), ringImage, level));
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), PositionTexture.CreatePosSize(TopRight, 1, 0, 1024, 1024), ringImage, level));
                //RingsTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(topCenter, .5, 0, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(leftCenter, 0, .5, 1024, 1024), PositionTexture.CreatePosSize(BottomLeft, 0, 1, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(BottomRight, 1, 1, 1024, 1024), PositionTexture.CreatePosSize(rightCenter, 1, .5, 1024, 1024), ringImage, level));
                //RingsTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePosSize(center, .5, .5, 1024, 1024), PositionTexture.CreatePosSize(bottomCenter, .5, 1, 1024, 1024), PositionTexture.CreatePosSize(BottomRight, 1, 1, 1024, 1024), ringImage, level));

                List<PositionTexture> vertexList;
                vertexList = new List<PositionTexture>();

                int Width = 1024;
                int Height = 1024;

                vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height));
                vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height));

                List<Triangle> childTriangleList = new List<Triangle>();

                //if (dataset.BottomsUp)
                //{
                //    childTriangleList.Add(Triangle.Create(0, 1, 2));
                //    childTriangleList.Add(Triangle.Create(2, 1, 3));
                //}
                //else
                {
                    childTriangleList.Add(Triangle.Create(0, 2, 1));
                    childTriangleList.Add(Triangle.Create(2, 3, 1));

                }

                int count = 5;
                while (count-- > 1)
                {
                    List<Triangle> newList = new List<Triangle>();
                    foreach (Triangle tri in childTriangleList)
                    {
                        tri.SubDivideNoNormalize(newList, vertexList);
                    }
                    childTriangleList = newList;
                }

                double miter = .6 / (Width / 256);
                foreach (Triangle tri in childTriangleList)
                {
                    PositionTexture p1 = vertexList[tri.A];
                    PositionTexture p2 = vertexList[tri.B];
                    PositionTexture p3 = vertexList[tri.C];

                    RingsTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, ringImage, level, miter));
                }

            }

            if (renderContext.gl == null)
            {
                Vector3d cam = renderContext.CameraPosition;
                Vector3d test = new Vector3d();

                //Matrix3d wv = renderContext.WV;

                Matrix3d worldLocal = Matrix3d.MultiplyMatrix(Matrix3d.RotationY(Math.Atan2(renderContext.SunPosition.X, renderContext.SunPosition.Z)), renderContext.WorldBaseNonRotating);

                Matrix3d wv = Matrix3d.MultiplyMatrix(worldLocal, renderContext.View);
                Matrix3d wvp = Matrix3d.MultiplyMatrix(wv, renderContext.Projection);
                double Width = renderContext.Width;
                double Height = renderContext.Height;

                wvp.Scale(Vector3d.Create(Width / 2, -Height / 2, 1));
                wvp.Translate(Vector3d.Create(Width / 2, Height / 2, 0));
                double td = 0;
               // RenderTriangle.CullInside = !RenderTriangle.CullInside;
                for (int i = 0; i < 2; i++)
                {
                    foreach (RenderTriangle tri in RingsTriangleLists[0])
                    {
                        //test = Vector3d.SubtractVectors(wv.Transform(tri.A.Position), cam);
                        test = wv.Transform(tri.A.Position);
                        td = test.Length();

                        bool draw = td > distance;

                        if (front)
                        {
                            draw = !draw;
                        }

                        if (draw)
                        {
                            tri.Opacity = 1;

                            tri.Draw(renderContext.Device, wvp);
                        }
                    }
                    RenderTriangle.CullInside = !RenderTriangle.CullInside;
                }
            }
            else
            {
                //todo port rings to web gl
                //renderContext.gl.enableVertexAttribArray(renderContext.vertLoc);
                //renderContext.gl.enableVertexAttribArray(renderContext.textureLoc);
                //renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                //renderContext.gl.vertexAttribPointer(renderContext.vertLoc, 3, GL.FLOAT, false, 20, 0);
                ////renderContext.gl.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                //renderContext.gl.vertexAttribPointer(renderContext.textureLoc, 2, GL.FLOAT, false, 20, 12);
                //renderContext.gl.activeTexture(GL.TEXTURE0);
                //renderContext.gl.bindTexture(GL.TEXTURE_2D, texture2d);

                ////if (tileX == TileTargetX && tileY == TileTargetY && Level == TileTargetLevel)
                ////{
                ////    renderContext.gl.bindTexture(GL.TEXTURE_2D, null);
                ////}

                //renderContext.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, GetIndexBuffer(part, accomidation));
                //renderContext.gl.drawElements(GL.TRIANGLES, TriangleCount * 3, GL.UNSIGNED_SHORT, 0);
            }
        }
示例#31
0
        // ** Begin
        public void Draw3D(RenderContext renderContext, float opacity, Vector3d centerPoint)
        {
            //    Device device = renderContext.Device;
            //    double zoom = Earth3d.MainWindow.ZoomFactor;
            //    double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 15.5) * 90;
            //    //double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 14) * 30 + 24;

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


            //    if (alpha > 254)
            //    {
            //        return;
            //    }


            //    if (orbitVertexBuffer == null)
            //    {
            //        KeplerShader.MakeVertexShader(device);
            //        InitVertexBuffer(renderContext.Device);
            //        return;
            //    }
            //    //device.DrawUserPrimitives(PrimitiveType.LineList, segments, points);


            //    //       Matrix savedWorld = device.Transform.World;

            //    //        Matrix offset = Matrix.Translation(-centerPoint.Vector3);

            //    //  device.Transform.World = device.Transform.World * offset;
            //    Vector3 cam = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;


            //    double M = elements.n * (SpaceTimeController.JNow - elements.T) * 0.01745329251994;
            //    double F = 1;
            //    if (M < 0)
            //    {
            //        F = -1;
            //    }
            //    M = Math.Abs(M) / (2 * Math.PI);
            //    M = (M - (int)(M)) * 2 * Math.PI * F;


            //    KeplerShader.UseShader(device, SpaceTimeController.JNow, cam, opacity, (float)M);

            //    device.RenderState.PointSpriteEnable = true;
            //    device.RenderState.PointScaleEnable = true;

            //    device.RenderState.PointScaleA = 0;
            //    device.RenderState.PointScaleB = 0;
            //    device.RenderState.PointScaleC = 100f;
            //    device.RenderState.ZBufferEnable = true;
            //    device.RenderState.ZBufferWriteEnable = false;
            //    device.SetTexture(0, null);

            //    device.SetStreamSource(0, orbitVertexBuffer, 0);
            //    device.VertexFormat = KeplerVertex.Format;

            //    device.RenderState.CullMode = Cull.None;
            //    device.RenderState.AlphaBlendEnable = true;
            //    device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha;
            //    device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha;

            //    //device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.One;



            //    device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
            //    device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            //    device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            //    device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            //    device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            //    device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            //    device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;

            //    device.TextureState[1].ColorOperation = TextureOperation.SelectArg1;
            //    device.TextureState[1].ColorArgument1 = TextureArgument.Current;
            //    device.TextureState[1].ColorArgument2 = TextureArgument.Constant;
            //    device.TextureState[1].AlphaOperation = TextureOperation.Modulate;
            //    device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
            //    device.TextureState[1].AlphaArgument2 = TextureArgument.Constant;

            //    device.TextureState[2].ColorOperation = TextureOperation.Disable;
            //    device.TextureState[2].AlphaOperation = TextureOperation.Disable;

            //    device.TextureState[1].ConstantColor = Color.FromArgb(255 - alpha, 255 - alpha, 255 - alpha, 255 - alpha);

            //    device.DrawPrimitives(PrimitiveType.LineStrip, 0, segmentCount - 1);
            //    device.VertexShader = null;
            //    device.RenderState.ZBufferWriteEnable = true;
            //    device.RenderState.PointSpriteEnable = false;
            //    device.RenderState.PointScaleEnable = false;
            //    // device.Transform.World = savedWorld;
        }
示例#32
0
        public override bool CreateGeometry(RenderContext renderContext)
        {
            if (GeometryCreated)
            {
                return(true);
            }
            GeometryCreated = true;

            for (int i = 0; i < 4; i++)
            {
                RenderTriangleLists[i] = new List <RenderTriangle>();
            }

            LatLngEdges edges = GetLatLngEdges();

            TopLeft     = GeoTo3dTan(edges.latMin, edges.lngMin);
            BottomRight = GeoTo3dTan(edges.latMax, edges.lngMax);
            TopRight    = GeoTo3dTan(edges.latMin, edges.lngMax);
            BottomLeft  = GeoTo3dTan(edges.latMax, edges.lngMin);

            Vector3d center       = Vector3d.MidPoint(TopLeft, BottomRight);
            Vector3d leftCenter   = Vector3d.MidPoint(TopLeft, BottomLeft);
            Vector3d rightCenter  = Vector3d.MidPoint(TopRight, BottomRight);
            Vector3d topCenter    = Vector3d.MidPoint(TopLeft, TopRight);
            Vector3d bottomCenter = Vector3d.MidPoint(BottomLeft, BottomRight);

            if (renderContext.gl == null)
            {
                RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePos(TopLeft, 0, 0), PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(topCenter, .5, 0), texture, Level));
                RenderTriangleLists[0].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, 0.5), PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(topCenter, .5, 0), texture, Level));
                RenderTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePos(topCenter, .5, 0), PositionTexture.CreatePos(rightCenter, 1, .5), PositionTexture.CreatePos(TopRight, 1, 0), texture, Level));
                RenderTriangleLists[1].Add(RenderTriangle.Create(PositionTexture.CreatePos(topCenter, .5, 0), PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(rightCenter, 1, .5), texture, Level));
                RenderTriangleLists[2].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(bottomCenter, .5, 1), PositionTexture.CreatePos(center, .5, .5), texture, Level));
                RenderTriangleLists[2].Add(RenderTriangle.Create(PositionTexture.CreatePos(leftCenter, 0, .5), PositionTexture.CreatePos(BottomLeft, 0, 1), PositionTexture.CreatePos(bottomCenter, .5, 1), texture, Level));
                RenderTriangleLists[3].Add(RenderTriangle.Create(PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(BottomRight, 1, 1), PositionTexture.CreatePos(rightCenter, 1, .5), texture, Level));
                RenderTriangleLists[3].Add(RenderTriangle.Create(PositionTexture.CreatePos(center, .5, .5), PositionTexture.CreatePos(bottomCenter, .5, 1), PositionTexture.CreatePos(BottomRight, 1, 1), texture, Level));
                ReadyToRender = true;
            }
            else
            {
                //process vertex list
                VertexBuffer = PrepDevice.createBuffer();
                PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer);
                Float32Array f32array = new Float32Array(9 * 5);
                float[]      buffer   = (float[])(object)f32array;
                int          index    = 0;

                index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1));    //1
                index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1));   //2
                index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5));      //3
                index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5));   //4
                index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5));  //5
                index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0));    //6
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0));       //7
                index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0));      //8
                PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW);

                // process index buffers

                for (int i = 0; i < 4; i++)
                {
                    index         = 0;
                    TriangleCount = 2;
                    Uint16Array ui16array = new Uint16Array(TriangleCount * 3);

                    UInt16[] indexArray = (UInt16[])(object)ui16array;
                    switch (i)
                    {
                    case 0:
                        indexArray[index++] = 7;
                        indexArray[index++] = 4;
                        indexArray[index++] = 6;
                        indexArray[index++] = 4;
                        indexArray[index++] = 3;
                        indexArray[index++] = 6;
                        break;

                    case 1:
                        indexArray[index++] = 6;
                        indexArray[index++] = 5;
                        indexArray[index++] = 8;
                        indexArray[index++] = 6;
                        indexArray[index++] = 3;
                        indexArray[index++] = 5;
                        break;

                    case 2:
                        indexArray[index++] = 4;
                        indexArray[index++] = 0;
                        indexArray[index++] = 3;
                        indexArray[index++] = 4;
                        indexArray[index++] = 1;
                        indexArray[index++] = 0;
                        break;

                    case 3:
                        indexArray[index++] = 3;
                        indexArray[index++] = 2;
                        indexArray[index++] = 5;
                        indexArray[index++] = 3;
                        indexArray[index++] = 0;
                        indexArray[index++] = 2;
                        break;
                    }
                    IndexBuffers[i] = PrepDevice.createBuffer();
                    PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]);
                    PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW);
                }
            }
            return(true);
        }
示例#33
0
        public static bool DrawEquitorialGridText(RenderContext renderContext, float opacity, Color drawColor)
        {
            MakeEquitorialGridText();

            EquTextBatch.Draw(renderContext, opacity, drawColor);
            return true;
        }
示例#34
0
        private void DrawHoverText(RenderContext RenderContext)
        {
            if (RenderContext.gl == null)
            {
                CanvasContext2D ctx = RenderContext.Device;
                ctx.Save();

                ctx.FillStyle = "White";
                ctx.Font = "15px Arial";
                ctx.FillText(hoverText, hoverTextPoint.X, hoverTextPoint.Y);
                ctx.Restore();
            }
        }
示例#35
0
        public static bool DrawGalacticGrid(RenderContext renderContext, float opacity, Color drawColor)
        {
            if (galLineList == null)
            {
                galLineList = new SimpleLineList();
                galLineList.DepthBuffered = false;

                for (double l = 0; l < 360; l += 10)
                {
                    for (double b = -80; b < 80; b += 2)
                    {
                        galLineList.AddLine(Coordinates.GalacticTo3dDouble(l, b), Coordinates.GalacticTo3dDouble(l, b + 2));
                    }
                }

                for (double b = -80; b <= 80; b += 10)
                {
                    for (double l = 0; l < 360; l += 5)
                    {
                        galLineList.AddLine(Coordinates.GalacticTo3dDouble(l, b), Coordinates.GalacticTo3dDouble(l + 5, b));
                    }
                }

                int counter = 0;
                for (double l = 0; l < 360; l += 1)
                {

                    double b = 0.25;
                    switch (counter % 10)
                    {
                        case 0:
                            counter++;
                            continue;
                        case 5:
                            b = .5;
                            break;
                    }
                    counter++;

                    galLineList.AddLine(Coordinates.GalacticTo3dDouble(l, b), Coordinates.GalacticTo3dDouble(l, -b));
                }

                counter = 0;
                for (double l = 0; l < 360; l += 90)
                {
                    counter = 0;
                    for (double b = -80; b <= 80; b += 1)
                    {
                        double width = 0.5 / 2;
                        switch (counter % 10)
                        {
                            case 0:
                                counter++;
                                continue;
                            case 5:
                                width = .5;
                                break;
                        }
                        counter++;

                        galLineList.AddLine(Coordinates.GalacticTo3dDouble(l + width, b), Coordinates.GalacticTo3dDouble(l - width, b));
                    }
                }
            }

            galLineList.DrawLines(renderContext, opacity, drawColor);

            return true;
        }
示例#36
0
        public override bool Draw(RenderContext renderContext, float opacity, bool flat)
        {
            RenderContext device = renderContext;

            //if (shaderA == null)
            //{
            //    MakeVertexShaderA(device);
            //}

            if (bufferIsFlat != flat)
            {
                CleanUp();
                bufferIsFlat = flat;
            }

            if (dirty)
            {
                PrepVertexBuffer(device, opacity);
            }

            double jNow =  SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate);

            if (triangleList2d != null)
            {
                triangleList2d.Decay = decay;
                triangleList2d.Sky = this.Astronomical;
                triangleList2d.TimeSeries = timeSeries;
                triangleList2d.JNow = jNow;
                triangleList2d.Draw(renderContext, opacity * Opacity, CullMode.Clockwise);
            }

            if (triangleList != null)
            {

                triangleList.Decay = decay;
                triangleList.Sky = this.Astronomical;
                triangleList.TimeSeries = timeSeries;
                triangleList.JNow = jNow;
                triangleList.Draw(renderContext, opacity * Opacity, CullMode.Clockwise);
            }

            if (pointList != null)
            {
                pointList.DepthBuffered = false;
                pointList.Decay = decay;
                pointList.Sky = this.Astronomical;
                pointList.TimeSeries = timeSeries;
                pointList.JNow = jNow;
                pointList.Draw(renderContext, opacity * Opacity, false);
            }

            if (lineList != null)
            {
                lineList.Sky = this.Astronomical;
                lineList.Decay = decay;
                lineList.TimeSeries = timeSeries;
                lineList.JNow = jNow;
                lineList.DrawLines(renderContext, opacity * Opacity);
            }

            if (lineList2d != null)
            {
                lineList2d.Sky = this.Astronomical;
                lineList2d.Decay = decay;
                lineList2d.TimeSeries = timeSeries;
                lineList2d.ShowFarSide = ShowFarSide;
                lineList2d.JNow = jNow;
                lineList2d.DrawLines(renderContext, opacity * Opacity);
            }

            //device.RenderState.AlphaBlendEnable = true;
            //device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha;
            //device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha;
            //device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;

            //TextureOperation oldTexOp = device.TextureState[0].ColorOperation;

            //bool zBufferEnabled = device.RenderState.ZBufferEnable;

            //if (astronomical && !bufferIsFlat)
            //{
            //    device.RenderState.ZBufferEnable = true;
            //}
            //else
            //{
            //    device.RenderState.ZBufferEnable = false;
            //}
            //device.TextureState[0].ColorOperation = TextureOperation.Disable;

            //FillMode oldMode = device.RenderState.FillMode;
            //DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);
            //device.RenderState.FillMode = FillMode.Solid;
            //device.SetTexture(0, null);
            //device.Indices = shapeFileIndex;
            //device.VertexShader = shaderA;
            //// Vector3 cam = Vector3d.TransformCoordinate(Earth3d.cameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;
            //Vector3 cam = Vector3.TransformCoordinate(renderContext.CameraPosition.Vector3, Matrix.Invert(renderContext.Device.Transform.World));
            //constantTableA.SetValue(device, cameraHandleA, new Vector4(cam.X, cam.Y, cam.Z, 1));
            //constantTableA.SetValue(device, jNowHandleA, (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate)));
            //constantTableA.SetValue(device, decayHandleA, timeSeries ? decay : 0f);

            //float adjustedScale = scaleFactor;

            //if (flat && astronomical && (markerScale == MarkerScales.World))
            //{
            //    adjustedScale = (float)(scaleFactor / (Earth3d.MainWindow.ZoomFactor / 360));
            //}
            //constantTableA.SetValue(device, scaleHandleA, (markerScale == MarkerScales.World) ? (float)adjustedScale : -(float)adjustedScale);
            //constantTableA.SetValue(device, skyHandleA, astronomical ? -1 : 1);
            //constantTableA.SetValue(device, opacityHandleA, opacity * this.Opacity);
            //constantTableA.SetValue(device, showFarSideHandleA, ShowFarSide ? 1f : 0f);

            //// Matrix matrixWVP = Earth3d.WorldMatrix * Earth3d.ViewMatrix * Earth3d.ProjMatrix;
            ////Matrix matrixWVP = device.Transform.World * device.Transform.View * device.Transform.Projection;
            //Matrix3d matrixWVP = renderContext.World * renderContext.View * renderContext.Projection;

            //constantTableA.SetValue(device, worldViewHandleA, matrixWVP.Matrix);

            //device.SetStreamSource(0, shapeFileVertex, 0);
            ////device.VertexFormat = VertexFormats.None;
            ////device.VertexDeclaration = vertexDeclA;
            //device.VertexFormat = PointVertex.Format;

            //device.RenderState.PointSpriteEnable = plotType != PlotTypes.Point;

            //device.RenderState.PointScaleEnable = (markerScale == MarkerScales.World && plotType != PlotTypes.Point) ? true : false;
            //device.RenderState.PointSize = 0;
            //device.RenderState.PointScaleA = 0;
            //device.RenderState.PointScaleB = 0;

            //device.RenderState.PointScaleC = 10000000f;

            //switch (plotType)
            //{
            //    case PlotTypes.Gaussian:
            //        device.SetTexture(0, Grids.StarProfile);
            //        break;
            //    case PlotTypes.Circle:
            //        device.SetTexture(0, CircleTexture);
            //        break;
            //    case PlotTypes.Point:
            //        device.SetTexture(0, null);
            //        break;
            //    //case PlotTypes.Square:
            //    //    device.SetTexture(0, null);
            //    //    break;
            //    //case PlotTypes.Custom:
            //    //    break;
            //    case PlotTypes.PushPin:
            //        device.SetTexture(0, PushPin.GetPushPinTexture(markerIndex));
            //        break;

            //    default:
            //        break;
            //}

            //device.RenderState.CullMode = Cull.None;
            //device.RenderState.AlphaBlendEnable = true;
            //device.RenderState.SourceBlend = Microsoft.DirectX.Direct3D.Blend.SourceAlpha;
            //if (plotType == PlotTypes.Gaussian)
            //{
            //    device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.One;
            //}
            //else
            //{
            //    device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha;
            //}

            //device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha;
            //device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            //device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            //device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            //device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            //device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            //device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;

            //device.TextureState[1].ColorOperation = TextureOperation.Disable;
            //device.TextureState[1].ColorArgument1 = TextureArgument.Current;
            //device.TextureState[1].ColorArgument2 = TextureArgument.Constant;
            //device.TextureState[1].AlphaOperation = TextureOperation.Disable;
            //device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
            //device.TextureState[1].AlphaArgument2 = TextureArgument.Constant;

            //device.TextureState[1].ConstantColor = Color.FromArgb(255, 255, 255, 255);
            ////                device.TextureState[1].ConstantColor = Color.FromArgb(0, 0, 0, 0);

            //device.DrawPrimitives(PrimitiveType.PointList, 0, shapeVertexCount);
            //device.RenderState.PointSpriteEnable = false;

            ////device.DrawUserPrimitives(PrimitiveType.LineList, segments, points);

            //device.RenderState.FillMode = oldMode;
            //device.TextureState[0].ColorOperation = oldTexOp;
            //device.VertexShader = null;

            //device.RenderState.ZBufferEnable = zBufferEnabled;
            //device.RenderState.AlphaBlendEnable = false;
            //device.RenderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlue;
            return true;
        }
示例#37
0
        public static bool DrawGalacticGridText(RenderContext renderContext, float opacity, Color drawColor)
        {
            MakeGalacticGridText();

            GalTextBatch.Draw(renderContext, opacity, drawColor);
            return true;
        }
示例#38
0
 public virtual bool PreDraw(RenderContext renderContext, float opacity)
 {
     return true;
 }
示例#39
0
        public static bool DrawPrecessionChart(RenderContext renderContext, float opacity, Color drawColor)
        {
            MakePrecessionChart();

            PrecTextBatch.Draw(renderContext, opacity, drawColor);

            precLineList.DrawLines(renderContext, opacity, drawColor);

            return true;
        }
示例#40
0
        public void InitVertexBuffer(RenderContext renderContext)
        {
            //try
            //{
            //    if (orbitVertexBuffer == null)
            //    {

            //        VertexBuffer temp = new VertexBuffer(typeof(KeplerVertex), segmentCount, device, Usage.WriteOnly, KeplerVertex.Format, Tile.PoolToUse);
            //        KeplerVertex[] points = (KeplerVertex[])temp.Lock(0, 0); // Lock the buffer (which will return our structs)
            //        for (int i = 0; i < segmentCount; i++)
            //        {
            //            points[i].Fill(elements);
            //            points[i].orbitPos = (float)i / (float)(segmentCount - 1);
            //            points[i].a /= scale;
            //            points[i].Col = orbitColor.ToArgb();
            //        }

            //        temp.Unlock();
            //        orbitVertexBuffer = temp;
            //    }
            //}
            //finally
            //{
            //}
        }
示例#41
0
 //        //private static void DrawPlanet2pnt5d(Device device, int planetID)
 //        //{
 //        //    Vector3 planetPosition = planet3dLocations[planetID];
 //        //    if (planetID < 9 )
 //        //    {
 //        //        device.SetTexture(0, planetTextures[planetID]);
 //        //    }
 //        //    else if (planetID == 9 )
 //        //    {
 //        //        device.SetTexture(0, planetTextures[19]);
 //        //    }
 //        //    else
 //        //    {
 //        //        return;
 //        //    }
 //        //    double diameter = planetDiameters[planetID];
 //        //    float radius = (double)(diameter / 2.0 );
 //        //    if (!Settings.Active.ActualPlanetScale)
 //        //    {
 //        //        if (planetID != 0)
 //        //        {
 //        //            radius *= 1000;
 //        //        }
 //        //        else
 //        //        {
 //        //            radius *= 100;
 //        //        }
 //        //    }
 //        //    CustomVertex.PositionTextured[] points = new CustomVertex.PositionTextured[4];
 //        //    Vector3 pos = planet3dLocations[planetID];
 //        //    points[0].Position = new Vector3(pos.X + radius, pos.Y, pos.Z + radius);
 //        //    points[0].Tu = 0;
 //        //    points[0].Tv = 0;
 //        //    points[1].Position = new Vector3(pos.X - radius, pos.Y, pos.Z + radius);
 //        //    points[1].Tu = 1;
 //        //    points[1].Tv = 0;
 //        //    points[2].Position = new Vector3(pos.X + radius, pos.Y, pos.Z - radius);
 //        //    points[2].Tu = 0;
 //        //    points[2].Tv = 1;
 //        //    points[3].Position = new Vector3(pos.X - radius, pos.Y, pos.Z - radius);
 //        //    points[3].Tu = 1;
 //        //    points[3].Tv = 1;
 //        //    //Matrix mat = Microsoft.DirectX.Matrix.RotationZ(rotationAngle);
 //        //    device.DrawUserPrimitives(PrimitiveType.TriangleStrip, points.Length - 2, points);
 //        //    // Render Stuff Here
 //        //}        public static bool Lighting = true;
 //        //private static void DrawPlanet3d(Device device, int planetID, Vector3d centerPoint)
 //        //{
 //        //    if (planetID == (int)SolarSystemObjects.Sun)
 //        //    {
 //        //        device.RenderState.Lighting = false;
 //        //    }
 //        //    else
 //        //    {
 //        //        device.RenderState.Lighting = Lighting;
 //        //    }
 //        //    double radius = GetAdjustedPlanetRadius(planetID);
 //        //    double rotationCurrent = 0;
 //        //    if (planetID == (int)SolarSystemObjects.Earth)
 //        //    {
 //        //        rotationCurrent = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0)/180.0 * Math.PI;
 //        //    }
 //        //    else
 //        //    {
 //        //        rotationCurrent = (((jNow - 2451545.0) / planetRotationPeriod[planetID]) * Math.PI * 2) % (Math.PI * 2);
 //        //    }
 //        //    Matrix matOld = device.Transform.World;
 //        //    matOld = device.Transform.World;
 //        //    Matrix matLocal = device.Transform.World;
 //        //    Vector3d translation = planet3dLocations[planetID]-centerPoint;
 //        //    matLocal.Scale((double)radius, (double)radius, (double)radius);
 //        //    matLocal.Multiply(Matrix.RotationY((double)-rotationCurrent));
 //        //    matLocal.Multiply(Matrix.RotationX((double)(planetTilts[planetID]*RC)));
 //        //    matLocal.Multiply(Matrix.Translation(translation.Vector3));
 //        //    device.Transform.World = matLocal;
 //        //    Earth3d.MainWindow.MakeFrustum();
 //        //    DrawSphere(device, planetTexturesMaps[planetID], GetNameFrom3dId(planetID));
 //        //    if (planetID == 5)
 //        //    {
 //        //        device.RenderState.CullMode = Cull.None;
 //        //        Color oldAmbient = device.RenderState.Ambient;
 //        //        device.RenderState.Ambient = Color.FromArgb(40, 40, 40);
 //        //        DrawRings(device);
 //        //        device.RenderState.Ambient = oldAmbient;
 //        //        device.RenderState.CullMode = Cull.Clockwise;
 //        //    }
 //        //    device.Transform.World = matOld;
 //        //    Earth3d.MainWindow.MakeFrustum();
 //        //    device.RenderState.Lighting = false;
 //        //}
 //        public static bool Lighting = true;
 public static bool IsPlanetInFrustum(RenderContext renderContext, float rad)
 {
     PlaneD[] frustum = renderContext.Frustum;
     Vector3d center =  Vector3d.Create(0, 0, 0);
     Vector4d centerV4 = new Vector4d(0, 0, 0, 1f);
     for (int i = 0; i < 6; i++)
     {
         if (frustum[i].Dot(centerV4) + rad < 0)
         {
             return false;
         }
     }
     return true;
 }
示例#42
0
        public static void ProcessQueue(RenderContext renderContext)
        {
            while(queue.Count > 0 && openThreads > 0)
            {

                double minDistance = 100000.0f;
                bool overlayTile = false;
                string maxKey = null;
                int level = 1000;

                foreach (String key in queue.Keys)
                {
                    Tile t = queue[key];
                    if (!t.RequestPending && t.InViewFrustum)
                    {

                        Vector3d vectTemp = Vector3d.MakeCopy(t.SphereCenter);

                        vectTemp.TransformByMatrics(renderContext.World);

                        if (renderContext.Space)
                        {
                            vectTemp.Subtract(Vector3d.Create(0.0f, 0.0f, -1.0f));
                        }
                        else
                        {
                            vectTemp.Subtract(renderContext.CameraPosition);
                        }

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

                        //if (t.Level < (level-1) || (distTemp < minDistance && t.Level == level))
                        bool thisIsOverlay = (t.Dataset.Projection == ProjectionType.Tangent) || (t.Dataset.Projection == ProjectionType.SkyImage);
                        if (distTemp < minDistance && (!overlayTile || thisIsOverlay))
                        {
                            minDistance = distTemp;
                            maxKey = t.Key;
                            level = t.Level;
                            overlayTile = thisIsOverlay;
                        }
                    }

                }
                if (maxKey != null)
                {
                    Tile workTile = (Tile)queue[maxKey];
                    workTile.RequestPending = true;
                    openThreads--;
                    if (openThreads < 0)
                    {
                        openThreads = 0;
                    }
                    workTile.RequestImage();
                    if (workTile.Dataset.ElevationModel )// && workTile.Dataset.Projection == ProjectionType.Toast)
                    {
                        workTile.RequestDem();
                    }
                }
                else
                {
                    return;
                }
            }
        }
示例#43
0
        private static void DrawPlanet(RenderContext renderContext, int planetID, double opacity)
        {
            AstroRaDec planetPosition = planetLocations[planetID];

            if (((planetID < 14) && planetScales[planetID] < ( renderContext.ViewCamera.Zoom / 6.0) / 400) )
            {
                if (planetID < 10 || ((planetID < 14) && planetScales[planetID] > (renderContext.ViewCamera.Zoom / 6.0) / 6400))
                {
                    Vector3d point = (Vector3d)Coordinates.RADecTo3d(planetPosition.RA, planetPosition.Dec);
                    DrawPointPlanet(renderContext, point, 3, planetColors[planetID], false);
                }
                return;
            }
            //else
            //{
            //    if ((planetID < 10 ) || (planetID < 14 && !planetPosition.Eclipsed) || (planetID > 13 && planetPosition.Shadow) )
            //    {
            //        Vector3d point = (Vector3d)Coordinates.RADecTo3d(planetPosition.RA, planetPosition.Dec);
            //        DrawPointPlanet(canvas, point, planetScales[planetID] / (Viewer.MasterView.FovScale / 3600), planetColors[planetID], false, perspectiveViewMatrix, perspectiveProjectionMatrix);
            //    }
            //}

            ImageElement brush = null;

            if (planetID < 10 || planetID == 18)
            {
                brush =  planetTextures[planetID].ImageElement;
            }
            else if (planetID < 14)
            {
                if (planetLocations[planetID].Eclipsed)
                {
                    brush = planetTextures[15].ImageElement;

                }
                else
                {
                    if (Settings.Active.ShowMoonsAsPointSource)
                    {
                        brush = planetTextures[14].ImageElement;
                    }
                    else
                    {
                        brush = planetTextures[planetID].ImageElement;
                    }
                }
            }
            else
            {
                if (!planetLocations[planetID].Shadow)
                {
                    return;
                }
                //Shadows of moons
                brush = planetTextures[15].ImageElement;
            }

            Vector3d center = Coordinates.RADecTo3d(planetPosition.RA, planetPosition.Dec);

            double rad = planetScales[planetID] / ( renderContext.FovScale / 3600) / 2;

            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);
            if (screenSpacePnt.Z < 0)
            {
                return;
            }

            if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, (Vector3d)center) < .55)
            {
                return;
            }

            // Specil Case for Saturn and Eclipse
            //if (planetID == 18 || planetID == 5)
            //{
            //    double Width = rad*2;
            //    double Height = rad*2;
            //    var points = new PointCollection { new Point(screenSpacePnt.X - Width / 2, screenSpacePnt.Y - Height / 2), new Point(screenSpacePnt.X + Width / 2, screenSpacePnt.Y - Height / 2), new Point(screenSpacePnt.X + Width / 2, screenSpacePnt.Y + Height / 2), new Point(screenSpacePnt.X - Width / 2, screenSpacePnt.Y + Height / 2) };
            //    //var bitmapImage = new BitmapImage(this.sourceUri);
            //    //var imageBrush = new ImageBrush { ImageSource = bitmapImage, RelativeTransform = this.imageTransform };

            //    Polygon polygon = new Polygon { Points = points };

            //    polygon.Opacity = opacity;
            //    if (rad < 8)
            //    {
            //        SolidColorBrush fillBrush = new SolidColorBrush(planetColors[planetID]);
            //        polygon.Fill = fillBrush;
            //    }
            //    else
            //    {
            //        polygon.Fill = brush;
            //    }

            //    //RotateTransform rt = new RotateTransform();
            //    //rt.CenterX = screenSpacePnt.X;
            //    //rt.CenterY = screenSpacePnt.Y;
            //    //rt.Angle = this.RotationAngle;
            //    //polygon.RenderTransform = rt;
            //    canvas.Children.Add(polygon);
            //}
            //else
            {
                if (renderContext.gl != null)
                {
                    //todo draw in WebGL
                }
                else
                {
                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();
                    ctx.Alpha = opacity;
                    ctx.BeginPath();
                    ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                    ctx.LineWidth = 0;

                    ctx.ClosePath();
                    ctx.Clip();
                    // ctx.FillStyle = Colors.White.ToString();

                    // Draw image here
                    //     ctx.Fill();
                    ctx.DrawImage(brush, screenSpacePnt.X - rad, screenSpacePnt.Y - rad, rad * 2, rad * 2);

                    ctx.Alpha = 1.0;
                    // ctx.StrokeStyle = Colors.White.ToString();
                    //ctx.Stroke();

                    ctx.Restore();

                    //Ellipse ellipse = new Ellipse();
                    //ellipse.Width = rad * 2;
                    //ellipse.Height = ellipse.Width;
                    //ellipse.StrokeThickness = 0;
                    //ellipse.Stroke = null;
                    //ellipse.Opacity = opacity;

                    //if (rad < 8)
                    //{
                    //    SolidColorBrush fillBrush = new SolidColorBrush(planetColors[planetID]);
                    //    ellipse.Fill = fillBrush;
                    //}
                    //else
                    //{
                    //    ellipse.Fill = brush;
                    //}
                    //TranslateTransform tt = new TranslateTransform();
                    //tt.X = screenSpacePnt.X - rad;
                    //tt.Y = screenSpacePnt.Y - rad;
                    //ellipse.RenderTransform = tt;
                    //canvas.Children.Add(ellipse);
                }
            }
        }
示例#44
0
        //todo remove the stuff from draw that is redundant once predraw has run
        internal static void PreDraw(RenderContext renderContext, float opacity, bool astronomical, string referenceFrame, bool nested)
        {
            if (!AllMaps.ContainsKey(referenceFrame))
            {
                return;
            }

            LayerMap thisMap = AllMaps[referenceFrame];

            if (thisMap.ChildMaps.Count == 0 && thisMap.Layers.Count == 0)
            {
                return;
            }
            if (TourPlayer.Playing)
            {
                TourPlayer player = (TourPlayer)WWTControl.Singleton.uiController as TourPlayer;
                if (player != null)
                {
                    TourDocument tour = player.Tour;
                    if (tour.CurrentTourStop != null)
                    {
                        player.UpdateTweenPosition(-1);
                        tour.CurrentTourStop.UpdateLayerOpacity();
                        foreach (Guid key in tour.CurrentTourStop.Layers.Keys)
                        {
                            LayerInfo info = tour.CurrentTourStop.Layers[key];
                            if (LayerList.ContainsKey(info.ID))
                            {
                                LayerList[info.ID].Opacity = info.FrameOpacity;
                                LayerList[info.ID].SetParams(info.FrameParams);
                            }
                        }

                    }
                }
            }

            Matrix3d matOld = renderContext.World;
            Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating;
            double oldNominalRadius = renderContext.NominalRadius;
            if (thisMap.Frame.Reference == ReferenceFrames.Custom)
            {
                thisMap.ComputeFrame(renderContext);
                if (thisMap.Frame.ReferenceFrameType != ReferenceFrameTypes.Orbital)
                //if (true)
                {
                    renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.World);
                }
                else
                {
                    renderContext.World = Matrix3d.MultiplyMatrix(thisMap.Frame.WorldMatrix, renderContext.WorldBaseNonRotating);

                }
                renderContext.NominalRadius = thisMap.Frame.MeanRadius;
            }

            for (int pass = 0; pass < 2; pass++)
            {
                foreach (Layer layer in AllMaps[referenceFrame].Layers)
                {
                    if ((pass == 0 && layer is ImageSetLayer) || (pass == 1 && !(layer is ImageSetLayer)))
                    {
                        if (layer.Enabled) // && astronomical == layer.Astronomical)
                        {
                            double layerStart = SpaceTimeController.UtcToJulian(layer.StartTime);
                            double layerEnd = SpaceTimeController.UtcToJulian(layer.EndTime);
                            double fadeIn = SpaceTimeController.UtcToJulian(layer.StartTime) - ((layer.FadeType == FadeType.FadeIn || layer.FadeType == FadeType.Both) ? (layer.FadeSpan / 864000000) : 0);
                            double fadeOut = SpaceTimeController.UtcToJulian(layer.EndTime) + ((layer.FadeType == FadeType.FadeOut || layer.FadeType == FadeType.Both) ? (layer.FadeSpan / 864000000) : 0);

                            if (SpaceTimeController.JNow > fadeIn && SpaceTimeController.JNow < fadeOut)
                            {
                                float fadeOpacity = 1;
                                if (SpaceTimeController.JNow < layerStart)
                                {
                                    fadeOpacity = (float)((SpaceTimeController.JNow - fadeIn) / (layer.FadeSpan / 864000000));
                                }

                                if (SpaceTimeController.JNow > layerEnd)
                                {
                                    fadeOpacity = (float)((fadeOut - SpaceTimeController.JNow) / (layer.FadeSpan / 864000000));
                                }
                                if (thisMap.Frame.Reference == ReferenceFrames.Sky)
                                {
                                    layer.Astronomical = true;
                                }
                                layer.PreDraw(renderContext, opacity * fadeOpacity);
                            }
                        }
                    }

                }
            }
            if (nested)
            {
                foreach (string key in AllMaps[referenceFrame].ChildMaps.Keys)
                {
                    LayerMap map = AllMaps[referenceFrame].ChildMaps[key];
                    if ((map.Frame.Reference == ReferenceFrames.Custom || map.Frame.Reference == ReferenceFrames.Identity))
                    {
                        PreDraw(renderContext, opacity, astronomical, map.Name, nested);
                    }
                }
            }
            renderContext.NominalRadius = oldNominalRadius;
            renderContext.World = matOld;
            renderContext.WorldBaseNonRotating = matOldNonRotating;
        }
示例#45
0
        //        private static Matrix bias = Matrix.Scaling(new Vector3(.5f, .5f, .5f)) * Matrix.Translation(new Vector3(.5f, .5f, .5f));
        private static void DrawPlanet3d(RenderContext renderContext, int planetID, Vector3d centerPoint)
        {
            if (planetID == (int)SolarSystemObjects.Sun)
            {
            //    device.RenderState.Lighting = false;
            }
            else
            {
             //   device.RenderState.Lighting = Settings.Active.SolarSystemLighting;
            }

            double radius = GetAdjustedPlanetRadius(planetID);

            double rotationCurrent = 0;
            if (planetID == (int)SolarSystemObjects.Earth)
            {
                rotationCurrent = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180.0 * Math.PI;
            }
            else
            {
                rotationCurrent = (((jNow - 2451545.0) / planetRotationPeriod[planetID]) * Math.PI * 2) % (Math.PI * 2);
            }

            //Matrix3d matOldWV = renderContext.WV.Clone();

            Matrix3d matOld = renderContext.World;
            Matrix3d matOldBase = renderContext.WorldBase;
            Matrix3d matOldNonRotating = renderContext.WorldBaseNonRotating;

            Matrix3d matLocal = renderContext.World.Clone();
            Matrix3d matLocalNR = renderContext.World.Clone();

            Vector3d translation = Vector3d.SubtractVectors(planet3dLocations[planetID], centerPoint);

            matLocal.Scale(Vector3d.Create(radius, radius, radius));
            matLocal.Multiply(Matrix3d.RotationY((double)-rotationCurrent));
            matLocal.Multiply(Matrix3d.RotationX((double)(planetTilts[planetID] * RC)));
            matLocal.Multiply(Matrix3d.Translation(translation));

            matLocalNR.Scale(Vector3d.Create(radius, radius, radius));
            matLocalNR.Multiply(Matrix3d.RotationX((double)(planetTilts[planetID] * RC)));
            matLocalNR.Multiply(Matrix3d.Translation(translation));

            renderContext.World = matLocal;
            renderContext.WorldBase = matLocal.Clone();
            renderContext.WorldBaseNonRotating = matLocalNR;
            renderContext.MakeFrustum();

            float planetWidth = 1;

            if (planetID == (int)SolarSystemObjects.Saturn)
            {
                planetWidth = 3;
            }

            if (IsPlanetInFrustum(renderContext,planetWidth))
            {
                //Matrix3d matOld2 = renderContext.World.Clone();
                //Matrix3d matOldBase2 = renderContext.WorldBase.Clone();
                //Matrix3d matOldNonRotating2 = renderContext.WorldBaseNonRotating;

                Vector3d sun = planet3dLocations[0].Copy();
                Vector3d planet = planet3dLocations[planetID].Copy();

                sun = matOld.Transform(sun);
                planet = matOld.Transform(planet);

                Vector3d sunPosition = Vector3d.SubtractVectors(sun, planet);
                sunPosition.Normalize();

                renderContext.SunPosition = sunPosition;

                Vector3d loc = Vector3d.SubtractVectors(planet3dLocations[planetID], centerPoint);
                loc.Subtract(renderContext.CameraPosition);
                double dist = loc.Length();
                double sizeIndexParam = (2 * Math.Atan(.5 * (radius / dist))) / Math.PI * 180;

                int sizeIndex = 0;
                if (sizeIndexParam > 10.5)
                {
                    sizeIndex = 0;
                }
                else if (sizeIndexParam > 3.9)
                {
                    sizeIndex = 1;
                }
                else if (sizeIndexParam > .72)
                {
                    sizeIndex = 2;
                }
                else if (sizeIndexParam > 0.05)
                {
                    sizeIndex = 3;
                }
                else
                {
                    sizeIndex = 4;
                }

                //ShadowStuff
                if (planetID == (int)SolarSystemObjects.Earth && sizeIndex < 2)
                {
                    float width = Settings.Active.SolarSystemScale * .00001f;
                  //todo add shadows  centerPoint = SetupShadow(device, centerPoint, width, SolarSystemObjects.Moon);
                }
                //ShadowStuff end

                if (sizeIndex < 3)
                {
                     bool oldLighting = renderContext.Lighting;
                   //double planetDistance = Vector3d.SubtractVectors(planet3dLocations[planetID], renderContext.CameraPosition).Length();
                    if (planetID == 5)
                    {
                        renderContext.Lighting = false;
                        // DRAW BACK HALF OF RINGS
                        DrawSaturnsRings(renderContext, false, dist);
                        renderContext.Lighting = oldLighting;
                        //if (Settings.Active.SolarSystemLighting)
                        //{
                        //    SetupRingShadow(device, centerPoint, SolarSystemObjects.Saturn, rotationCurrent);
                        //}
                        // todo saturns rings DrawRings(device);

                    }

                    if (planetID == 0)
                    {
                        renderContext.Lighting = false;
                    }

                    DrawSphere(renderContext, planetID);

                    if (planetID == 5)
                    {
                        renderContext.Lighting = false;
                        DrawSaturnsRings(renderContext, true, dist);
                        // DRAW FRONT HALF OF RINGS
                        //if (Settings.Active.SolarSystemLighting)
                        //{
                        //    SetupRingShadow(device, centerPoint, SolarSystemObjects.Saturn, rotationCurrent);
                        //}
                       // todo saturns rings DrawRings(device);

                    }

                    renderContext.Lighting = oldLighting;

                }
                else
                {
                    if (planetID == 0)
                    {
                        DrawPointPlanet(renderContext, new Vector3d(), (double)(10 * planetDiameters[planetID]), planetColors[planetID], true);
                    }
                    else if (planetID < (int)SolarSystemObjects.Moon || planetID == (int)SolarSystemObjects.Earth)
                    {
                        double size = (800 * planetDiameters[planetID]);
                        DrawPointPlanet(renderContext, new Vector3d(), (double)Math.Max(.05, Math.Min(.1f, size)), planetColors[planetID], true);
                    }
                    else if (sizeIndexParam > .002)
                    {
                        double size = (800 * planetDiameters[planetID]);
                        DrawPointPlanet(renderContext, new Vector3d(), (double)Math.Max(.05, Math.Min(.1f, size)), planetColors[planetID], true);
                    }
                }
                //renderContext.World = matOld2;
                //renderContext.WorldBase = matOldBase2;
                //renderContext.WorldBaseNonRotating = matOldNonRotating2;
            }

            renderContext.World = matOld;
            renderContext.WorldBase = matOldBase;
            renderContext.WorldBaseNonRotating = matOldNonRotating;
        }
示例#46
0
        public void Draw(RenderContext renderContext, float opacity, Color color)
        {
            if (renderContext.gl == null)
            {
                Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform);

                double drawHeight = (Height / renderContext.FovAngle) * renderContext.Height / 180;

                foreach (Text3d t3d in Items)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(t3d.center);
                    if (screenSpacePnt.Z < 0)
                    {
                        continue;
                    }

                    if (Vector3d.Dot((Vector3d)viewPoint, (Vector3d)t3d.center) < .55)
                    {
                        continue;
                    }

                    Vector3d screenSpaceTop = renderContext.WVP.Transform(t3d.top);

                    double rotation = Math.Atan2(screenSpacePnt.X - screenSpaceTop.X, screenSpacePnt.Y - screenSpaceTop.Y);

                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();

                    ctx.Translate(screenSpacePnt.X, screenSpacePnt.Y);
                    ctx.Rotate(-rotation); // todo update with up vector
                    ctx.Alpha = opacity;
                    ctx.FillStyle = color.ToString();
                    ctx.Font = "normal" + " " + (false ? "bold" : "normal") + " " + Math.Round(drawHeight * 1.2).ToString() + "px " + "Arial";
                    ctx.TextBaseline = TextBaseline.Top;

                    TextMetrics tm = ctx.MeasureText(t3d.Text);

                    ctx.FillText(t3d.Text, -tm.Width / 2, -drawHeight / 2);
                    ctx.Restore();
                }
            }
            else
            {
                // gl version
                if (glyphCache == null || glyphCache.Version > glyphVersion)
                {
                    PrepareBatch();
                }
                if (glyphCache.Ready == false)
                {
                    return;
                }

                TextShader.Use(renderContext, vertexBuffer.VertexBuffer, glyphCache.Texture.Texture2d);

                renderContext.gl.drawArrays(GL.TRIANGLES, 0, vertexBuffer.Count);

            }
        }
示例#47
0
        void InitLineBuffer(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (lineBuffers.Count == 0)
                {
                    int count = linePoints.Count;

                    PositionColoredVertexBuffer lineBuffer = null;


                    PositionColored[] linePointList = null;
                    localCenter = new Vector3d();
                    if (DepthBuffered)
                    {
                        // compute the local center..
                        foreach (Vector3d point in linePoints)
                        {
                            localCenter.Add(point);
                        }
                        localCenter.X /= count;
                        localCenter.Y /= count;
                        localCenter.Z /= count;
                    }

                    int      countLeft = count;
                    int      index     = 0;
                    int      counter   = 0;
                    Vector3d temp;

                    foreach (Vector3d point in linePoints)
                    {
                        if (counter >= 100000 || linePointList == null)
                        {
                            if (lineBuffer != null)
                            {
                                lineBuffer.Unlock();
                            }
                            int thisCount = Math.Min(100000, countLeft);

                            countLeft -= thisCount;
                            lineBuffer = new PositionColoredVertexBuffer(thisCount);

                            linePointList = lineBuffer.Lock(); // Lock the buffer (which will return our structs)

                            lineBuffers.Add(lineBuffer);
                            lineBufferCounts.Add(thisCount);
                            counter = 0;
                        }

                        if (UseLocalCenters)
                        {
                            temp = Vector3d.SubtractVectors(point, localCenter);
                            linePointList[counter] = new PositionColored(temp, lineColors[index]);
                        }
                        else
                        {
                            linePointList[counter] = new PositionColored(point, lineColors[index]);
                        }
                        index++;
                        counter++;
                    }

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