Public Group

# Drawing a better(or more efficient) Sphere

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

## Recommended Posts

i've been working on procedurally generating a sphere, which i have done, but I took a short cut, and i'd liek to figure out a less hacky way to do it, here's an example of the code
D3DXVECTOR4 Temp;
D3DXMATRIX rot;

for(int j =180;j >= 0; j -= 12)
{

for(int i = 360;i>=0;i-= 12 )
{

CircleList.push_back(PCVertex(D3DXVECTOR3
(Temp.x,Temp.y,Temp.z),D3DCOLOR_XRGB(255,255,255)));
}
}


basiclly i plot a series of circles, proforming a rotation to every vertex, but thats a lot of calculations for every vertex does anyone see know of a simpler technique for logically rotating the circle around the Y axis? thanks

##### Share on other sites
Why not use the function D3DXCreateSphere(...) to make a sphere mesh?

##### Share on other sites
because then I wouldn't learn anything :) I figure computational geometry is an important aspect in computer graphics, and the more practice and experience I get, the better off I am

##### Share on other sites
Well if you insist on knowing things! ;)

First off, don't bother with all the matrix transform math just to place a vertex - use some trigonometry to work out the position from your two angle loop variables. If you're stuck, think of a slice through the sphere as a circle with radius of cos(latitude) (latitude being the angle from the 'equator' of course) and then use the 'longitude' to place each vertex on that ring. But given that this is probably an 'offline' operation (i.e. you're not regenerating the sphere each frame I assume?) the efficiency probably isn't a massive issue.

More problematic is that you're creating degenerate vertices at the poles. Consider the poles as a special case and just generate one vertex for them, then connect that vertex to the first proper 'ring' of the sphere using a triangle-fan arrangement. Determining correct index buffer ordering might take some thought.

More generally though, while I agree it's a useful exercise to create procedural geometry I wouldn't get too caught up in it without good reason. An equally valid learning exercise would be to import data using a standard file format created by a 3D modelling package.

##### Share on other sites
thanks for the help, I knew it would be a trig problem, I'm still getting a handle on 3D geometry so it's hard to visualiz, and no I wouldn't be updating it.

I've also been working on pulling geometry from 3D File's(I wrote an MD2 loader, i'll probobly start on an MD3 or MD5 loader soon enough), as well as getting some practice ripping data from a D3DXMESH through Frank Luna's 2nd Ed. directX9 book.

I'm gonna look at it in the way you suggested, and see if I can pick up on it, and I've resigned myself to the fact that generating indices is gonna be a challenge, but a challenge is the path to growth.

Thanks for the help

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

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

• Total Topics
633677
• Total Posts
3013284
×