You didn't send complete runnable code, or the value of 'facets', or a
screenshot....

The only suspicious points that jump out at me are:

- I think your color sometimes has a negative red component;

- I am not confident that those ranges of theta and phi will end properly
(since they coerce the step to an int, probably rounding it off). You might
want to just print the ranges and check them.

Maybe there are other problems that will be obvious to someone else (or that
would be, if you sent complete code).

If you want to see completely different Sphere-drawing code that is known to
work, it's probably common; one example is in my pyweek game "Outlawn"
(class Sphere in gamelib/shapes.py).

- Bruce Smith

On Tue, Jan 18, 2011 at 9:19 AM, Will <[email protected]> wrote:

> This isn't really a pyglet question but I thought I would ask it
> anyway. I am trying to approximate a sphere using the instructions at
> http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/sphere_cylinder/,
> but it doesn't look right at all. This is my code:
>
> def draw_sphere(facets, radius=100):
>    """approximate a sphere using a certain number of facets"""
>
>    dtheta = 180.0 / facets
>    dphi = 360.0 / facets
>
>    global sphere_list
>    sphere_list = glGenLists(2)
>    glNewList(sphere_list, GL_COMPILE)
>
>    glBegin(GL_QUADS)
>
>    for theta in range(-90, 90, int(dtheta)):
>        for phi in range(0, 360, int(dphi)):
>            print theta, phi
>            a1 = theta, phi
>            a2 = theta + dtheta, phi
>            a3 = theta + dtheta, phi + dphi
>            a4 = theta, phi + dphi
>
>            angles = [a1, a2, a3, a4]
>
>            print 'angles: %s' % (angles)
>
>
>            glColor4f(theta/360.,phi/360.,1,0.5)
>
>            for angle in angles:
>                x, y, z = angle_to_coords(angle[0], angle[1], radius)
>                print 'coords: %s,%s,%s' % (x, y, z)
>                glVertex3f(x, y, z)
>
>
>
>    glEnd()
>
>    glEndList()
>
>
> def angle_to_coords(theta, phi, radius):
>    """return coordinates of point on sphere given angles and
> radius"""
>
>    x = cos(theta) * cos(phi)
>    y = cos(theta) * sin(phi)
>    z = sin(theta)
>
>    return x * radius, y * radius, z * radius
>
>
> It seems that some of the quads aren't simple, i.e. the edges are
> crossing, but changing the order of the vertices doesn't seem to make
> any difference.
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<pyglet-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to