static public void CreateInfoTree(StarScan.ScanNode sn, StarScan.ScanNode parent, int p, double prevmasskg, List <BodyInfo> oilist)
        {
            KeplerOrbitElements kepler = null;

            if (sn.scandata != null && sn.scandata.nSemiMajorAxis.HasValue)
            {
                kepler = new KeplerOrbitElements(true,
                                                 sn.scandata.nSemiMajorAxis.Value,
                                                 sn.scandata.nEccentricity != null ? sn.scandata.nEccentricity.Value : 0, // protect against missing data
                                                 sn.scandata.nOrbitalInclination != null ? sn.scandata.nOrbitalInclination.Value : 0,
                                                 sn.scandata.nAscendingNode != null ? sn.scandata.nAscendingNode.Value : 0,
                                                 sn.scandata.nPeriapsis != null ? sn.scandata.nPeriapsis.Value : 0,
                                                 sn.scandata.nMeanAnomaly != null ? sn.scandata.nPeriapsis.Value : 0,
                                                 sn.scandata.EventTimeUTC.ToJulianDate()
                                                 );
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"{sn.OwnName} does not have kepler info");
            }

            BodyInfo oi = new BodyInfo();

            oi.kepler      = kepler;
            oi.scannode    = sn;
            oi.index       = oilist.Count;
            oi.parentindex = p;
            oi.orbitpos    = new GLRenderDataWorldPositionColor();
            oi.bodypos     = new GLRenderDataWorldPositionColor();
            oilist.Add(oi);

            if (kepler != null)
            {
                if (prevmasskg == 0 && kepler.SemiMajorAxis > 0)
                {
                    kepler.CentralMass = kepler.CalculateMass(sn.scandata.nOrbitalPeriod.Value);
                }
                else
                {
                    kepler.CentralMass = prevmasskg;
                }
            }


            if (sn.Children != null)
            {
                foreach (var kvp in sn.Children)
                {
                    CreateInfoTree(kvp.Value, sn, oi.index, sn.scandata?.nMassKG != null ? sn.scandata.nMassKG.Value : 0, oilist);
                }
            }
        }
Esempio n. 2
0
        public void CreateBodies(string file)
        {
            string  para = File.ReadAllText(file);
            JObject jo   = JObject.Parse(para);

            starsystemnodes = StarScan.ReadJSON(jo);

            displaysubnode = 0;
            CreateBodies(starsystemnodes, displaysubnode);

            jdscaling = 0;
            currentjd = new DateTime(2021, 11, 18, 12, 0, 0).ToJulianDate();
        }
Esempio n. 3
0
        private void CreateBodies(StarScan.ScanNode node, int subnode)
        {
            rBodyObjects.Clear();

            bodyinfo = new List <BodyInfo>();

            bool sysenabled = false;

            if (subnode > 0 && node.NodeType == StarScan.ScanNodeType.barycentre && node.Children != null)
            {
                node       = node.Children.Values[subnode - 1];
                sysenabled = true;
            }

            displaycontrol.ApplyToControlOfName("sys*", (c) => { c.Visible = sysenabled; });

            BodyInfo.CreateInfoTree(node, null, -1, 0, bodyinfo);

            foreach (var o in bodyinfo)
            {
                System.Diagnostics.Debug.Write($"Body {o.scannode.OwnName} {o.scannode.scandata?.StarType} {o.scannode.scandata?.PlanetClass} Lvl {o.scannode.Level} ");

                if (o.kepler != null)
                {
                    System.Diagnostics.Debug.Write($"SMA {o.kepler.SemiMajorAxis / oneAU_m} AU {o.kepler.SemiMajorAxis / 1000} km " +
                                                   $" Ecc {o.kepler.Eccentricity} Orbital Period {o.kepler.OrbitalPeriodS / 24 / 60 / 60 / 365} Y Radius {o.scannode.scandata.nRadius} m CM {o.kepler.CentralMass} axt {o.scannode.scandata.nAxialTilt}");
                }

                System.Diagnostics.Debug.WriteLine("");

                if (o.kepler != null)
                {
                    Vector4[]     orbit = o.kepler.Orbit(currentjd, 0.1, mscaling);
                    GLRenderState lines = GLRenderState.Lines(1);
                    lines.DepthTest = false;

                    o.orbitpos.ColorIndex = node.scandata?.nRadius != null ? 0 : 1;

                    var riol = GLRenderableItem.CreateVector4(items, PrimitiveType.LineStrip, lines, orbit, o.orbitpos);
                    rBodyObjects.Add(orbitlineshader, riol);

                    GLRenderState quad = GLRenderState.Quads(cullface: false);
                    quad.DepthTest = false;
                    var s       = 100000e3f * mscaling;
                    var quadpos = new Vector4[] { new Vector4(-s, 0, -s, 1), new Vector4(-s, 0, +s, 1), new Vector4(+s, 0, +s, 1), new Vector4(+s, 0, -s, 1) };
                    var plane   = GLRenderableItem.CreateVector4(items, PrimitiveType.Quads, quad, quadpos, o.bodypos);
                    rBodyObjects.Add(bodyplaneshader, plane);
                }
            }

            int bodies = bodyinfo.Count;

            // hold planet and barycentre positions/sizes/imageno
            bodymatrixbuffer.AllocateBytes(GLBuffer.Mat4size * bodies);

            GLRenderState rt = GLRenderState.Tri();

            rt.DepthTest = false;
            var ribody = GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Triangles, rt, spherebuffer, spheretexcobuffer, bodymatrixbuffer,
                                                                      spherebuffer.Length / sizeof(float) / 4,
                                                                      ic: bodies, matrixdivisor: 1);

            rBodyObjects.Add(bodyshader, ribody);

            rifind = GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Triangles, GLRenderState.Tri(), spherebuffer, spheretexcobuffer, bodymatrixbuffer,
                                                                  spherebuffer.Length / sizeof(float) / 4,
                                                                  ic: bodies, matrixdivisor: 1);
        }