XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

How can I draw a sphere in XNA? Do I need a model? (any free ones available?)

Last post 08-13-2008 1:06 AM by DigitalLibrarian. 4 replies.
  • 05-12-2008 7:03 PM

    How can I draw a sphere in XNA? Do I need a model? (any free ones available?)

    How can I draw a simple 3D sphere in XNA?  I've searched the best I could and it seems like I need an actual 3D model, or an algorithm that creates the vertices needed (triangle strips?) to create the mesh (is that the right term?).

    If so, does anybody have any simple sphere models I could use?

    Thanks for any help!

  • 05-12-2008 7:13 PM In reply to

    Re: How can I draw a sphere in XNA? Do I need a model? (any free ones available?)

    You can build your own vertex/index buffers with whatever data you want but its easier to use a model.

    See http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Shader-Series-4_3A00_-Materials-and-Multiple-Light-Sources.aspx for how to do it and models of basic shapes that are free and open for you to use.



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 05-12-2008 7:15 PM In reply to

    Re: How can I draw a sphere in XNA? Do I need a model? (any free ones available?)

    It'd be a ton easier to just use a model.  It would be good to download Blender (www.blender.org) and get familiar with the basics.  A sphere can be produced in a about two seconds and then exported to FBX.

    In the mean time, the last sample in the shader series has a few primitive shape models, such as SphereLowPoly.fbx and SphereHighPoly.fbx, so you could download that sample and use those.

  • 05-13-2008 7:28 AM In reply to

    Re: How can I draw a sphere in XNA? Do I need a model? (any free ones available?)

    I think that what you need is this:

    protected override void Tesellate()
    {
    vpnt = new VertexPositionNormalTexture[(slices + 1) * (stacks + 1)];

    float phi, theta;
    float dphi = MathHelper.Pi / stacks;
    float dtheta = MathHelper.TwoPi / slices;
    float x, y, z, sc;
    int index = 0;

    for (int stack = 0; stack <= stacks; stack++)
    {
    phi = MathHelper.PiOver2 - stack * dphi;
    y = radius * (float)Math.Sin(phi);
    sc = -radius * (float)Math.Cos(phi);

    for (int slice = 0; slice <= slices; slice++)
    {
    theta = slice * dtheta;
    x = sc * (float)Math.Sin(theta);
    z = sc * (float)Math.Cos(theta);
    vpnt[index++] = new VertexPositionNormalTexture(new Vector3(x, y, z),
    new Vector3(x, y, z),
    new Vector2((float)slice / (float)slices, (float)stack / (float)stacks));
    }
    }

    indices = new int[slices * stacks * 6];
    index = 0;
    int k = slices + 1;

    for (int stack = 0; stack < stacks; stack++)
    {
    for (int slice = 0; slice < slices; slice++)
    {
    indices[index++] = (stack + 0) * k + slice;
    indices[index++] = (stack + 1) * k + slice;
    indices[index++] = (stack + 0) * k + slice + 1;

    indices[index++] = (stack + 0) * k + slice + 1;
    indices[index++] = (stack + 1) * k + slice;
    indices[index++] = (stack + 1) * k + slice + 1;
    }
    }
    }
    The slices is the north divisions to south, the stacks they are around the meridian. In the first loop you fill the vertex buffer and in the socend loop fill the indexes (stack + 0) are for clarify.
     
    I wait to have helped you. a greeting
     
  • 08-13-2008 1:06 AM In reply to

    Re: How can I draw a sphere in XNA? Do I need a model? (any free ones available?)

    Can we see the calls to the GraphicsDevice to draw the thing?

     

    I've been trying to use this tesselation sample for a couple weeks now, and finally bit the bullet and joined creator's club.  I've been working on my own simple mesh model 

    generation routines for primitives that I can chain together to get a basic physics system going.

    I need to see how it's drawn, how the VertexBuffer and IndexBuffer are set up, and also how the VertexDeclaration is defined.


Page 1 of 1 (5 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG