/// <summary> /// Must be called after the animations have been setup, so that they may be used /// to sample and properly setup default rotations for the pivot transforms /// </summary> /// <param name="node"></param> public void setupSolarPanelData(ModelSolarData[] data, Transform[] roots) { int len = data.Length; panelData = new PanelData[len]; for (int i = 0; i < len; i++) { panelData[i] = new PanelData(data[i], roots[i]); } initializeRotations(); }
private void findTransforms() { panelData.Clear(); String[] suncatcherNames = rayTransforms.Split(','); String[] pivotNames = pivotTransforms.Split(','); if (pivotNames.Length != suncatcherNames.Length) { print("ERROR: pivot and suncatcher names length not equal"); return; } PanelData pd; String pn, sn; Transform t1, t2; int length = pivotNames.Length;//lists -should- be the same size, or there will be problems for (int i = 0; i < length; i++) { pn = pivotNames[i].Trim(); sn = suncatcherNames[i].Trim(); t1 = part.FindModelTransform(pn); t2 = part.FindModelTransform(sn); if (t1 == null || t2 == null) { print("ERROR null transform found for solar panel pivot/suncather names names.. " + pn + " :: " + sn + " :: " + t1 + " ::" + t2); continue; } pd = new PanelData(); pd.pivotTransform = t1; pd.rayCastTransform = t2; pd.defaultOrientation = pd.pivotTransform.localRotation; panelData.Add(pd); } if (windBreakTransformName != null && windBreakTransformName.Length > 0) { t1 = part.FindModelTransform(windBreakTransformName); if (t1 != null) { windBreakTransform = t1; } } if (windBreakTransform == null && panelData.Count > 0) { windBreakTransform = panelData[0].pivotTransform; }//else it will use default vessel transform }
private void updatePanelRotation(PanelData pd) { if (vessel.solarFlux > 0) { //vector from pivot to sun Vector3 vector = pd.pivotTransform.InverseTransformPoint(sunTransform.position); //finding angle to turn towards based on direction of vector on a single axis float y = (float)SSTUUtils.toDegrees(Mathf.Atan2(vector.x, vector.z));// * 57.29578f; //lerp towards destination rotation by trackingSpeed amount Quaternion to = pd.pivotTransform.rotation * Quaternion.Euler(0f, y, 0f); pd.pivotTransform.rotation = Quaternion.Lerp(pd.pivotTransform.rotation, to, TimeWarp.deltaTime * this.trackingSpeed); } else { } }
private void updatePanelPower(PanelData pd) { if (!isOccludedByPart(pd.rayCastTransform)) { Vector3 normalized = (sunTransform.position - pd.rayCastTransform.position).normalized; float sunAOA = Mathf.Clamp(Vector3.Dot(pd.rayCastTransform.forward, 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; } }