Beispiel #1
0
        public void UpdatePosition(OrbitingEntity theOrbit, long deltaSeconds)
        {
            double x, y;

            /// <summary>
            /// Increment the second remainder counter, and then check to see if timeSinceApogee(days) should be incremented.
            /// </summary>
            theOrbit.TimeSinceApogeeRemainder = theOrbit.TimeSinceApogeeRemainder + deltaSeconds;

            while (theOrbit.TimeSinceApogeeRemainder > Constants.TimeInSeconds.Day)
            {
                theOrbit.TimeSinceApogee          = theOrbit.TimeSinceApogee + 1;
                theOrbit.TimeSinceApogeeRemainder = theOrbit.TimeSinceApogeeRemainder - Constants.TimeInSeconds.Day;
            }

            /// <summary>
            /// if timeSinceApogee is greater than the orbital period then the orbital period should be safe to subtract without changing anything about how the orbit works.
            /// Orbital Period needs to be converted to seconds.
            /// </summary>
            while (theOrbit.TimeSinceApogee > (long)(theOrbit.OrbitalPeriod))
            {
                theOrbit.TimeSinceApogee = theOrbit.TimeSinceApogee - (long)(theOrbit.OrbitalPeriod);
            }

            /// <summary>
            /// now get the position.
            /// </summary>
            FindCartesianPosition(theOrbit, theOrbit.TimeSinceApogee, out x, out y);
            theOrbit.Position.X = x;
            theOrbit.Position.Y = y;
        }
Beispiel #2
0
        public void FindCartesianPosition(OrbitingEntity theOrbit, long DaysSinceEpoch, out double x, out double y)
        {
            double angle, radius;

            FindPolarPosition(theOrbit, DaysSinceEpoch, out angle, out radius);
            x = -1 * radius * Math.Sin(angle);
            y = radius * Math.Cos(angle);
        }
Beispiel #3
0
 private void initOrbitPosition(OrbitingEntity entity)
 {
     if (entity.Parent != null)
     {
         entity.OrbitalPeriod     = EnviroUtilities.Period(entity.SemiMajorAxis, entity.Mass);
         entity.LongitudeOfApogee = rnd.NextDouble(0.0, 2 * Math.PI);
         entity.TimeSinceApogee   = Convert.ToInt64(rnd.NextDouble(0.0, entity.OrbitalPeriod * Constants.Units.SECONDS_PER_HOUR * 24.0));
     }
 }
Beispiel #4
0
        public CircleElement(GLEffect a_oDefaultEffect, Vector3 a_oPosition, OrbitingEntity a_oOrbitEntity, System.Drawing.Color a_oColor)
            : base()
        {
            m_oPrimaryPrimitive = new GLCircle(a_oDefaultEffect,
                                               a_oPosition,
                                               a_oOrbitEntity,
                                               a_oColor,
                                               UIConstants.Textures.DEFAULT_TEXTURE);

            m_lPrimitives.Add(m_oPrimaryPrimitive);
        }
Beispiel #5
0
        public double FindRadiusFromAngle(OrbitingEntity theOrbit, double angle)
        {
            //angle += theOrbit.LongitudeOfApogee;
            //if(angle > Math.PI * 2)
            //	angle -= Math.PI * 2;

            //double radius = theOrbit.SemiMajorAxis * (1 - theOrbit.Eccentricity * theOrbit.Eccentricity) / (1 + theOrbit.Eccentricity * Math.Cos(angle+theOrbit.LongitudeOfApogee));

            double radius = theOrbit.SemiMajorAxis * (1 - theOrbit.Eccentricity * theOrbit.Eccentricity) / (1 + theOrbit.Eccentricity * Math.Cos(angle /* + theOrbit.TrueAnomaly*/));

            return(radius);
        }
Beispiel #6
0
        public void FindCordsFromAngle(OrbitingEntity theOrbit, double angle, out double x, out double y)
        {
            //angle += theOrbit.LongitudeOfApogee;
            //if(angle > Math.PI * 2)
            //angle -= Math.PI * 2;

            //double radius = theOrbit.SemiMajorAxis * (1 - theOrbit.Eccentricity * theOrbit.Eccentricity) / (1 + theOrbit.Eccentricity * Math.Cos(angle+theOrbit.LongitudeOfApogee));

            double radius = theOrbit.SemiMajorAxis * (1 - theOrbit.Eccentricity * theOrbit.Eccentricity) / (1 + theOrbit.Eccentricity * Math.Cos(angle /* + theOrbit.TrueAnomaly*/));

            x = -1 * radius * Math.Sin(angle);
            y = radius * Math.Cos(angle);
        }
