Ejemplo n.º 1
0
        public Base6Directions.Direction TransformDirection(Base6Directions.Direction baseDirection)
        {
            Base6Directions.Axis axis = Base6Directions.GetAxis(baseDirection);
            int num = (int)(baseDirection % Base6Directions.Direction.Left);

            switch (axis)
            {
            case Base6Directions.Axis.ForwardBackward:
                if (num != 1)
                {
                    return(this.Forward);
                }
                return(Base6Directions.GetFlippedDirection(this.Forward));

            case Base6Directions.Axis.LeftRight:
                if (num != 1)
                {
                    return(this.Left);
                }
                return(Base6Directions.GetFlippedDirection(this.Left));
            }
            if (num != 1)
            {
                return(this.Up);
            }
            return(Base6Directions.GetFlippedDirection(this.Up));
        }
Ejemplo n.º 2
0
 public Base6Directions.Direction TransformDirectionInverse(Base6Directions.Direction baseDirection)
 {
     Base6Directions.Axis axis = Base6Directions.GetAxis(baseDirection);
     if (axis == Base6Directions.GetAxis(this.Forward))
     {
         if (baseDirection != this.Forward)
         {
             return(Base6Directions.Direction.Backward);
         }
         return(Base6Directions.Direction.Forward);
     }
     if (axis == Base6Directions.GetAxis(this.Left))
     {
         if (baseDirection != this.Left)
         {
             return(Base6Directions.Direction.Right);
         }
         return(Base6Directions.Direction.Left);
     }
     if (baseDirection != this.Up)
     {
         return(Base6Directions.Direction.Down);
     }
     return(Base6Directions.Direction.Up);
 }
Ejemplo n.º 3
0
 public long AxisValue(Base6Directions.Axis axis)
 {
     if (axis == Base6Directions.Axis.ForwardBackward)
     {
         return(this.Z);
     }
     if (axis == Base6Directions.Axis.LeftRight)
     {
         return(this.X);
     }
     return(this.Y);
 }
Ejemplo n.º 4
0
            public IntervalSampler(double min, double max, double weightMultiplier, Base6Directions.Axis axis)
            {
                m_min        = min;
                m_max        = max;
                m_axis       = axis;
                m_weightMult = weightMultiplier;

                m_totalWeight = weightMultiplier * (m_max - m_min);

                m_entries = new List <SamplingEntry>();
                m_entries.Add(new SamplingEntry(m_max, null, m_totalWeight));
            }
