示例#1
0
 public void Initialize(ShipBehaviour ship, PlaneConfig configs)
 {
     Ship = ship;
     _move.Initialize(configs.GetMaxMoveSpeed, configs.GetMinMoveSpeed, configs.GetAngularSpeed);
     if (_planeFly == null)
     {
         _planeFly = new PlaneFly(this);
     }
     MaxDistancePos = Ship.GetMaxPlaneDistance;
     RestartPlane();
 }
    // Return indices of HalfEdges with vertices that have the given config
    List <short> GetConfigEdges(HEFace face, PlaneConfig config)
    {
        List <short> he  = HalfEdge.FaceHalfEdges(face, halfEdges);
        List <short> res = new List <short>();

        foreach (short s in he)
        {
            if (vertices[halfEdges[s].verIndex].config == config)
            {
                res.Add(s);
            }
        }
        return(res);
    }
示例#3
0
        private static void SaveToCfg()
        {
            ConfigNode config   = new ConfigNode();
            ConfigNode gpwsNode = new ConfigNode();

            gpwsNode.name = "GPWS_SETTINGS";
            gpwsNode.AddValue("name", "gpwsSettings");

            ConfigNode planeNode = new ConfigNode();

            PlaneConfig.Save(planeNode);
            gpwsNode.AddNode(planeNode);

            ConfigNode landerNode = new ConfigNode();

            LanderConfig.Save(landerNode);
            gpwsNode.AddNode(landerNode);

            gpwsNode.AddValue("Volume", Settings.Volume);
            gpwsNode.AddValue("UseBlizzy78Toolbar", UseBlizzy78Toolbar);

            config.AddNode(gpwsNode);
            config.Save(KSPUtil.ApplicationRootPath + "GameData/GPWS/settings.cfg", "GPWS");
        }
    // Every face should be a triangle! So call Triangulate first
    public void SplitInLeftAndRightMesh(HalfEdgeMesh left, HalfEdgeMesh right)
    {
        // Have to re-index everything :(
        Dictionary <Vector3, short> leftVertDict  = new Dictionary <Vector3, short>();
        Dictionary <Vector3, short> rightVertDict = new Dictionary <Vector3, short>();

        // First add the vertices, and get their indices
        short lVertIdx = 0;
        short rVertIdx = 0;

        foreach (HEVertex v in vertices)
        {
            HEVertex newVL = new HEVertex {
                v = v.v, heIndex = v.heIndex
            };
            HEVertex newVR = new HEVertex {
                v = v.v, heIndex = v.heIndex
            };
            if (v.config == PlaneConfig.Left)
            {
                newVL.config = PlaneConfig.Left;
                leftVertDict.Add(v.v, lVertIdx);
                left.vertices.Add(newVL);
                lVertIdx++;
            }
            else if (v.config == PlaneConfig.Right)
            {
                newVR.config = PlaneConfig.Right;
                rightVertDict.Add(v.v, rVertIdx);
                right.vertices.Add(newVR);
                rVertIdx++;
            }
            else
            {
                newVR.config = PlaneConfig.On;
                newVL.config = PlaneConfig.On;
                leftVertDict.Add(v.v, lVertIdx);
                left.vertices.Add(newVL);
                lVertIdx++;
                rightVertDict.Add(v.v, rVertIdx);
                right.vertices.Add(newVR);
                rVertIdx++;
            }
        }
        // The dicts should map old idx -> new idx...
        Dictionary <short, short> leftEdgeIdxMap  = new Dictionary <short, short>();
        Dictionary <short, short> rightEdgeIdxMap = new Dictionary <short, short>();
        Dictionary <short, short> leftFaceIdxMap  = new Dictionary <short, short>();
        Dictionary <short, short> rightFaceIdxMap = new Dictionary <short, short>();
        int lEdgeIdx = 0;
        int lFaceIdx = 0;
        int rEdgeIdx = 0;
        int rFaceIdx = 0;

        // Build the idx maps
        foreach (HalfEdge h in halfEdges)
        {
            PlaneConfig pConfig = GetFaceConfig(faces[h.faceIndex]);
            if (pConfig == PlaneConfig.Left)
            {
                leftEdgeIdxMap.Add(h.index, (short)lEdgeIdx);
                left.halfEdges.Add(h.Copy());
                lEdgeIdx++;
                if (!leftFaceIdxMap.ContainsKey(h.faceIndex))
                {
                    left.faces.Add(faces[h.faceIndex].Copy());
                    left.faces[lFaceIdx].heIndex = (short)(lEdgeIdx - 1);
                    leftFaceIdxMap.Add(h.faceIndex, (short)lFaceIdx);
                    lFaceIdx++;
                }
            }
            else if (pConfig == PlaneConfig.Right)
            {
                rightEdgeIdxMap.Add(h.index, (short)rEdgeIdx);
                right.halfEdges.Add(h.Copy());
                rEdgeIdx++;
                if (!rightFaceIdxMap.ContainsKey(h.faceIndex))
                {
                    right.faces.Add(faces[h.faceIndex].Copy());
                    right.faces[rFaceIdx].heIndex = (short)(rEdgeIdx - 1);
                    rightFaceIdxMap.Add(h.faceIndex, (short)rFaceIdx);
                    rFaceIdx++;
                }
            }
            else   // On, not possible for a face?
            {
                // ...
            }
        }
        // Update all the indices and stuff
        // Edge case is if both vertices are ON the plane, then they don't have an opposite edge
        // I think I will leave it and deal with it when triangulating the cap
        foreach (KeyValuePair <short, short> kvp in leftEdgeIdxMap)
        {
            // The edge
            left.halfEdges[kvp.Value].faceIndex = leftFaceIdxMap[halfEdges[kvp.Key].faceIndex];
            left.halfEdges[kvp.Value].nextIndex = leftEdgeIdxMap[halfEdges[kvp.Key].nextIndex];
            left.halfEdges[kvp.Value].verIndex  = leftVertDict[vertices[halfEdges[kvp.Key].verIndex].v];
            left.halfEdges[kvp.Value].index     = kvp.Value;
            // face done in loop above

            // Update vertices edge index, doesn't matter if we overwrite
            left.vertices[left.halfEdges[kvp.Value].verIndex].heIndex = kvp.Value;
        }
        foreach (KeyValuePair <short, short> kvp in rightEdgeIdxMap)
        {
            // The edge
            right.halfEdges[kvp.Value].faceIndex = rightFaceIdxMap[halfEdges[kvp.Key].faceIndex];
            right.halfEdges[kvp.Value].nextIndex = rightEdgeIdxMap[halfEdges[kvp.Key].nextIndex];
            right.halfEdges[kvp.Value].verIndex  = rightVertDict[vertices[halfEdges[kvp.Key].verIndex].v];
            right.halfEdges[kvp.Value].index     = kvp.Value;
            // face done in loop above

            // Update vertices edge index, doesn't matter if we overwrite
            right.vertices[right.halfEdges[kvp.Value].verIndex].heIndex = kvp.Value;
        }
    }