Advertisement

Ball

Started by October 15, 2000 02:45 PM
19 comments, last by Dunge 24 years, 1 month ago
A small correction: You can make a sphere out of Quads AND Triangles(or just Triangles).

Also, there are two main kinds of spheres: "normal" ones(I don''t know the technical name) and "geospheres". geosphere''s are usually used in games, and can only be made with triangles.
Hey....... I only want to do a ball in a PONG game and I want an exemple of gluSphere (C++) I seen in the MSDN but I don''t understand how to use it.....

void gluSphere( GLUquadricObj *qobj, GLdouble radius, GLint slices, GLint stacks );

slices and stacks are the number of line in the ball vertical and horizontal, radius is the size but qobj?
Advertisement
    //During global variable declaration add the line:GLUquadricObj *quadratic;//At the end of your InitGL function add:quadratic=gluNewQuadric();gluQuadricNormals(quadratic, GLU_SMOOTH);gluQuadricTexture(quadratic, GL_TRUE);//Then during your DrawGLScene function add the function:gluSphere(quadratic, [radius], [slices], [stacks]);            


That is coming straight out of NeHe tutorial 18 on quadratics and there may be something that is missing in there.

quote:
by GLUT u mean the glu functions?


I think nate means the functions contained in the GLUT.H header file.

Edited by - oglman on October 16, 2000 10:19:59 PM
You can do it yourself:

    //---------------------------------------------------------------------------void __fastcall CObject::Draw(){	//	Ball	for(int z=0; z<8; z++)	{		glBegin(GL_QUAD_STRIP);		for(int r=0; r<=16; r++)		{			glNormal3d(				cos(2*PI/16*r) * sin(2*PI/16*z),				sin(2*PI/16*r) * sin(2*PI/16*z),				cos(2*PI/16*z));			glVertex3d(				Object.Position.x + dSize * cos(2*PI/16*r) * sin(2*PI/16*z),				Object.Position.y + dSize * sin(2*PI/16*r) * sin(2*PI/16*z),				Object.Position.z + dSize * cos(2*PI/16*z));			glNormal3d(				cos(2*PI/16*r) * sin(2*PI/16*(z+1)),				sin(2*PI/16*r) * sin(2*PI/16*(z+1)),				cos(2*PI/16*(z+1)));			glVertex3d(				Object.Position.x + dSize * cos(2*PI/16*r) * sin(2*PI/16*(z+1)),				Object.Position.y + dSize * sin(2*PI/16*r) * sin(2*PI/16*(z+1)),				Object.Position.z + dSize * cos(2*PI/16*(z+1)));		}		glEnd();	}}//---------------------------------------------------------------------------    


You have to replace the 8 and 16 values with the amount of vertices you want.

Does someone know how to calculate a sphere with even-sized polygons? Or have a link to some interresting stuff about this?

Will that code right there run faster than Glusphere with Backface culling enabled?
sinistrx: To be honest - I don''t have a clue

But the code can be optimized. Just a few:
  • Calc the sin/cos only once. Also every other value used twice or more, can be calced only once.
  • Do it in assembly.
  • Use floats - not doubles.
  • Unrolled loops in some situations (hehe - just kidding )
  • Don''t multiply but interpolate using pre-calculated values.
  • Optimisation is endless work...


  • Just a few reasons why this code could be faster:
  • More calculations can be pre-calculated because. For instance: the size/position/slices can be a constant.
  • You don''t need an extra glTranslate().


  • Another advantage:
  • You can enter your own glTexCoord() and/or glColor() values.
  • It''s fun to do it yourself
  • You can add other strange effects...!



  • I don''t know much about glut, so I can''t say what is faster...
    But glut is just another OpenGL wrapper. I don''t want to start a war about this, it''s just that personally I like to stay as low level as I can. Maybe others do too - that''s why I posted this answer.

    Advertisement
    I was just telling him how to use gluSphere() not suggesting anything about hoe efficiant it is
    the source of glut is included with the distribution so u can have a looksy to see what glutsolidsphere does
    also check out the mesa source

    http://members.xoom.com/myBollux
    Where can I download the SDK and the runtime for OpenGL? Thanks!

    -------------------------------
    I'll screw up whoever screws around with the gamedev forum!

    ..-=gLaDiAtOr=-..
    So many people use it and nobody knows?

    -------------------------------
    I'll screw up whoever screws around with the gamedev forum!

    ..-=gLaDiAtOr=-..

    This topic is closed to new replies.

    Advertisement