示例#1
0
        private void UpdateAttachGroupDrag(List <AttachNode> attachNodeGroup, AttachGroupType attachGroupType, Transform[] ThisPartModelTransforms, Transform[] AllVesselModelTransforms)
        {
            //This is standard single node; the blunt area is to be determined by everything near it
            if (attachGroupType == AttachGroupType.INDEPENDENT_NODE)
            {
                //Get area represented by current node
                Vector2 bounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, ThisPartModelTransforms);

                double area = (bounds.x + bounds.y);
                area *= 0.5;
                area *= area;
                area *= Math.PI;       //Calculate area based on circular cross-section

                //Get area covered by other parts
                Transform[] OtherTransforms = FARGeoUtil.ChooseNearbyModelTransforms(part, attachNodeGroup, bounds, ThisPartModelTransforms, AllVesselModelTransforms);
                Vector2     otherBounds     = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, OtherTransforms);

                double opposedArea = (otherBounds.x + otherBounds.y);
                opposedArea *= 0.5f;
                opposedArea *= opposedArea;
                opposedArea *= Math.PI;       //Calculate area based on circular cross-section

                //Debug.Log(part.partInfo.title + " Area: " + area + " Opposed area: " + opposedArea + " OtherTransforms: " + OtherTransforms.Length);

                area = FARMathUtil.Clamp(area - opposedArea, 0, double.PositiveInfinity);


                //Update attachNodeDragDict with new data
                attachNodeData newAttachNodeData = new attachNodeData();
                newAttachNodeData.areaValue = area / FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                Vector3 orientation = attachNodeGroup[0].position;

                if (Vector3d.Dot(orientation, localUpVector) > 1)
                {
                    newAttachNodeData.pitchesAwayFromUpVec = true;
                }
                else
                {
                    newAttachNodeData.pitchesAwayFromUpVec = false;
                }


                if (attachNodeDragDict.ContainsKey(orientation))
                {
                    attachNodeData tmp = attachNodeDragDict[orientation];
                    tmp.areaValue += newAttachNodeData.areaValue;
                    attachNodeDragDict[orientation] = tmp;
                }
                else
                {
                    attachNodeDragDict.Add(orientation, newAttachNodeData);
                }


                return;
            }
            //This is a group of nodes that can be used for clustered tanks/engines; the area calculated must be divided over them
            else if (attachGroupType == AttachGroupType.PARALLEL_NODES)
            {
                //Get area represented by current nodes
                Vector2 bounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, ThisPartModelTransforms);

                double area = (bounds.x + bounds.y);
                area *= 0.5;
                area *= area;
                area *= Math.PI;       //Calculate area based on circular cross-section

                //Get area covered by other parts
                Transform[] OtherTransforms = FARGeoUtil.ChooseNearbyModelTransforms(part, attachNodeGroup, bounds, ThisPartModelTransforms, AllVesselModelTransforms);
                Vector2     otherBounds     = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, OtherTransforms);

                double opposedArea = (otherBounds.x + otherBounds.y);
                opposedArea *= 0.5;
                opposedArea *= opposedArea;
                opposedArea *= Mathf.PI;       //Calculate area based on circular cross-section

                //Debug.Log(part.partInfo.title + " Area: " + area + " Opposed area: " + opposedArea + " OtherTransforms: " + OtherTransforms.Length);

                area = FARMathUtil.Clamp(area - opposedArea, 0, double.PositiveInfinity);

                //Update attachNodeDragDict with new data
                attachNodeData newAttachNodeData = new attachNodeData();
                newAttachNodeData.areaValue = area / FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                Vector3 orientation = Vector3.zero;
                foreach (AttachNode attach in attachNodeGroup)
                {
                    orientation += attach.position;
                }
                orientation /= attachNodeGroup.Count;

                if (Vector3d.Dot(orientation, localUpVector) > 1)
                {
                    newAttachNodeData.pitchesAwayFromUpVec = true;
                }
                else
                {
                    newAttachNodeData.pitchesAwayFromUpVec = false;
                }


                if (attachNodeDragDict.ContainsKey(orientation))
                {
                    attachNodeData tmp = attachNodeDragDict[orientation];
                    tmp.areaValue += newAttachNodeData.areaValue;
                    attachNodeDragDict[orientation] = tmp;
                }
                else
                {
                    attachNodeDragDict.Add(orientation, newAttachNodeData);
                }


                return;
            }
            //This represents a vertical stack of nodes, for different payload heights, multiple payload fairings, etc.  One node being used means that they are all used
            else if (attachGroupType == AttachGroupType.VERTICAL_NODES)
            {
                double     area = 0;
                AttachNode usedNode;
                Vector2    bounds      = Vector2.zero;
                Vector3    orientation = Vector3.zero;

                foreach (AttachNode attach in attachNodeGroup)
                {
                    //Get area represented by current node
                    bounds = FARGeoUtil.NodeBoundaries(part, attach, Vector3.zero, 0.05f, ThisPartModelTransforms);

                    double tmpArea = (bounds.x + bounds.y);
                    tmpArea *= 0.5;
                    tmpArea *= tmpArea;
                    tmpArea *= Math.PI;       //Calculate area based on circular cross-section

                    if (tmpArea > area)
                    {
                        area     = tmpArea;
                        usedNode = attach;
                    }
                    orientation += attach.position;
                }
                //Get area covered by other parts
                Transform[] OtherTransforms = FARGeoUtil.ChooseNearbyModelTransforms(part, attachNodeGroup, bounds, ThisPartModelTransforms, AllVesselModelTransforms);
                Vector2     otherBounds     = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, OtherTransforms);

                double opposedArea = (otherBounds.x + otherBounds.y);
                opposedArea *= 0.5;
                opposedArea *= opposedArea;
                opposedArea *= Math.PI;       //Calculate area based on circular cross-section

                area = FARMathUtil.Clamp(area - opposedArea, 0, double.PositiveInfinity);

                //Update attachNodeDragDict with new data
                attachNodeData newAttachNodeData = new attachNodeData();
                newAttachNodeData.areaValue = area / FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                orientation /= attachNodeGroup.Count;

                if (Vector3d.Dot(orientation, localUpVector) > 1)
                {
                    newAttachNodeData.pitchesAwayFromUpVec = true;
                }
                else
                {
                    newAttachNodeData.pitchesAwayFromUpVec = false;
                }


                if (attachNodeDragDict.ContainsKey(orientation))
                {
                    attachNodeData tmp = attachNodeDragDict[orientation];
                    tmp.areaValue += newAttachNodeData.areaValue;
                    attachNodeDragDict[orientation] = tmp;
                }
                else
                {
                    attachNodeDragDict.Add(orientation, newAttachNodeData);
                }

                return;
            }
        }
        private void UpdateAttachGroupDrag(List<AttachNode> attachNodeGroup, AttachGroupType attachGroupType, Transform[] ThisPartModelTransforms, Transform[] AllVesselModelTransforms)
        {
            //This is standard single node; the blunt area is to be determined by everything near it
            if (attachGroupType == AttachGroupType.INDEPENDENT_NODE)
            {
                //Get area represented by current node
                Vector2 bounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, ThisPartModelTransforms);

                double area = (bounds.x + bounds.y);
                area *= 0.5;
                area *= area;
                area *= Math.PI;       //Calculate area based on circular cross-section

                //Get area covered by other parts
                Transform[] OtherTransforms = FARGeoUtil.ChooseNearbyModelTransforms(part, attachNodeGroup, bounds, ThisPartModelTransforms, AllVesselModelTransforms);
                Vector2 otherBounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, OtherTransforms);

                double opposedArea = (otherBounds.x + otherBounds.y);
                opposedArea *= 0.5f;
                opposedArea *= opposedArea;
                opposedArea *= Math.PI;       //Calculate area based on circular cross-section

                //Debug.Log(part.partInfo.title + " Area: " + area + " Opposed area: " + opposedArea + " OtherTransforms: " + OtherTransforms.Length);

                area = FARMathUtil.Clamp(area - opposedArea, 0, double.PositiveInfinity);

                //Update attachNodeDragDict with new data
                attachNodeData newAttachNodeData = new attachNodeData();
                newAttachNodeData.areaValue = area / FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                Vector3 orientation = attachNodeGroup[0].position;

                if (Vector3d.Dot(orientation, localUpVector) > 1)
                    newAttachNodeData.pitchesAwayFromUpVec = true;
                else
                    newAttachNodeData.pitchesAwayFromUpVec = false;

                if (attachNodeDragDict.ContainsKey(orientation))
                {
                    attachNodeData tmp = attachNodeDragDict[orientation];
                    tmp.areaValue += newAttachNodeData.areaValue;
                    attachNodeDragDict[orientation] = tmp;
                }
                else
                    attachNodeDragDict.Add(orientation, newAttachNodeData);

                return;
            }
            //This is a group of nodes that can be used for clustered tanks/engines; the area calculated must be divided over them
            else if (attachGroupType == AttachGroupType.PARALLEL_NODES)
            {
                //Get area represented by current nodes
                Vector2 bounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, ThisPartModelTransforms);

                double area = (bounds.x + bounds.y);
                area *= 0.5;
                area *= area;
                area *= Math.PI;       //Calculate area based on circular cross-section

                //Get area covered by other parts
                Transform[] OtherTransforms = FARGeoUtil.ChooseNearbyModelTransforms(part, attachNodeGroup, bounds, ThisPartModelTransforms, AllVesselModelTransforms);
                Vector2 otherBounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, OtherTransforms);

                double opposedArea = (otherBounds.x + otherBounds.y);
                opposedArea *= 0.5;
                opposedArea *= opposedArea;
                opposedArea *= Mathf.PI;       //Calculate area based on circular cross-section

                //Debug.Log(part.partInfo.title + " Area: " + area + " Opposed area: " + opposedArea + " OtherTransforms: " + OtherTransforms.Length);

                area = FARMathUtil.Clamp(area - opposedArea, 0, double.PositiveInfinity);

                //Update attachNodeDragDict with new data
                attachNodeData newAttachNodeData = new attachNodeData();
                newAttachNodeData.areaValue = area / FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                Vector3 orientation = Vector3.zero;
                foreach (AttachNode attach in attachNodeGroup)
                {
                    orientation += attach.position;
                }
                orientation /= attachNodeGroup.Count;

                if (Vector3d.Dot(orientation, localUpVector) > 1)
                    newAttachNodeData.pitchesAwayFromUpVec = true;
                else
                    newAttachNodeData.pitchesAwayFromUpVec = false;

                if (attachNodeDragDict.ContainsKey(orientation))
                {
                    attachNodeData tmp = attachNodeDragDict[orientation];
                    tmp.areaValue += newAttachNodeData.areaValue;
                    attachNodeDragDict[orientation] = tmp;
                }
                else
                    attachNodeDragDict.Add(orientation, newAttachNodeData);

                return;
            }
                //This represents a vertical stack of nodes, for different payload heights, multiple payload fairings, etc.  One node being used means that they are all used
            else if (attachGroupType == AttachGroupType.VERTICAL_NODES)
            {
                double area = 0;
                AttachNode usedNode;
                Vector2 bounds = Vector2.zero;
                Vector3 orientation = Vector3.zero;

                foreach (AttachNode attach in attachNodeGroup)
                {
                    //Get area represented by current node
                    bounds = FARGeoUtil.NodeBoundaries(part, attach, Vector3.zero, 0.05f, ThisPartModelTransforms);

                    double tmpArea = (bounds.x + bounds.y);
                    tmpArea *= 0.5;
                    tmpArea *= tmpArea;
                    tmpArea *= Math.PI;       //Calculate area based on circular cross-section

                    if (tmpArea > area)
                    {
                        area = tmpArea;
                        usedNode = attach;
                    }
                    orientation += attach.position;
                }
                //Get area covered by other parts
                Transform[] OtherTransforms = FARGeoUtil.ChooseNearbyModelTransforms(part, attachNodeGroup, bounds, ThisPartModelTransforms, AllVesselModelTransforms);
                Vector2 otherBounds = FARGeoUtil.NodeBoundaries(part, attachNodeGroup, Vector3.zero, 0.05f, OtherTransforms);

                double opposedArea = (otherBounds.x + otherBounds.y);
                opposedArea *= 0.5;
                opposedArea *= opposedArea;
                opposedArea *= Math.PI;       //Calculate area based on circular cross-section

                area = FARMathUtil.Clamp(area - opposedArea, 0, double.PositiveInfinity);

                //Update attachNodeDragDict with new data
                attachNodeData newAttachNodeData = new attachNodeData();
                newAttachNodeData.areaValue = area / FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                orientation /= attachNodeGroup.Count;

                if (Vector3d.Dot(orientation, localUpVector) > 1)
                    newAttachNodeData.pitchesAwayFromUpVec = true;
                else
                    newAttachNodeData.pitchesAwayFromUpVec = false;

                if (attachNodeDragDict.ContainsKey(orientation))
                {
                    attachNodeData tmp = attachNodeDragDict[orientation];
                    tmp.areaValue += newAttachNodeData.areaValue;
                    attachNodeDragDict[orientation] = tmp;
                }
                else
                    attachNodeDragDict.Add(orientation, newAttachNodeData);

                return;
            }
        }