Exemple #1
0
        /// <summary>
        /// Removes the faces "covered" by the current vertex and adds the newly created ones.
        /// </summary>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool CreateCone()
        {
            var currentVertexIndex = CurrentVertex;

            ConeFaceBuffer.Clear();

            for (var fIndex = 0; fIndex < AffectedFaceBuffer.Count; fIndex++)
            {
                var oldFaceIndex = AffectedFaceBuffer[fIndex];
                var oldFace      = FacePool[oldFaceIndex];

                // Find the faces that need to be updated
                var updateCount = 0;
                for (var i = 0; i < NumOfDimensions; i++)
                {
                    var af = oldFace.AdjacentFaces[i];
                    if (!AffectedFaceFlags[af]) // Tag == false when oldFaces does not contain af
                    {
                        UpdateBuffer[updateCount]  = af;
                        UpdateIndices[updateCount] = i;
                        ++updateCount;
                    }
                }

                for (var i = 0; i < updateCount; i++)
                {
                    var adjacentFace = FacePool[UpdateBuffer[i]];

                    var oldFaceAdjacentIndex = 0;
                    var adjFaceAdjacency     = adjacentFace.AdjacentFaces;
                    for (var j = 0; j < adjFaceAdjacency.Length; j++)
                    {
                        if (oldFaceIndex == adjFaceAdjacency[j])
                        {
                            oldFaceAdjacentIndex = j;
                            break;
                        }
                    }

                    var forbidden = UpdateIndices[i]; // Index of the face that corresponds to this adjacent face

                    int   oldVertexIndex;
                    int[] vertices;

                    var newFaceIndex = ObjectManager.GetFace();
                    var newFace      = FacePool[newFaceIndex];
                    vertices = newFace.Vertices;
                    for (var j = 0; j < NumOfDimensions; j++)
                    {
                        vertices[j] = oldFace.Vertices[j];
                    }
                    oldVertexIndex = vertices[forbidden];

                    int orderedPivotIndex;

                    // correct the ordering
                    if (currentVertexIndex < oldVertexIndex)
                    {
                        orderedPivotIndex = 0;
                        for (var j = forbidden - 1; j >= 0; j--)
                        {
                            if (vertices[j] > currentVertexIndex)
                            {
                                vertices[j + 1] = vertices[j];
                            }
                            else
                            {
                                orderedPivotIndex = j + 1;
                                break;
                            }
                        }
                    }
                    else
                    {
                        orderedPivotIndex = NumOfDimensions - 1;
                        for (var j = forbidden + 1; j < NumOfDimensions; j++)
                        {
                            if (vertices[j] < currentVertexIndex)
                            {
                                vertices[j - 1] = vertices[j];
                            }
                            else
                            {
                                orderedPivotIndex = j - 1;
                                break;
                            }
                        }
                    }

                    vertices[orderedPivotIndex] = CurrentVertex;

                    if (!mathHelper.CalculateFacePlane(newFace, Center))
                    {
                        return(false);
                    }

                    ConeFaceBuffer.Add(MakeDeferredFace(newFace, orderedPivotIndex, adjacentFace, oldFaceAdjacentIndex,
                                                        oldFace));
                }
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Удаляет закрытые грание текущей вершины и добовляет к новосозданным
        /// </summary>
        private bool CreateCone()
        {
            var currentVertexIndex = CurrentVertex;

            ConeFaceBuffer.Clear();

            for (int fIndex = 0; fIndex < AffectedFaceBuffer.Count; fIndex++)
            {
                var oldFaceIndex = AffectedFaceBuffer[fIndex];
                var oldFace      = FacePool[oldFaceIndex];

                // Найти грани, которые должны быть обновлены
                int updateCount = 0;
                for (int i = 0; i < Dimension; i++)
                {
                    var af = oldFace.AdjacentFaces[i];
                    if (!AffectedFaceFlags[af]) // Tag == false , когда oldFaces не содержит af
                    {
                        UpdateBuffer[updateCount]  = af;
                        UpdateIndices[updateCount] = i;
                        ++updateCount;
                    }
                }

                for (int i = 0; i < updateCount; i++)
                {
                    var adjacentFace = FacePool[UpdateBuffer[i]];

                    int oldFaceAdjacentIndex = 0;
                    var adjFaceAdjacency     = adjacentFace.AdjacentFaces;
                    for (int j = 0; j < adjFaceAdjacency.Length; j++)
                    {
                        if (oldFaceIndex == adjFaceAdjacency[j])
                        {
                            oldFaceAdjacentIndex = j;
                            break;
                        }
                    }

                    var forbidden = UpdateIndices[i]; // Индекс грани, который соответствует этой смежной грани

                    ConvexFaceInternal newFace;

                    int   oldVertexIndex;
                    int[] vertices;

                    var newFaceIndex = ObjectManager.GetFace();
                    newFace  = FacePool[newFaceIndex];
                    vertices = newFace.Vertices;
                    for (int j = 0; j < Dimension; j++)
                    {
                        vertices[j] = oldFace.Vertices[j];
                    }
                    oldVertexIndex = vertices[forbidden];

                    int orderedPivotIndex;

                    // скорректировать порядок
                    if (currentVertexIndex < oldVertexIndex)
                    {
                        orderedPivotIndex = 0;
                        for (int j = forbidden - 1; j >= 0; j--)
                        {
                            if (vertices[j] > currentVertexIndex)
                            {
                                vertices[j + 1] = vertices[j];
                            }
                            else
                            {
                                orderedPivotIndex = j + 1;
                                break;
                            }
                        }
                    }
                    else
                    {
                        orderedPivotIndex = Dimension - 1;
                        for (int j = forbidden + 1; j < Dimension; j++)
                        {
                            if (vertices[j] < currentVertexIndex)
                            {
                                vertices[j - 1] = vertices[j];
                            }
                            else
                            {
                                orderedPivotIndex = j - 1;
                                break;
                            }
                        }
                    }

                    vertices[orderedPivotIndex] = CurrentVertex;

                    if (!MathHelper.CalculateFacePlane(newFace, Center))
                    {
                        return(false);
                    }

                    ConeFaceBuffer.Add(MakeDeferredFace(newFace, orderedPivotIndex, adjacentFace, oldFaceAdjacentIndex, oldFace));
                }
            }

            return(true);
        }