# how to draw a ball

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

## Recommended Posts

is there any convenient and effective algorithm

##### Share on other sites

In 2D, you just write a pixel shader that clip the pixel when the distance to the center is larger than the radius.

For soft edges, you can also take saturate(radius + 0.5 - distanceToCenter) as opacity from the alpha channel.

##### Share on other sites

For googling you might want to also try "sphere" instead of ball.

It appears directx has a built in function for generating a sphere mesh which you can find and look into.

If it lacks features you need, there are other approaches:

1. Generate the sphere yourself

*Use a kind of longitude/latitude sphere made out of quads. It will cause them to be really tightly packed at the poles.

*Tessellate something like an icosahedron to create spheres of different polygonal fidelity. This will make symmetric spheres where the triangles are not packed around the poles...

*Tessellate a cube and move the corners closer to the center (or extrude the centers of the quads). This might be nice if you want a sphere with 1 texture on each side (the axis directions, so 6 sides)

2. Use a modeling program to create the sphere and import it (probably makes it easier to add texture coords and other data on the vertices)

##### Share on other sites

D3DXCreateSphere, and then mesh->DrawSubset(0).

Edited by unbird

##### Share on other sites

If you are interested in doing the drawing yourself, you can check out the implementation in my GeometryActor class from Hieroglyph 3.

##### Share on other sites
LPD3DXMESH sphere;

Create sphere:

D3DXCreateSphere(device, reduis, slices, stacks, &sphere);


Draw sphere:

device->SetTexture(...);
device->SetMaterial(...);
device->SetTransform(...);
sphere->DrawSubset(0);


1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013181
×