how to draw a ball

Started by
4 comments, last by Medo Mex 10 years, 11 months ago

is there any convenient and effective algorithm

Advertisement

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.

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)

o3o

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

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


LPD3DXMESH sphere;

Create sphere:


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

Draw sphere:


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

This topic is closed to new replies.

Advertisement