コード例 #1
0
ファイル: Program.cs プロジェクト: amenzies/Embree.NET
        /// <summary>
        /// Generates the unit sphere to arbitrary resolution.
        /// </summary>
        /// <remarks>
        /// Copied verbatim from the Embree benchmark code.
        /// </remarks>
        public static IMesh GenerateSphere(int numPhi)
        {
            var numTheta = 2 * numPhi; // we tessellate the unit sphere
            var vertices = new IEmbreePoint[numTheta * (numPhi + 1)];
            var indices  = new int[3 * 2 * numTheta * (numPhi - 1)];

            int   tri         = 0;
            float rcpNumTheta = 1.0f / (float)numTheta;
            float rcpNumPhi   = 1.0f / (float)numPhi;

            for (var phi = 0; phi <= numPhi; ++phi)
            {
                for (var theta = 0; theta < numTheta; ++theta)
                {
                    float phif   = phi * (float)Math.PI * rcpNumPhi;
                    float thetaf = theta * 2 * (float)Math.PI * rcpNumTheta;
                    float x      = (float)(Math.Sin(phif) * Math.Sin(thetaf));
                    float y      = (float)(Math.Cos(phif));
                    float z      = (float)(Math.Sin(phif) * Math.Cos(thetaf));
                    vertices[phi * numTheta + theta] = new Vector(x, y, z);
                }

                if (phi == 0)
                {
                    continue;
                }

                for (var theta = 1; theta <= numTheta; ++theta)
                {
                    int p00 = (phi - 1) * numTheta + theta - 1;
                    int p01 = (phi - 1) * numTheta + theta % numTheta;
                    int p10 = phi * numTheta + theta - 1;
                    int p11 = phi * numTheta + theta % numTheta;

                    if (phi > 1)
                    {
                        indices[3 * tri + 0] = p10;
                        indices[3 * tri + 1] = p00;
                        indices[3 * tri + 2] = p01;
                        ++tri;
                    }

                    if (phi < numPhi)
                    {
                        indices[3 * tri + 0] = p11;
                        indices[3 * tri + 1] = p10;
                        indices[3 * tri + 2] = p01;
                        ++tri;
                    }
                }
            }

            return(new TriangleMesh(indices, vertices));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: TomCrypto/Embree.NET
        /// <summary>
        /// Generates the unit sphere to arbitrary resolution.
        /// </summary>
        /// <remarks>
        /// Copied verbatim from the Embree benchmark code.
        /// </remarks>
        public static IMesh GenerateSphere(int numPhi)
        {
            var numTheta = 2 * numPhi; // we tessellate the unit sphere
            var vertices = new IEmbreePoint[numTheta * (numPhi + 1)];
            var indices = new int[3 * 2 * numTheta * (numPhi - 1)];

            int tri = 0;
            float rcpNumTheta = 1.0f / (float)numTheta;
            float rcpNumPhi   = 1.0f / (float)numPhi;

            for (var phi = 0; phi <= numPhi; ++phi)
            {
                for (var theta = 0; theta < numTheta; ++theta)
                {
                    float phif   = phi * (float)Math.PI * rcpNumPhi;
                    float thetaf = theta * 2 * (float)Math.PI * rcpNumTheta;
                    float x = (float)(Math.Sin(phif) * Math.Sin(thetaf));
                    float y = (float)(Math.Cos(phif));
                    float z = (float)(Math.Sin(phif) * Math.Cos(thetaf));
                    vertices[phi * numTheta + theta] = new Vector(x, y, z);
                }

                if (phi == 0)
                    continue;

                for (var theta = 1; theta <= numTheta; ++theta)
                {
                    int p00 = (phi - 1) * numTheta + theta - 1;
                    int p01 = (phi - 1) * numTheta + theta % numTheta;
                    int p10 = phi * numTheta + theta - 1;
                    int p11 = phi * numTheta + theta % numTheta;

                    if (phi > 1)
                    {
                        indices[3 * tri + 0] = p10;
                        indices[3 * tri + 1] = p00;
                        indices[3 * tri + 2] = p01;
                        ++tri;
                    }

                    if (phi < numPhi)
                    {
                        indices[3 * tri + 0] = p11;
                        indices[3 * tri + 1] = p10;
                        indices[3 * tri + 2] = p01;
                        ++tri;
                    }
                }
            }

            return new TriangleMesh(indices, vertices);
        }