コード例 #1
0
ファイル: Mesh.cs プロジェクト: zpconn/Gas
        /// <summary>
        /// Builds a rectangular mesh, centered around the origin.
        /// </summary>
        public static Mesh Rectangle( Renderer renderer, Color color, float width, float height,
            float textureMapTiling)
        {
            Mesh rectMesh = new Mesh( renderer, 4, 2 );

            rectMesh.AddVertex( 0, new Vector3( -width / 2, height / 2, 1.0f ), color,
                new Vector2( 0.0f, 0.0f ) );
            rectMesh.AddVertex( 1, new Vector3( width / 2, height / 2, 1.0f ), color,
                new Vector2( textureMapTiling, 0.0f ) );
            rectMesh.AddVertex( 2, new Vector3( width / 2, -height / 2, 1.0f ), color,
                new Vector2( textureMapTiling, textureMapTiling ) );
            rectMesh.AddVertex( 3, new Vector3( -width / 2, -height / 2, 1.0f ), color,
                new Vector2( 0.0f, textureMapTiling ) );

            rectMesh.AddTriangle( 0, 0, 1, 2 );
            rectMesh.AddTriangle( 1, 0, 2, 3 );

            return rectMesh;
        }
コード例 #2
0
ファイル: Mesh.cs プロジェクト: zpconn/Gas
        /// <summary>
        /// Builds a circular mesh centered around the origin.
        /// </summary>
        public static Mesh Circle( Renderer renderer, Color color, float radius,
            int numSubdivisions, float textureMapTiling)
        {
            Mesh circleMesh = new Mesh( renderer, numSubdivisions, numSubdivisions - 2 );

            float angleStep = ( 2 * ( float )Math.PI ) / numSubdivisions;
            for ( int i = 0; i < numSubdivisions; ++i )
            {
                Vector2 texCoords = textureMapTiling * ( new Vector2(
                    ( float )Math.Cos( angleStep * i ) / 2.0f + 0.5f,
                    1.0f - ( ( float )Math.Sin( angleStep * i ) / 2.0f + 0.5f ) ) );

                circleMesh.AddVertex( i, new Vector3( radius * ( float )Math.Cos( angleStep * i ),
                    radius * ( float )Math.Sin( angleStep * i ), 1.0f ), color, texCoords );
            }

            for ( int i = 2, count = 0; i < numSubdivisions - 1; ++i, ++count )
            {
                circleMesh.AddTriangle( count, 0, i, i - 1 );
            }

            circleMesh.AddTriangle( numSubdivisions - 3, 0, numSubdivisions - 2, numSubdivisions - 1 );

            return circleMesh;
        }