views:

145

answers:

2

below are a whole length of code i have copied from NEHE Production (Lesson 25).. i was just trying to play around but seem to not able to change/convert each points into a individual spheres nor cylinder..
somehow when i did my adjustment they are not arranged in the way they are suppose to and they won't rotate..
i planed to add light in this tutorial later on as well..

thanks in advance for any help =]

int InitGL(GLvoid)
{
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    maxver=0;
    objload("data/sphere.txt",&morph1);
    objload("data/torus.txt",&morph2);
    objload("data/Tube.txt",&morph3);

    objallocate(&morph4,10300);

    for(int i=0;i<10300;i++)
    {
        morph4.points[i].x=((float)(rand()%14000)/1000)-7;
        morph4.points[i].y=((float)(rand()%14000)/1000)-7;
        morph4.points[i].z=((float)(rand()%14000)/1000)-7;
    }

    objload("data/Tube.txt",&helper);
    sour=dest=&morph1;

    return TRUE;
}

void DrawGLScene(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(cx,cy,cz);
    glRotatef(xrot,1,0,0);
    glRotatef(yrot,0,1,0);
    glRotatef(zrot,0,0,1);

    xrot+=xspeed; yrot+=yspeed; zrot+=zspeed;

    GLfloat tx,ty,tz;
    VERTEX q;
    glPointSize(2.0f);

    //glBegin(GL_POINTS);
    for(int i=0;i<morph3.verts;i++)
    {
        if(morph) 
            q=calculate(i); 
        else 
            q.x=q.y=q.z=0;

        helper.points[i].x-=q.x;
        helper.points[i].y-=q.y;
        helper.points[i].z-=q.z;
        tx=helper.points[i].x;
        ty=helper.points[i].y;
        tz=helper.points[i].z;

        glColor3f(0,1,1);
        glPushMatrix(); //i have modified this part onwards
        gltranslaste(tx,ty,tz);
        glutSolidSphere(2,6,6);
        glPopMatrix();

        /*glVertex3f(tx,ty,tz);
        glColor3f(0,0.5f,1);
        tx-=2*q.x; ty-=2*q.y; ty-=2*q.y;
        glVertex3f(tx,ty,tz);
        glColor3f(0,0,1);
        tx-=2*q.x; ty-=2*q.y; ty-=2*q.y;
        glVertex3f(tx,ty,tz);*/
    }
    //glEnd();

    if(morph && step<=steps)
        step++; 
    else 
    { 
        morph=FALSE; sour=dest; step=0;
    }
}
A: 

This looks like the tutorial code, intact. Or more to the point, I see no code attempting to draw spheres or cylinders. What did you try? How did it go wrong?

If you're looking for pointers, I suggest you start by isolating the code which draws the points. Try writing a function which draws a point given its properties in the parameters.

(Note that you should move the glBegin()-glEnd() pair to inside the function as well. Have it call glBegin() before and glEnd() after drawing every single point, i.e. as the first and last lines. This is because you'll have to get rid of them when you eventually call gluSphere() from within. There aren't many GL functions you can call between a glBegin()-glEnd() pair.)

Edit in response to question's edit:

Your code works. Replacing gltranslaste with glTranslatef, obviously, it is able to draw cyan shapes instead of plain dots. Granted, the shapes look ugly and nothing like spheres, but they're there and they even "morph". What's the problem?

You may want to play with the material and lighting options to make them look better. (Or just assign a texture so you can see their alignment.) As for rotating them, you should be able to call glRotate() in between pushing and popping the [MV] matrix.

aib
aib, i have include the code now please, let me know where i go wrong.there are so many types spheres from gl, glu, glui, glut and glaux i confused of which one would be the easiest to use..
noob88
I think you're better off using polygons first, as @Ricket has suggested below. But I don't see anything wrong with glutSolidSphere(), which draws a sphere with a single line of code.
aib
+1  A: 

A good place to start is to replace glBegin(GL_POINTS) with glBegin(GL_TRIANGLES) or GL_QUADS or GL_POLYGONS.

See the help page on glBegin/End here.

Ricket