Beispiel #7
0
        public void FindPolarPosition(OrbitingEntity theOrbit, long DaysSinceEpoch, out double angle, out double radius)
        {
            long orbitPeriod = (long)(theOrbit.OrbitalPeriod);


            /// <summary>
            /// orbitFraction is essentially mean Anomaly
            /// </summary>
            //double orbitFraction = 1.0 * ((DaysSinceEpoch + theOrbit.TimeSinceApogee) % orbitPeriod) / orbitPeriod;
            double orbitFraction          = 1.0 * theOrbit.TimeSinceApogee / orbitPeriod;
            double orbitFractionRemainder = 1.0 * ((float)(theOrbit.TimeSinceApogeeRemainder / (float)Constants.TimeInSeconds.Day) / (float)orbitPeriod);

            orbitFraction = orbitFraction + orbitFractionRemainder;

#warning how can this orbit code be made more efficient?

            /// <summary>
            /// Eccentric anomaly Calculation code. I hope. this is copied from http://www.jgiesen.de/ 's Solving Kepler's Equation
            /// </summary>
            int    iteration        = 0;
            int    maxIteration     = 30;
            double delta            = Math.Pow(10, -10);
            double radian           = Math.PI / 180.0;
            double meanAnomaly      = orbitFraction * 360.0;
            double eccentricAnomaly = Math.PI;
            if (theOrbit.Eccentricity < 0.8)
            {
                eccentricAnomaly = meanAnomaly;
            }

            /// <summary>
            /// I don't know any more descriptive name for this than partial, I'm not sure what it represents.
            /// </summary>
            double partial = eccentricAnomaly - theOrbit.Eccentricity * Math.Sin((meanAnomaly * radian)) - meanAnomaly;

            while ((Math.Abs(partial) > delta) && (iteration < maxIteration))
            {
                eccentricAnomaly = eccentricAnomaly - partial / (1.0 - theOrbit.Eccentricity * Math.Cos((eccentricAnomaly * radian)));
                partial          = eccentricAnomaly - theOrbit.Eccentricity * Math.Sin((eccentricAnomaly * radian)) - meanAnomaly;
                iteration        = iteration + 1;
            }

            eccentricAnomaly = eccentricAnomaly * radian;


            /// <summary>
            /// True Anomaly Calculation code, from same place as above.
            /// </summary>

            double SinV = Math.Sin(eccentricAnomaly);
            double CosV = Math.Cos(eccentricAnomaly);

            /// <summary>
            /// I called this Numerator because that is what this particular section is in many functions. Otherwise I'm not sure if it has a more descriptive name.
            /// </summary>
            double Numerator   = Math.Sqrt(1.0 - (theOrbit.Eccentricity * theOrbit.Eccentricity));
            double trueAnomaly = Math.Atan2((Numerator * SinV), (CosV - theOrbit.Eccentricity)) /*/ radian*/;

            angle = trueAnomaly;

            theOrbit.TrueAnomaly = trueAnomaly;

            radius = theOrbit.SemiMajorAxis * (1 - theOrbit.Eccentricity * theOrbit.Eccentricity) / (1 + theOrbit.Eccentricity * Math.Cos(trueAnomaly));

            /*bool mirrorSide = false;
             *          if( orbitFraction >= 0.5)
             *          {
             *                  mirrorSide = true;
             *                  orbitFraction = 1.0 - orbitFraction;
             *          }*/



            /*if (theOrbit.Eccentricity >= 0.15)
             * {
             *
             *  String Entry = String.Format("TO:{0} E:{1} OF:{2}", theOrbit.Name, theOrbit.Eccentricity, orbitFraction);
             *  MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.Count, null, null, GameState.Instance.GameDateTime,
             *                                     GameState.Instance.LastTimestep, Entry);
             *  GameState.Instance.Factions[0].MessageLog.Add(Msg);
             * }*/


            /*
             * /// <summary>
             * /// Floor and Ceiling of orbitFraction * node Count * 2. orbit fraction appears to be between 0.0 and 0.5
             * /// </summary>
             * int lowerA = (int)(orbitFraction * m_oNodes * 2);
             * int upperA = (int)Math.Ceiling(orbitFraction * m_oNodes * 2);
             *
             * /// <summary>
             * /// Floor and ceiling of eccentricity * number of eccentricity steps.
             * /// </summar>
             * int lowerE = (int)theOrbit.Eccentricity * m_oOrbits;
             * int upperE = (int)Math.Ceiling(theOrbit.Eccentricity * m_oOrbits);
             *
             * double lowEA = m_lTable[lowerE, lowerA] + (m_lTable[lowerE, upperA] - m_lTable[lowerE, lowerA]) * (orbitFraction * m_oNodes * 2.0 - lowerA);
             * double highEA = m_lTable[upperE, lowerA] + (m_lTable[upperE, upperA] - m_lTable[upperE, lowerA]) * (orbitFraction * m_oNodes * 2.0 - lowerA);
             *
             * angle = lowEA + (highEA - lowEA) * (theOrbit.Eccentricity * m_oOrbits - lowerE);
             *
             *          if(mirrorSide)
             *                  angle = Math.PI * 2 - angle;
             *
             *          //angle += theOrbit.LongitudeOfApogee;
             *          //if(angle > Math.PI * 2)
             *          //	angle -= Math.PI * 2;
             */

            /// <summary>
            /// This is radius from true anomoaly, found a bug in the / part, changed 1 - theOrbit.Eccentricity to 1 + theOrbit.Eccentricity
            /// r = a(1 – e^2)/(1 + e cos (phi)) phi being true anomaly in this
            /// If we had the eccentric anomaly the equation would be r = a * (1 - (e * cos E)) E being the eccentric anomaly and e being eccentricity
            /// (angle+theOrbit.LongitudeOfApogee) appears to be true anomaly
            /// <summary>
#warning did we mean / (1 - theOrbit.Eccentricity despite that being incorrect? also corrected all the ones further down.
            //radius = theOrbit.SemiMajorAxis * (1 - theOrbit.Eccentricity * theOrbit.Eccentricity) / (1 + theOrbit.Eccentricity * Math.Cos(angle+theOrbit.LongitudeOfApogee));
        }
