Beispiel #1
0
        public static Mesh GetMesh(int discretisation)
        {
            StandardMesh smesh = new StandardMesh();

            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * ( float )i / ( float )discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        ( float )Math.Cos(angleVal),
                        0.0f,
                        ( float )Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(0, i, i + 1);
            }

            smesh.ComputeNormals();
            smesh.ComputeTangents();
            return(smesh.ReturnMesh());
        }
Beispiel #2
0
        /// <summary>
        /// Retourne la taille en octet d'un sommet
        /// </summary>
        public static int Size(VertexTypeD11 type)
        {
            switch (type)
            {
            case VertexTypeD11.COLOR_VERTEX:
                return(ColoredVertex.GetSize());

            case VertexTypeD11.STANDARD_VERTEX:
                return(StandardVertex.GetSize());
            }
            return(-1);
        }
Beispiel #3
0
        // Public

        // Static Methods

        /// <summary>
        ///  Retourne les informations concernant le type sommet nécessaire à DirectX
        /// </summary>
        public static InputElement[] Infos(VertexTypeD11 type)
        {
            switch (type)
            {
            case VertexTypeD11.COLOR_VERTEX:
                return(ColoredVertex.GetInfos());

            case VertexTypeD11.STANDARD_VERTEX:
                return(StandardVertex.GetInfos());
            }

            return(null);
        }
Beispiel #4
0
 public void AddVertex(StandardVertex v)
 {
     Vertices.Add(v);
     indexes.Add(Vertices.Count - 1);
 }
Beispiel #5
0
 public void AddVertex(StandardVertex vertex)
 {
     m_Vertices.Add(vertex);
 }
Beispiel #6
0
        // Public

        // Static Methods

        /// <summary>
        /// Retourne un cylindre, la valeur passé en paramètre détermine le niveau de
        /// détail du cylindre
        /// </summary>
        public static Mesh GetMesh(int discretisation)
        {
            StandardMesh smesh = new StandardMesh();

            // On commence par crée les points du cercle qui forme la base du cylindre
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(0, i, i + 1);
            }

            int meshOffset = smesh.GetVertexCount();

            // On commence par crée un deuxième cercle en haut du cylindre
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        1.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(meshOffset, meshOffset + i + 1, meshOffset + i);
            }

            meshOffset = smesh.GetVertexCount();

            // On Crée encore une fois le cercle à la base et en haut du cylindre pour éviter les souscis de normales
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }
            // On Crée encore une fois le cercle à la base et en haut du cylindre pour éviter les souscis de normales
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        1.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }


            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(meshOffset + i, meshOffset + discretisation + i, meshOffset + i + 1);
                smesh.AddFace(meshOffset + i + 1, meshOffset + discretisation + i, meshOffset + discretisation + i + 1);
            }

            smesh.AddFace(meshOffset + discretisation - 1, meshOffset + discretisation + discretisation - 1, meshOffset);
            smesh.AddFace(meshOffset, meshOffset + discretisation + discretisation - 1, meshOffset + discretisation);
            //smesh.AddFace(meshOffset + i + 1, meshOffset + discretisation + i, meshOffset + discretisation + i + 1);

            smesh.ComputeNormals();
            smesh.ComputeTangents();
            return(smesh.ReturnMesh());
        }
Beispiel #7
0
        // Public

        // Static Methods

        /// <summary>
        /// Crée un nouveau cône dont le cercle de base est composé du nombre
        /// de sommet passé en paramètre
        /// </summary>
        /// <param name="discretisation"></param>
        /// <returns></returns>
        public static Mesh GetMesh(int discretisation)
        {
            StandardMesh smesh = new StandardMesh();

            // On commence par crée les points du cercle qui forme la base du cône
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            smesh.AddVertex(new StandardVertex(new Vector3(0.0f, 1.0f, 0.0f)));


            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(i + 1, i, smesh.GetVertexCount() - 1);
            }

            smesh.AddFace(0, smesh.GetVertexCount() - 2, smesh.GetVertexCount() - 1);

            // On construit la base


            int startSecondCircle = smesh.GetVertexCount();

            // On Crée une deuxième fois les sommets à la base du cone pour éviter les problèmes
            // de normales (comme le cube par exemple)
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }


            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(startSecondCircle, startSecondCircle + i, startSecondCircle + i + 1);
            }

            smesh.ComputeNormals();
            smesh.ComputeTangents();

            return(smesh.ReturnMesh());
        }
Beispiel #8
0
        // Methods

        public void AddPoint(StandardVertex sv)
        {
            Vertices.Add(sv);
        }