Jump to content
  • Advertisement
Sign in to follow this  
tcige

how to draw a ball

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
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 this post


Link to post
Share on other sites

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

Edited by unbird

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!