Thread: gluSphere and quadratic objects

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    15

    gluSphere and quadratic objects

    Dear All,

    I posted a question a little while ago (entitled "gl animation too slow"). Thanks for all the suggestions.
    I have another related question, which might help me speed things up.
    In my code, I call gluSphere several thousand times ( ), but I can't allow this to take long.
    I see that gluSphere takes a GLUquadricObj as a parameter. Does this mean that the sphere is now stored in this quadratic object? If so, then since I want all my spheres to look the same, can I re-use that objcet, rather than calling gluSphere time and again?
    If so, how? I don't know how I would re-render such an object. (Re-render is probably not the word I should use - I hope you understand what I mean).

    Thanks everyone,

    Phil Drew

    If it helps, here's my code again:
    Code:
    	::glNewList(1,GL_COMPILE_AND_EXECUTE);
    
    	for(i=0; i<m_ppf; i++)
    	{
    		n = m_ppf*f + i;
    		X = m_x[n];
    		Y = m_y[n];
    		Z = m_z[n];
    
    		glPushMatrix();
    			glTranslated(X, Y, Z);
    			glColor3f(1.0f,1.0f,1.0f);
    			glMaterialfv(GL_FRONT,GL_DIFFUSE,farraygrey);
    			gluSphere(m_quadratic, m_radius, m_quality+1, m_quality+1);
    		glPopMatrix();
    	}
    
    	::glEndList();

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Again I'm not sure of this glSphere stuff but I do have code from NVidia which creates a sphere mathematically.

    Using the newer video cards ability to add and remove vertexes on the fly you could do the following and forget the quadratic.

    1. Pre-render a sphere at set size and radius and save the vertexes.
    2. To create a new sphere simply add or subtract vertexes and translate new vertexes by the amount needed to get a new radius.
    3. Render the new sphere.


    This would be very fast and would require next to nil in clock cycles.

    I don't know how to add or remove vertexes in OpenGL - basically its a real time optimized adapting mesh kinda like a ROAM terrain engine...but NVidia provides native support for doing this. Check out the DirectX SDK example. They start with a lion-type model and then allow you to add complexity or remove it in real-time. This is what I'm referring to.

    So pre-render the base sphere based on the following formula.


    0<alpha<360
    -90<beta<90

    newx=centerx+((cos(alpha)*cos(beta))*radius)
    newy=centery+((cos(alpha)*sin(beta))*radius)
    newz=centerz+((sin(alpha))*radius)

    Create a base mesh out of this and then to create a new sphere - simply add vertexes to the base mesh, and translate them by (desiredradius-baseradius).

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    15
    Thanks for that - I've actually tried that (practically given myself a hernia trying to figure out all the maths for myself), but it never gives as good a sphere as gluSphere - no idea why.

    But it's OK now anyway - there was a simple solution. Just make one sphere (using gluSphere) inside a glList, and then keep recalling that list when making the bigger world list.

    Sod's Law that I come up with the solution 5 minutes after I post the question after a week of trying to work it out!

    Thanks anyway everybody!

Popular pages Recent additions subscribe to a feed