Ejemplo n.º 5
0
 public int AxisValue(Base6Directions.Axis axis)
 {
     if (axis == Base6Directions.Axis.ForwardBackward)
     {
         return(Z);
     }
     else if (axis == Base6Directions.Axis.LeftRight)
     {
         return(X);
     }
     Debug.Assert(axis == Base6Directions.Axis.UpDown, "Invalid axis in Vector3I.AxisProjection!");
     return(Y);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the direction that this orientation transforms to baseDirection
        /// </summary>
        public Base6Directions.Direction TransformDirectionInverse(Base6Directions.Direction baseDirection)
        {
            Base6Directions.Axis axis = Base6Directions.GetAxis(baseDirection);

            if (axis == Base6Directions.GetAxis(Forward))
            {
                return(baseDirection == Forward ? Base6Directions.Direction.Forward : Base6Directions.Direction.Backward);
            }
            if (axis == Base6Directions.GetAxis(Left))
            {
                return(baseDirection == Left ? Base6Directions.Direction.Left : Base6Directions.Direction.Right);
            }
            Debug.Assert(axis == Base6Directions.GetAxis(Up), "Direction invalid in MyBlockOrientation");
            return(baseDirection == Up ? Base6Directions.Direction.Up : Base6Directions.Direction.Down);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the direction baseDirection will point to after transformation
        /// </summary>
        public Base6Directions.Direction TransformDirection(Base6Directions.Direction baseDirection)
        {
            Base6Directions.Axis axis = Base6Directions.GetAxis(baseDirection);
            int flip = ((int)baseDirection % 2);

            if (axis == Base6Directions.Axis.ForwardBackward)
            {
                return(flip == 1 ? Base6Directions.GetFlippedDirection(Forward) : Forward);
            }
            if (axis == Base6Directions.Axis.LeftRight)
            {
                return(flip == 1 ? Base6Directions.GetFlippedDirection(Left) : Left);
            }
            Debug.Assert(axis == Base6Directions.Axis.UpDown, "Axis invalid in MyBlockOrientation");
            return(flip == 1 ? Base6Directions.GetFlippedDirection(Up) : Up);
        }
Ejemplo n.º 8
0
 private void SelectMinMax(ref BoundingBoxD bb, Base6Directions.Axis axis, out double min, out double max)
 {
     if (axis == Base6Directions.Axis.UpDown)
     {
         min = bb.Min.Y;
         max = bb.Max.Y;
     }
     else if (axis == Base6Directions.Axis.ForwardBackward)
     {
         min = bb.Min.Z;
         max = bb.Max.Z;
     }
     else
     {
         System.Diagnostics.Debug.Assert(axis == Base6Directions.Axis.LeftRight, "Invalid Axis value");
         min = bb.Min.X;
         max = bb.Max.X;
     }
     return;
 }
Ejemplo n.º 9
0
            private IntervalSampler(IntervalSampler other, double t, bool clone)
            {
                m_min         = other.m_min;
                m_max         = other.m_max;
                m_axis        = other.m_axis;
                m_weightMult  = other.m_weightMult;
                m_totalWeight = other.m_totalWeight;

                m_entries = new List <SamplingEntry>(other.m_entries);
                for (int i = 0; i < other.m_entries.Count; ++i)
                {
                    m_entries[i] = new SamplingEntry(other.m_entries[i]);
                }

                Multiply(t);

                // If we are not cloning, we are splitting, so we have to multiply the remnant as well
                if (!clone)
                {
                    other.Multiply(1.0 - t);
                }
            }
            public MyGravitonThruster(IMyGravityGenerator gravGen, List <SharedMass> allMass)
            {
                m_gravGen = gravGen;
                //m_enabled = m_gravGen.Enabled;


                //Correction de l'orientation du thruster (pour qu'ils poussent tous dans la même direction
                switch (m_gravGen.Orientation.Up)
                {
                case Base6Directions.Direction.Right:
                    axe = Base6Directions.Axis.LeftRight;
                    m_orientationThrusterCorrection = -1;
                    break;

                case Base6Directions.Direction.Left:
                    axe = Base6Directions.Axis.LeftRight;
                    m_orientationThrusterCorrection = 1;
                    break;

                case Base6Directions.Direction.Up:
                    axe = Base6Directions.Axis.UpDown;
                    m_orientationThrusterCorrection = -1;
                    break;

                case Base6Directions.Direction.Down:
                    axe = Base6Directions.Axis.UpDown;
                    m_orientationThrusterCorrection = 1;
                    break;

                case Base6Directions.Direction.Forward:
                    axe = Base6Directions.Axis.ForwardBackward;
                    m_orientationThrusterCorrection = 1;
                    break;

                case Base6Directions.Direction.Backward:
                    axe = Base6Directions.Axis.ForwardBackward;
                    m_orientationThrusterCorrection = -1;
                    break;
                }


                Vector3 gravityFeild = new Vector3(); //On réoriente le vector "Gravity feild" pour que sa zone corresponde aux coordonées des autres elements de la grille

                switch (axe)
                {
                case Base6Directions.Axis.LeftRight:
                    gravityFeild.X = m_gravGen.FieldSize.Y / 5f;                             //On divise par 2.5 car 1 bloc fait 2.5 de coté, et aussi par 2, car on souhaite avoir le rayon à la place du diamètre diamètre. Donc 5
                    if (m_gravGen.Orientation.Forward <= Base6Directions.Direction.Backward) // ForwardBackward
                    {
                        gravityFeild.Y = m_gravGen.FieldSize.X / 5f;
                        gravityFeild.Z = m_gravGen.FieldSize.Z / 5f;
                    }
                    else     // UpDown
                    {
                        gravityFeild.Y = m_gravGen.FieldSize.Z / 5f;
                        gravityFeild.Z = m_gravGen.FieldSize.X / 5f;
                    }
                    break;

                case Base6Directions.Axis.UpDown:
                    gravityFeild.Y = m_gravGen.FieldSize.Y / 5f;
                    if (m_gravGen.Orientation.Forward <= Base6Directions.Direction.Backward)     // ForwardBackward
                    {
                        gravityFeild.X = m_gravGen.FieldSize.X / 5f;
                        gravityFeild.Z = m_gravGen.FieldSize.Z / 5f;
                    }
                    else     // LeftRight
                    {
                        gravityFeild.X = m_gravGen.FieldSize.Z / 5f;
                        gravityFeild.Z = m_gravGen.FieldSize.X / 5f;
                    }
                    break;

                case Base6Directions.Axis.ForwardBackward:
                    gravityFeild.Z = m_gravGen.FieldSize.Y / 5f;
                    if (m_gravGen.Orientation.Forward <= Base6Directions.Direction.Right)     // LeftRight
                    {
                        gravityFeild.X = m_gravGen.FieldSize.X / 5f;
                        gravityFeild.Y = m_gravGen.FieldSize.Z / 5f;
                    }
                    else     // UpDown
                    {
                        gravityFeild.X = m_gravGen.FieldSize.Z / 5f;
                        gravityFeild.Y = m_gravGen.FieldSize.X / 5f;
                    }
                    break;
                }

                //On récupère la liste des masses artificielles qui sont dans le champ de gravité
                Vector3 distance = new Vector3();

                m_position = new Vector3D(0, 0, 0);

                IMyVirtualMass mass;

                foreach (SharedMass shrMass in allMass)
                {
                    mass     = shrMass.mass;
                    distance = mass.Position - m_gravGen.Position;
                    if (Math.Abs(distance.X) <= gravityFeild.X &&
                        Math.Abs(distance.Y) <= gravityFeild.Y &&
                        Math.Abs(distance.Z) <= gravityFeild.Z)
                    {
                        m_mass.Add(shrMass);
                        m_position += mass.Position * mass.VirtualMass;
                    }
                }

                m_artificialMass_kg = m_mass.Sum(shrmass => shrmass.mass.VirtualMass);
                m_maximumThrust_kN  = 9.81f * m_artificialMass_kg / 1000;

                if (m_artificialMass_kg > 0)
                {
                    m_position = (m_position * 2.5D) / m_artificialMass_kg;
                }
                else
                {
                    m_position = m_gravGen.Position * 2.5D;
                }
            }
            private IntervalSampler(IntervalSampler other, double t, bool clone)
            {
                m_min = other.m_min;
                m_max = other.m_max;
                m_axis = other.m_axis;
                m_weightMult = other.m_weightMult;
                m_totalWeight = other.m_totalWeight;

                m_entries = new List<SamplingEntry>(other.m_entries);
                for (int i = 0; i < other.m_entries.Count; ++i)
                {
                    m_entries[i] = new SamplingEntry(other.m_entries[i]);
                }

                Multiply(t);

                // If we are not cloning, we are splitting, so we have to multiply the remnant as well
                if (!clone)
                {
                    other.Multiply(1.0 - t);
                }
            }
            public IntervalSampler(double min, double max, double weightMultiplier, Base6Directions.Axis axis)
            {
                m_min = min;
                m_max = max;
                m_axis = axis;
                m_weightMult = weightMultiplier;

                m_totalWeight = weightMultiplier * (m_max - m_min);

                m_entries = new List<SamplingEntry>();
                m_entries.Add(new SamplingEntry(m_max, null, m_totalWeight));
            }
Ejemplo n.º 13
0
            public void Subtract(ref BoundingBoxD originalBox, ref BoundingBoxD bb)
            {
                double min, max;

                SelectMinMax(ref bb, m_axis, out min, out max);

                bool minInserted = false;

                double prevLimit = m_min;
                double cumul     = 0.0;

                for (int i = 0; i < m_entries.Count; ++i)
                {
                    SamplingEntry entry = m_entries[i];

                    if (!minInserted)
                    {
                        if (entry.UpperLimit >= min)
                        {
                            if (entry.UpperLimit == min)
                            {
                                minInserted = true;
                            }
                            else // (entry.UpperLimit > min)
                            {
                                if (prevLimit == min)
                                {
                                    minInserted = true;
                                    i--;
                                    continue;
                                }

                                minInserted = true;
                                SamplingEntry insertedEntry = SamplingEntry.Divide(ref entry, prevLimit, cumul, m_weightMult, min);
                                m_entries[i] = entry;
                                m_entries.Insert(i, insertedEntry);

                                entry = insertedEntry;
                            }
                        }
                    }
                    else
                    {
                        if (prevLimit < max)
                        {
                            if (entry.UpperLimit > max)
                            {
                                SamplingEntry insertedEntry = SamplingEntry.Divide(ref entry, prevLimit, cumul, m_weightMult, max);
                                m_entries[i] = entry;
                                m_entries.Insert(i, insertedEntry);
                                entry = insertedEntry;
                            }

                            if (entry.UpperLimit <= max)
                            {
                                if (entry.Sampler == null)
                                {
                                    if (m_axis == Base6Directions.Axis.ForwardBackward)
                                    {
                                        entry.Full             = true;
                                        entry.CumulativeWeight = cumul;
                                    }
                                    else
                                    {
                                        if (entry.Full == false) // Full entries can be kept as they are
                                        {
                                            Base6Directions.Axis nextAxis = m_axis == Base6Directions.Axis.LeftRight ? Base6Directions.Axis.UpDown : Base6Directions.Axis.ForwardBackward;

                                            double min2, max2;
                                            SelectMinMax(ref originalBox, nextAxis, out min2, out max2);

                                            double range         = m_max - m_min;
                                            double volume        = m_weightMult * range;
                                            double relativeWidth = (entry.UpperLimit - prevLimit) / range;
                                            double newRange      = max2 - min2;

                                            entry.Sampler = new IntervalSampler(min2, max2, (volume * relativeWidth) / newRange, nextAxis);
                                        }
                                    }
                                }
                                if (entry.Sampler != null)
                                {
                                    entry.Sampler.Subtract(ref originalBox, ref bb);
                                    entry.CumulativeWeight = cumul + entry.Sampler.TotalWeight;
                                }
                                m_entries[i] = entry;
                            }
                        }
                        else
                        {
                            if (entry.Sampler == null)
                            {
                                if (entry.Full)
                                {
                                    entry.CumulativeWeight = cumul;
                                }
                                else
                                {
                                    entry.CumulativeWeight = cumul + (entry.UpperLimit - prevLimit) * m_weightMult;
                                }
                            }
                            else
                            {
                                entry.CumulativeWeight = cumul + entry.Sampler.TotalWeight;
                            }
                            m_entries[i] = entry;
                        }
                    }

                    prevLimit = entry.UpperLimit;
                    cumul     = entry.CumulativeWeight;
                }

                m_totalWeight = cumul;
            }