# DX11 Sphere Drawing with SlimDx using vertex n index buffers ( trianglelist primitive dx11)

This topic is 2381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I changed it using two angles and still not drawing properly...

 public bool Initialize(ref Device device) { /* vertex and index count will be calculated using radious & tesselation properties later I will make this class simple so that one who does not know much about it will also be able to Draw a sphere using this class */ BufferDescription vertexBuffDesc, indexBuffDesc; // Radious won't be used here , it will play role in just x = r * Cos(90); something like this .... vertexCount = ((int)tesselation + 1) * 12; indexCount = vertexCount*4*3*2; VertexPositionColor [] vertices = new VertexPositionColor[vertexCount]; int[] indices = new int[indexCount]; /* using mathematics rules , radious & tesselation I will fill the arrays here with data; */ // compute our step around each circle float step = ((float)System.Math.PI*2) / tesselation; // used to track the index into our vertex array int index = 0; //create the loop on the XY plane first for (float theta = -90f; theta < 90f; theta += 45f) { for (float phi = 0f; phi < 360; phi += 45f) { vertices[index++] = new VertexPositionColor(new Vector3((float)System.Math.Cos(phi) * (float)System.Math.Sin(theta) * radious, (float)System.Math.Sin(phi) * (float)System.Math.Sin(theta) * radious, 0f), new Vector4(0f, 1f, 0f, 0f)); vertices[index++] = new VertexPositionColor(new Vector3((float)System.Math.Cos(phi+theta) * (float)System.Math.Sin(theta+phi) * radious, (float)System.Math.Sin(phi+theta) * (float)System.Math.Sin(theta+phi) * radious, 0f), new Vector4(0f, 0f, 1f, 0f)); } } //next on the XZ plane for (float theta = -90f; theta < 90; theta += 45) { for (float phi = 0f; phi < 360; phi += 45) { vertices[index++] = new VertexPositionColor(new Vector3((float)System.Math.Cos(phi) * (float)System.Math.Sin(theta) * radious, 0f, (float)System.Math.Cos(theta)), new Vector4(1f, 0f, 0f, 0f)); vertices[index++] = new VertexPositionColor(new Vector3((float)System.Math.Cos(phi+theta) * (float)System.Math.Sin(theta+phi) * radious, 0f, (float)System.Math.Cos(theta+phi)), new Vector4(0f, 0f, 1f, 1f)); } } //finally on the YZ plane for (float theta = -90f; theta < 90; theta += 45) { for (float phi = 0f; phi < 360; phi += 45) { vertices[index++] = new VertexPositionColor(new Vector3(0f, (float)System.Math.Sin(phi) * (float)System.Math.Sin(theta) * radious, (float)System.Math.Cos(theta) ), new Vector4(0f, 0f, 0f, 1f)); vertices[index++] = new VertexPositionColor(new Vector3(0f, (float)System.Math.Sin(phi+theta) * (float)System.Math.Sin(theta+phi) * radious, (float)System.Math.Cos(theta+phi)), new Vector4(1f, 1f, 0f, 0f)); } } /* * keeping tesselation 10 get's me 10 points on each XY,YZ,XZ plan and now I would like to use Index Buffer's help to get better performance and reuse these */ int ind = 0; for (int i = 0; i < 192; i++) { indices[ind++] = i; indices[ind++] = i+1; indices[ind++] = 64+i; indices[ind++] = 64+i+1; indices[ind++] = 128+i; indices[ind++] = i; } //int six = 0; //float slices = (float)192/3; //float stacks = (float)3; //for (ushort slice = 0; slice < slices; ++slice) //{ // for (float stack = 0; stack < stacks; ++stack) // { // int v = (ushort)(slice * (stacks + 1) + stack); // indices[six++] = v; // indices[six++] = (int)(v + 1); // indices[six++] = (int)(v + (stacks + 1)); // indices[six++] = (int)(v + (stacks + 1)); // indices[six++] = (int)(v + 1); // indices[six++] = (int)(v + (stacks + 1) + 1); // } //} // I will make streams of these arrays here DataStream vertexDataStream = new DataStream(vertices, true, true); vertexDataStream.Position = 0; DataStream indexDataStream = new DataStream(indices, true, true); indexDataStream.Position = 0; /* these streams will create buffers */ // vertex buffer initialization vertexBuffDesc = new BufferDescription { Usage = ResourceUsage.Default, SizeInBytes = System.Runtime.InteropServices.Marshal.SizeOf(typeof(VertexPositionColor)) * vertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, StructureByteStride = 0, OptionFlags = 0 }; vertexBuffer = new Buffer(device, vertexDataStream, vertexBuffDesc); // index buffer initialization indexBuffDesc = new BufferDescription { Usage = ResourceUsage.Default, SizeInBytes = sizeof(int) * indexCount, BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, StructureByteStride = 0 }; indexBuffer = new Buffer(device, indexDataStream, indexBuffDesc); return true; } 

Previous POST : http://www.gamedev.n...th-slimdx-dx11/

##### Share on other sites
Please use the "code" tags if you're going to post source code, especially that much of it.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632997
• Total Posts
3009791
• ### Who's Online (See full list)

There are no registered users currently online

×