Archived

This topic is now archived and is closed to further replies.

3d Sphere

This topic is 6388 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

Hi, I''m trying to draw a shere in 3d just using single pixels so it looks like the sphere in the Land demo from GD Showcase (the expanding ball thing), I need all the help I can get, it would be great if some one could give me the equation to find a point on a sphere ( I''ve seen one but can''t find it anywhere) and it would be even better if some one could post a code snippet of how to actually draw a nice sphere with it. Thanks alot everyone. Also any articles woul be good a well. P.S Just in case your wondering its going to be for a particle effect.

Share this post


Link to post
Share on other sites
I have an example that I wrote in C that does pixel correct sphere rendering, however it is at home on a mac. If your still interested I will get it for you on monday. It has full degrees of freedom and phong shading specular hilights and all. I am able to add transparency into it so I can make the oceans see thru'' or I can add a cloud layer that is semi transparent. It looks very nice with the pics I have of all the planets.

It is quite fast but you might want to look at using opengl or something which will aproximate the sphere as lots of polygons, it takes surprisingly few polygons to look nice and it''s a good deal faster.

Share this post


Link to post
Share on other sites
Thanks, but what I ''m looking for is alot simpler, its just pixels ( not many say 200) that make up a sphere, I would like so that I have an equation that you can change the radius of all these points. Sorry that I cant explain better I wish I had an example of what I''m looking for. Oh well thanks anyway.

Share this post


Link to post
Share on other sites
Is this what you are looking for?

OK it goes something along the lines of the following

for (double lat = 0 ; lat < 180 ; lat += stepy)
{
double xlatrad = sin(lat) * XRadius;
double zlatrad = sin(lat) * ZRadius;
double y = cos(lat) * YRadius;
for (double lng = 0 ; lng < 360 ; lng += stepx)
{
double x = sin(lng) * xlatrad ;
double z = cos(lng) * zlatrad;

3dPlot(x,y,z);
}
}


lat - latitude
lng - longitude

Most libraries work in Radians, so to convert degrees to radians:

#define DegToRad(d) ((d) / 57.29)


There are other (finer) methods that will produce points on a sphere that are equidistant. This method bunches the points together at the poles.

Take a look at the BOIDS example int the DirectX SDK. There is an algorithm that produces spheres of varying point density. This is probably what you are looking for.


DISCLAIMER: You may need to tweek (swap sin and cos around) as I am doing this from memory. I haven''t done this sort of thing for a VERY (mid 80''s) long time. So I applogise for any inaccuracies for the above code snippet;

Share this post


Link to post
Share on other sites