コード例 #1
0
 private void SetConeDiameters(float topDiameter, float bottomDiameter)
 {
     if (SetShape <ProceduralShapeCone>())
     {
         ProceduralShapeCone con = part.GetModule <ProceduralShapeCone>();
         con.topDiameter    = topDiameter;
         con.bottomDiameter = bottomDiameter;
     }
     else
     {
         SetCylindricalDiameter(Math.Max(topDiameter, bottomDiameter));
     }
 }
コード例 #2
0
 private void SetConeDiameters(float topDiameter, float bottomDiameter)
 {
     if (SetShape <ProceduralShapeCone>())
     {
         ProceduralShapeCone con  = part.Modules.GetModule <ProceduralShapeCone>();
         float prevTopDiameter    = con.topDiameter;
         float prevBottomDiameter = con.bottomDiameter;
         con.topDiameter    = topDiameter;
         con.bottomDiameter = bottomDiameter;
         Notify(() => {
             con.OnShapeDimensionChanged(con.Fields["topDiameter"], prevTopDiameter);
             con.OnShapeDimensionChanged(con.Fields["bottomDiameter"], prevBottomDiameter);
         });
     }
     else
     {
         SetCylindricalDiameter(Math.Max(topDiameter, bottomDiameter));
     }
 }
コード例 #3
0
ファイル: SmartTankPart.cs プロジェクト: Fitiales/SmartTank
        public void ScaleNow()
        {
            if (HighLogic.LoadedSceneIsEditor && wetDensity > 0)
            {
                // Volume of fuel to use:
                double idealVolume = IdealTotalMass / wetDensity;

                if (part.HasModule <ProceduralShapeCylinder>())
                {
                    ProceduralShapeCylinder cyl = part.GetModule <ProceduralShapeCylinder>();
                    double radius           = 0.5 * cyl.diameter;
                    double crossSectionArea = Math.PI * radius * radius;
                    double idealLength      = idealVolume / crossSectionArea;
                    if (idealLength < radius)
                    {
                        idealLength = radius;
                    }
                    if (Math.Abs(cyl.length - idealLength) > 0.05)
                    {
                        cyl.length = (float)idealLength;
                        if (part.GetModule <ProceduralPart>().shapeName == cyl.displayName)
                        {
                            cyl.Update();
                        }
                    }
                }
                if (part.HasModule <ProceduralShapePill>())
                {
                    // We won't try to change the "fillet", so we can treat it as a constant
                    // Diameter is likewise a constant here
                    ProceduralShapePill pil = part.GetModule <ProceduralShapePill>();
                    double fillet = pil.fillet, diameter = pil.diameter;
                    double idealLength = (idealVolume * 24f / Math.PI - (10f - 3f * Math.PI) * fillet * fillet * fillet - 3f * (Math.PI - 4) * diameter * fillet * fillet) / (6f * diameter * diameter);
                    if (idealLength < 1)
                    {
                        idealLength = 1;
                    }
                    if (Math.Abs(pil.length - idealLength) > 0.05)
                    {
                        pil.length = (float)idealLength;
                        if (part.GetModule <ProceduralPart>().shapeName == pil.displayName)
                        {
                            pil.Update();
                        }
                    }
                }
                if (part.HasModule <ProceduralShapeCone>())
                {
                    ProceduralShapeCone con = part.GetModule <ProceduralShapeCone>();
                    double topDiameter = con.topDiameter, bottomDiameter = con.bottomDiameter;
                    double idealLength = idealVolume * 12f / (Math.PI * (topDiameter * topDiameter + topDiameter * bottomDiameter + bottomDiameter * bottomDiameter));
                    if (idealLength < 1)
                    {
                        idealLength = 1;
                    }
                    if (Math.Abs(con.length - idealLength) > 0.05)
                    {
                        con.length = (float)idealLength;
                        if (part.GetModule <ProceduralPart>().shapeName == con.displayName)
                        {
                            con.Update();
                        }
                    }
                }
                // BezierCone shapes not supported because they're too complicated.
                // See ProceduralShapeBezierCone.CalcVolume to see why.
            }
        }