Beispiel #8
0
        public GLCircle(GLEffect a_oEffect, Vector3 a_v3Pos, OrbitingEntity a_oOrbitEntity, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Save some stuff to member vars:
            //double dKMperAUdevby10 = (Pulsar4X.Constants.Units.KM_PER_AU / 10); // we scale everthing down by 10 to avoid float buffer overflows.
            m_v3Position = a_v3Pos;
            m_v2Size.X   = 1;

            // set verts to 360, looks good at any zoom.
            int iNumOfVerts = 360;

            //create our Vertex and index arrays:
            m_aoVerticies = new GLVertex[iNumOfVerts];
            m_auiIndicies = new ushort[iNumOfVerts + 1]; // make this one longer so it can loop back around to the begining!!

            for (int i = 0; i < iNumOfVerts; ++i)
            {
                double dAngle = i * (MathHelper.TwoPi / iNumOfVerts);

                double x, y;
                a_oOrbitEntity.Orbit.GetPosition(dAngle, out x, out y);

                m_aoVerticies[i].m_v4Position.X = (float)x;
                m_aoVerticies[i].m_v4Position.Y = (float)y;
                m_aoVerticies[i].m_v4Position.Z = 0;
                m_aoVerticies[i].SetColor(a_oColor);
                m_auiIndicies[i] = (ushort)i;
            }

            // set last index:
            m_auiIndicies[iNumOfVerts] = 0;

            // Setup Matrix:
            m_m4ModelMatrix = Matrix4.Identity * Matrix4.CreateTranslation(a_v3Pos);

            // Set our shader program:
            m_oEffect = a_oEffect;

            // Load texture if specified:
            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }


            // tell Opgl about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                                                                                                             // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                                          // Lets Open GL know that this is the current active buffer object.
            GL.BufferData <GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                                                                                                  //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle);                                                                        // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //    logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                         // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);                                           // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes);                          // tells OpenGL about the 4 floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //    logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //     logger.Info("OpenGL Create Circle Primitive: " + GL.GetError().ToString());
            //#endif
        }
Beispiel #9
0
 public ProtoPlanet(Star Primary, OrbitingEntity Parent)
 {
     Planet = new Planet(Primary, Parent);
 }