Example #1
0
        public short AddVertice(VertexPositionNormalColor vertex)
        {
            short index = fNumberOfVertices;

            fVertices[fNumberOfVertices++] = vertex;
            return(index);
        }
Example #2
0
        private int AddSphereVertex(Vector3 position, Vector3 origo, Color color)
        {
            VertexPositionNormalColor vertex = new VertexPositionNormalColor();

            vertex.Position = position + origo;
            vertex.Normal   = Vector3.Zero;
            vertex.Color    = color;
            int index = AddVertice(vertex);

            return(index);
        }
Example #3
0
        private short GetIndexYZ(short[,] matrix, int y, int z,
                                 int segments,
                                 float minY, float minZ, float x, float deltaY, float deltaZ, Color color)
        {
            short index = matrix[y, z];

            if (index < 0)
            {
                float factorY = (float)y / segments;
                float factorZ = (float)z / segments;
                VertexPositionNormalColor vertex = new VertexPositionNormalColor();
                vertex.Position = new Vector3(x, minY + factorY * deltaY, minZ + factorZ * deltaZ);
                vertex.Normal   = Vector3.Zero;
                vertex.Color    = color;
                index           = AddVertice(vertex);
                matrix[y, z]    = index;
            }
            return(index);
        }
Example #4
0
        private short GetIndexXY(short[,] matrix, int x, int y,
                                 int segments,
                                 float minX, float minY, float z, float deltaX, float deltaY, Color color)
        {
            short index = matrix[x, y];

            if (index < 0)
            {
                float factorX = (float)x / segments;
                float factorY = (float)y / segments;
                VertexPositionNormalColor vertex = new VertexPositionNormalColor();
                vertex.Position = new Vector3(minX + factorX * deltaX, minY + factorY * deltaY, z);
                vertex.Normal   = Vector3.Zero;
                vertex.Color    = color;
                index           = AddVertice(vertex);
                matrix[x, y]    = index;
            }
            return(index);
        }
Example #5
0
        private short GetIndexXZ(short[,] matrix, int x, int z,
                                 int segments,
                                 float minX, float minZ, float y, float deltaX, float deltaZ, Color color)
        {
            short index = matrix[x, z];

            if (index < 0)
            {
                float factorX = (float)x / segments;
                float factorZ = (float)z / segments;
                VertexPositionNormalColor vertex = new VertexPositionNormalColor();
                vertex.Position = new Vector3(minX + factorX * deltaX, y, minZ + factorZ * deltaZ);
                vertex.Normal   = Vector3.Zero;
                vertex.Color    = color;
                index           = AddVertice(vertex);
                matrix[x, z]    = index;
            }
            return(index);
        }
Example #6
0
        public short AddVertice(VertexPositionNormalColor vertex)
        {
            PrimitiveTriangles primitive = fTriangles[fTriangles.Count - 1];

            return(primitive.AddVertice(vertex));
        }
Example #7
0
        /// <summary>
        /// Init the plane
        /// </summary>
        private void InitPlane(
            int segments,
            float minX, float maxX, float minZ, float maxZ, float defaultY,
            Color color)
        {
            if (segments > 180)
            {
                throw new Exception("To many segments");
            }

            fNumberOfSegments     = segments;
            fNumberOfPointsOnLine = segments + 1;
            fNumberOfVertices     = fNumberOfPointsOnLine * fNumberOfPointsOnLine;
            fNumberOfLines        = 2 * fNumberOfSegments * fNumberOfPointsOnLine;
            fNumberOfTriangles    = 2 * fNumberOfSegments * fNumberOfSegments;
            int index;

            // Init points
            fVertices = new VertexPositionNormalColor[fNumberOfVertices];

            Vector3 position = new Vector3();

            position.Y = defaultY;
            float deltaZ = maxZ - minZ;
            float deltaX = maxX - minX;

            for (int z = 0; z <= fNumberOfSegments; z++)
            {
                float factorZ = (float)z / fNumberOfSegments;
                position.Z = minZ + factorZ * deltaZ;
                for (int x = 0; x <= fNumberOfSegments; x++)
                {
                    float factorX = (float)x / fNumberOfSegments;
                    position.X       = minX + factorX * deltaX;
                    index            = GetIndex(x, z);
                    fVertices[index] = new VertexPositionNormalColor(position, color);
                }
            }

            // Init indices for lines
            fIndicesForLines = new short[2 * fNumberOfLines];
            index            = 0;
            for (int z = 0; z < fNumberOfPointsOnLine; z++)
            {
                for (int x = 0; x < fNumberOfSegments; x++)
                {
                    fIndicesForLines[index++] = GetIndex(x, z);
                    fIndicesForLines[index++] = GetIndex(x + 1, z);
                }
            }
            for (int z = 0; z < fNumberOfSegments; z++)
            {
                for (int x = 0; x < fNumberOfPointsOnLine; x++)
                {
                    fIndicesForLines[index++] = GetIndex(x, z);
                    fIndicesForLines[index++] = GetIndex(x, z + 1);
                }
            }

            // Init indices for triangles
            fIndicesForTriangles = new short[3 * fNumberOfTriangles];
            index = 0;
            for (int z = 0; z < fNumberOfSegments; z++)
            {
                for (int x = 0; x < fNumberOfSegments; x++)
                {
                    short i00 = GetIndex(x, z);
                    short i10 = GetIndex(x + 1, z);
                    short i01 = GetIndex(x, z + 1);
                    short i11 = GetIndex(x + 1, z + 1);

                    fIndicesForTriangles[index++] = i00;
                    fIndicesForTriangles[index++] = i10;
                    fIndicesForTriangles[index++] = i01;
                    fIndicesForTriangles[index++] = i10;
                    fIndicesForTriangles[index++] = i11;
                    fIndicesForTriangles[index++] = i01;
                }
            }
        }
Example #8
0
 /// <summary>
 /// Set a point on the plane
 /// </summary>
 /// <param name="x"></param>
 /// <param name="z"></param>
 /// <param name="point"></param>
 public void SetPoint(int x, int z, VertexPositionNormalColor point)
 {
     fVertices[GetIndex(x, z)] = point;
 }