private void GenerateEdge(LatticeCube cube, int edgeIndex, int pointIndex, int pointIndex2)
        {
            Vector3     vector;
            LatticeEdge edge = cube.edgeArray[edgeIndex];

            if (edge.lastFrame < frameCount)
            {
                vector                    = lattice.PositionOnAxis(cube.pointArray[pointIndex], cube.pointArray[pointIndex2], edge.axis);
                edge.position             = vector;
                edge.vertexIndex          = vertexPointer;
                normals[vertexPointer]    = CalculateNormal(vector);
                vertices[vertexPointer++] = vector;
                edge.lastFrame            = frameCount;
            }
        }
            public void GenerateLattice()
            {
                // calculate the amount of cubes, points and edges based on the dimensions
                int pointArrayAmount = ((dimensionX + 1) * (dimensionY + 1) * (dimensionZ + 1));

                cubeArrayAmount = dimensionX * dimensionY * dimensionZ;
                int edgeArrayAmountTotal = (cubeArrayAmount * 3) + ((2 * dimensionX * dimensionY) + (2 * dimensionX * dimensionZ) + (2 * dimensionY * dimensionZ)) +
                                           dimensionX + dimensionY + dimensionZ;
                int edgeArrayAmountNow = edgeArrayAmountTotal + ((dimensionX * dimensionY) + (dimensionX * dimensionZ) + (dimensionY * dimensionZ)) * 2;

                cubeArray  = new LatticeCube[cubeArrayAmount];
                pointArray = new LatticePoint[pointArrayAmount];
                edgeArray  = new LatticeEdge[edgeArrayAmountNow];

                // create all edges
                for (int i = 0; i < edgeArrayAmountNow; i++)
                {
                    edgeArray[i] = new LatticeEdge(-1);
                }

                // create all points
                int pointIndex = 0;

                for (float i = 0; i <= dimensionX; i++)
                {
                    for (float j = 0; j <= dimensionY; j++)
                    {
                        for (float k = 0; k <= dimensionZ; k++)
                        {
                            pointArray[pointIndex] = new LatticePoint((i / dimensionX) - 0.5f, (j / dimensionY) - 0.5f, (k / dimensionZ) - 0.5f, system);
                            pointIndex++;
                        }
                    }
                }

                // create all cubes
                for (int i = 0; i < cubeArrayAmount; i++)
                {
                    cubeArray[i] = new LatticeCube();
                }

                LatticeCube cube;
                LatticeCube cube2;
                int         cubeIndex = 0;
                int         edgeIndex = 0;

                for (int i = 0; i < dimensionX; i++)
                {
                    for (int j = 0; j < dimensionY; j++)
                    {
                        for (int k = 0; k < dimensionZ; k++)
                        {
                            cube = cubeArray[cubeIndex];

                            cubeIndex++;

                            // set the position of the cube
                            cube.posX = i;
                            cube.posY = j;
                            cube.posZ = k;

                            // set the points of the cube
                            LatticePoint[] points = cube.pointArray;
                            points[0] = GetPoint(i, j, k);
                            points[1] = GetPoint(i + 1, j, k);
                            points[2] = GetPoint(i + 1, j + 1, k);
                            points[3] = GetPoint(i, j + 1, k);
                            points[4] = GetPoint(i, j, k + 1);
                            points[5] = GetPoint(i + 1, j, k + 1);
                            points[6] = GetPoint(i + 1, j + 1, k + 1);
                            points[7] = GetPoint(i, j + 1, k + 1);

                            LatticeEdge[] edges = cube.edgeArray;

                            // set the axis of the edges
                            edges[5]       = edgeArray[edgeIndex++];
                            edges[5].axis  = 1;
                            edges[6]       = edgeArray[edgeIndex++];
                            edges[6].axis  = 0;
                            edges[10]      = edgeArray[edgeIndex++];
                            edges[10].axis = 2;

                            // checks adjacent cubes and set their edges
                            cube2 = GetCube(i + 1, j, k);
                            if (cube2 != null)
                            {
                                cube2.edgeArray[11] = edges[10];
                                cube2.edgeArray[7]  = edges[5];
                            }

                            cube2 = GetCube(i, j + 1, k);
                            if (cube2 != null)
                            {
                                cube2.edgeArray[4] = cube.edgeArray[6];
                                cube2.edgeArray[9] = cube.edgeArray[10];
                            }

                            cube2 = GetCube(i, j + 1, k + 1);
                            if (cube2 != null)
                            {
                                cube2.edgeArray[0] = cube.edgeArray[6];
                            }

                            cube2 = GetCube(i + 1, j, k + 1);
                            if (cube2 != null)
                            {
                                cube2.edgeArray[3] = cube.edgeArray[5];
                            }

                            cube2 = GetCube(i + 1, j + 1, k);
                            if (cube2 != null)
                            {
                                cube2.edgeArray[8] = cube.edgeArray[10];
                            }

                            cube2 = GetCube(i, j, k + 1);
                            if (cube2 != null)
                            {
                                cube2.edgeArray[1] = cube.edgeArray[5];
                                cube2.edgeArray[2] = cube.edgeArray[6];
                            }

                            // set the remaining edges axis
                            if (edges[0] == null)
                            {
                                edges[0]      = edgeArray[edgeIndex++];
                                edges[0].axis = 0;
                            }

                            if (edges[1] == null)
                            {
                                edges[1]      = edgeArray[edgeIndex++];
                                edges[1].axis = 1;
                            }

                            if (edges[2] == null)
                            {
                                edges[2]      = edgeArray[edgeIndex++];
                                edges[2].axis = 0;
                            }

                            if (edges[3] == null)
                            {
                                edges[3]      = edgeArray[edgeIndex++];
                                edges[3].axis = 1;
                            }

                            if (edges[4] == null)
                            {
                                edges[4]      = edgeArray[edgeIndex++];
                                edges[4].axis = 0;
                            }

                            if (edges[7] == null)
                            {
                                edges[7]      = edgeArray[edgeIndex++];
                                edges[7].axis = 1;
                            }

                            if (edges[8] == null)
                            {
                                edges[8]      = edgeArray[edgeIndex++];
                                edges[8].axis = 2;
                            }

                            if (edges[9] == null)
                            {
                                edges[9]      = edgeArray[edgeIndex++];
                                edges[9].axis = 2;
                            }

                            if (edges[11] == null)
                            {
                                edges[11]      = edgeArray[edgeIndex++];
                                edges[11].axis = 2;
                            }
                        }
                    }
                }
            }