Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:12:20+00:00 2026-05-26T01:12:20+00:00

The mechanisms for building a mesh in WPF are quite low-level. For example you

  • 0

The mechanisms for building a mesh in WPF are quite low-level. For example you have to supply the vertexes and the indexes. Are there helpers in the WPF or anywhere in the .NET 4.0 framework I can use? Or do I have to resort to third party libraries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:12:21+00:00Added an answer on May 26, 2026 at 1:12 am

    Here’s an older chunk of XNA 3.1 code I wrote to build a Sphere. I apply a transformation matrix in my rendering loop that allows me to stretch and orient it. Computing the vertices is fairly straightforward… computing the indices are what I find more difficult. This should hopefully give you an idea, though. The other primitives (e.g. cone, cylinder, cube…) are much simpler to compute.

    The m_iSegments paremeter just allows me to define how many slices I want to divide the sphere into… the more segments, the more vertices, the smoother the sphere.

    The m_Appearance parameter is my wrapper for the shader.

            /// <summary>
            /// This method constructs ellipsoid vertices, indices, and normals.
            /// Equations are performed using the parameterized equations:
            /// 
            /// x = a cos(B)cos(L)
            /// y = b cos(B)sin(L)
            /// z = c sin(B)
            /// 
            /// Where:
            /// 
            /// B = latitude and,
            /// L = longitude
            /// 
            /// </summary>
            /// <seealso cref="http://en.wikipedia.org/wiki/Ellipsoid">Wikipedia - Ellipsoid</seealso>
            public override void BuildVertices()
            {
                #region Declarations
    
                int iIndex = 0;                                     // Stores the index of the vertex array.
                int iBeta = 0;                                      // Stores the beta increment.
                int iLambda = 0;                                    // Stores the lambda increment.
                float Beta = 0.0f;                                  // Beta0 - Stores the latitude.
                float Lambda = 0.0f;                                // Lambda0 - Stores the longitude.
                float BetaStep = MathHelper.Pi / m_iSegments;       // Latitude Segements, in degrees.
                float LambdaStep = MathHelper.TwoPi / m_iSegments;  // Longitude Segments, in degrees.
                Vector3 vectPos = Vector3.Zero;                     // Vertex Position Vector
                Vector3 vectNor = Vector3.Zero;                     // Vertex Normal Vector
                Vector2 vectTex = Vector2.Zero;                     // Vertex Texture Coordinate
    
                #endregion
    
                #region Build the vertices.
    
                int[] iIndices = new int[6 * m_iSegments * m_iSegments];
                Vector3[] vVertices = new Vector3[(m_iSegments + 1) * (m_iSegments + 1)];
                Vector2[] vTexCrds  = new Vector2[vVertices.Length];
    
                iIndex = 0;
    
                for (iBeta = 0; iBeta <= m_iSegments; iBeta++)
                {
                    // Compute the latitude.
                    Beta = MathHelper.Clamp((-MathHelper.PiOver2) + (iBeta * BetaStep), -MathHelper.PiOver2, MathHelper.PiOver2);
    
                    for (iLambda = 0; iLambda <= m_iSegments; iLambda++)
                    {
                        // Compute the current longitude.
                        Lambda = MathHelper.Clamp((-MathHelper.Pi) + (iLambda * LambdaStep), -MathHelper.Pi, MathHelper.Pi);
    
                        // Compute the current vertex.
                        vVertices[iIndex] = new Vector3((float)(Math.Cos(Beta) * Math.Sin(Lambda)),
                                                        (float)(Math.Sin(Beta)),
                                                        (float)(Math.Cos(Beta) * Math.Cos(Lambda)));
    
                        // Compute the triangle indices.
                        if (iBeta < m_iSegments &&
                            iLambda < m_iSegments)
                        {
                            iIndices[iIndex + (iIndex * 5) - (iBeta * 6) + 0] = iIndex;
                            iIndices[iIndex + (iIndex * 5) - (iBeta * 6) + 1] = iIndex + m_iSegments + 1;
                            iIndices[iIndex + (iIndex * 5) - (iBeta * 6) + 2] = iIndex + m_iSegments + 2;
                            iIndices[iIndex + (iIndex * 5) - (iBeta * 6) + 3] = iIndex;
                            iIndices[iIndex + (iIndex * 5) - (iBeta * 6) + 4] = iIndex + m_iSegments + 2;
                            iIndices[iIndex + (iIndex * 5) - (iBeta * 6) + 5] = iIndex + 1;
                        }
    
                        // Compute the texture coordinates.
                        vTexCrds[iIndex] = new Vector2((float)iLambda / (float)m_iSegments, 1.0f - (float)iBeta / (float)m_iSegments);
    
                        iIndex++;
                    }
    
                }
    
                # endregion
    
                #region Build the normals.
    
                Vector3[] vNormals = new Vector3[vVertices.Length];
                for (iIndex = 0; iIndex < vVertices.Length; iIndex++)
                {
                    vNormals[iIndex] = vVertices[iIndex] - this.AbsolutePosition;
                    vNormals[iIndex].Normalize();
                }
    
                #endregion
    
                #region Build the buffers.
    
                VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[vVertices.Length];
                for (iIndex = 0; iIndex < vVertices.Length; iIndex++)
                    vertices[iIndex] = new VertexPositionNormalTexture(vVertices[iIndex], vNormals[iIndex], vTexCrds[iIndex]);
                m_pAppearance.SetBuffers(vertices, iIndices);
    
                #endregion
           }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I know, there are two mechanisms in ANTLR for building abstract
Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue. Why do we have two?
I appreciate that there are now many mechanisms in dotnet to deal with XML
What ways are there to protect licensing enforcement mechanisms in C/C++? I know of:
When trying to work with Qt's signal/slot mechanisms over more than one level of
I am building an Asp.net MVC site where I have a fast dedicated server
I am building a real estate website. I have a table for properties (i.e.
I am building a Symfony project, and have created a new plug-in named sfUtilsPlugin
I need an application architecture advise. I am building a .Net 4 WPF desktop
I have been building applications / web apps for some time, and I guess

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.