Esempio n. 1
0
        private void updatePanelPower(SuncatcherData sc)
        {
            if (!isOccludedByPart(sc.suncatcherTransform))
            {
                Vector3 normalized       = (sunTransform.position - sc.suncatcherTransform.position).normalized;
                Vector3 suncatcherVector = Vector3.zero;
                float   invertValue      = 0f;
                switch (suncatcherAngleAxis)
                {
                case Axis.XPlus:
                    suncatcherVector = sc.suncatcherTransform.right;
                    invertValue      = sc.suncatcherTransform.lossyScale.x;
                    break;

                case Axis.XNeg:
                    suncatcherVector = -sc.suncatcherTransform.right;
                    invertValue      = sc.suncatcherTransform.lossyScale.x;
                    break;

                case Axis.YPlus:
                    suncatcherVector = sc.suncatcherTransform.up;
                    invertValue      = sc.suncatcherTransform.lossyScale.y;
                    break;

                case Axis.YNeg:
                    suncatcherVector = -sc.suncatcherTransform.up;
                    invertValue      = sc.suncatcherTransform.lossyScale.y;
                    break;

                case Axis.ZPlus:
                    suncatcherVector = sc.suncatcherTransform.forward;
                    invertValue      = sc.suncatcherTransform.lossyScale.z;
                    break;

                case Axis.ZNeg:
                    suncatcherVector = -sc.suncatcherTransform.forward;
                    invertValue      = sc.suncatcherTransform.lossyScale.z;
                    break;

                default:
                    break;
                }

                if (invertValue < 0)
                {
                    suncatcherVector = -suncatcherVector;
                }
                float sunAOA   = Mathf.Clamp(Vector3.Dot(suncatcherVector, normalized), 0f, 1f);
                float distMult = (float)(vessel.solarFlux / PhysicsGlobals.SolarLuminosityAtHome);

                if (distMult == 0 && FlightGlobals.currentMainBody != null) //vessel.solarFlux == 0, so occluded by a planetary body
                {
                    occluderName = FlightGlobals.currentMainBody.name;      //just guessing..but might be occluded by the body we are orbiting?
                }

                float efficMult   = temperatureEfficCurve.Evaluate((float)part.temperature);
                float panelEnergy = resourceAmount * TimeWarp.fixedDeltaTime * sunAOA * distMult * efficMult;
                energyFlow += panelEnergy;
            }
        }
Esempio n. 2
0
        public PanelData(ModelSolarData data, Transform root)
        {
            int len = data.pivotDefinitions.Length;

            pivots = new SolarPivotData[len];
            Transform[] pivotTransforms;
            Transform   pivotTransform;

            ModelSolarData.ModelSolarDataPivot pivotData;
            for (int i = 0; i < len; i++)
            {
                pivotData       = data.pivotDefinitions[i];
                pivotTransforms = root.FindChildren(pivotData.transformName);
                pivotTransform  = pivotTransforms[pivotData.pivotIndex];
                pivots[i]       = new SolarPivotData(pivotTransform, pivotData.pivotSpeed, pivotData.sunAxis, pivotData.rotAxis);
            }

            len         = data.suncatcherDefinitions.Length;
            suncatchers = new SuncatcherData[len];
            for (int i = 0; i < len; i++)
            {
                suncatchers[i] = new SuncatcherData(data.suncatcherDefinitions[i], root);
            }
        }
Esempio n. 3
0
        private void findTransforms()
        {
            String[] suncatcherNames = SSTUUtils.parseCSV(rayTransforms);
            String[] pivotNames      = SSTUUtils.parseCSV(pivotTransforms);

            PivotData      pd;
            SuncatcherData sd;
            int            len2;

            Transform[] trs;
            String      name;

            List <PivotData> tempPivotData = new List <PivotData>();
            int len = pivotNames.Length;

            for (int i = 0; i < len; i++)
            {
                name = pivotNames[i];
                if (String.IsNullOrEmpty(name))
                {
                    MonoBehaviour.print("ERROR: Empty name for solar pivot for part: " + part);
                }
                trs  = part.transform.FindChildren(name);
                len2 = trs.Length;
                if (len2 == 0)
                {
                    MonoBehaviour.print("ERROR: Could not locate solar pivot transforms for name: " + name + " for part: " + part);
                }
                for (int k = 0; k < len2; k++)
                {
                    pd = new PivotData();
                    pd.pivotTransform     = trs[k];
                    pd.defaultOrientation = pd.pivotTransform.localRotation;
                    tempPivotData.Add(pd);
                }
            }
            pivotData = tempPivotData.ToArray();
            tempPivotData.Clear();

            List <SuncatcherData> tempSunData = new List <SuncatcherData>();

            len = suncatcherNames.Length;
            for (int i = 0; i < len; i++)
            {
                name = suncatcherNames[i];
                if (String.IsNullOrEmpty(name))
                {
                    MonoBehaviour.print("ERROR: Empty name for suncatcher for part: " + part);
                }
                trs  = part.transform.FindChildren(name);
                len2 = trs.Length;
                if (len2 == 0)
                {
                    MonoBehaviour.print("ERROR: Could not locate suncatcher transforms for name: " + name + " for part: " + part);
                }
                for (int k = 0; k < len2; k++)
                {
                    sd = new SuncatcherData();
                    sd.suncatcherTransform = trs[k];
                    tempSunData.Add(sd);
                }
            }
            suncatcherData = tempSunData.ToArray();

            Transform t1;

            if (windBreakTransformName != null && windBreakTransformName.Length > 0)
            {
                t1 = part.FindModelTransform(windBreakTransformName);
                if (t1 != null)
                {
                    windBreakTransform = t1;
                }
            }
            if (windBreakTransform == null && pivotData.Length > 0)
            {
                windBreakTransform = pivotData[0].pivotTransform;
            }//else it will use default vessel transform
        }