# OpenGL [solved] Why some items wont show.

This topic is 4464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I have a problem where I am trying to draw a unicycle. I modelled a wheel as a scaled sphere at first, and am now trying to add a tyre. (In the code below the wheel is scaled extra small so I may better see the tyre) Due to assignment constraints I have to use a tree method of connecting the items, and am currently having the wheel -> tyre (cyclinder) -> one rim (disc) -> other disc. Now I know that if there is a problem with the tree then the objects wont display, however my problem is that only the top and bottom items in the tree are displayed (IE the scaled down wheel/sphere and one rim) I have enclosed a Small Compilable Example below, although with openGL it appears there is no such thing as a small example. (Also hopefully the [ code ] [ /code ] tags work as there isn't a preview button.) So my question is does anything strike you as a good reason as to why some members of the tree are not displaying. I have attempted to play around with the rotate and translate functions but haven't come up with anything yet. The C code below can also be found here: http://myboxoftricks.homedns.org/sce.c If anyone has any ideas I would appreciate it. Kind regards, Mitch. EDIT: I've removed the code as i reckon I might be scaring people off, obviously people are looking but not replying. I cant imagine that no-one has used a tree structure before, so is there anything I can do that would make my question easier to ask? [Edited by - spudtheimpaler on April 29, 2006 4:20:48 PM]

##### Share on other sites
Just bumping the thread to indicate I've changed it.

##### Share on other sites
By tree method I assume you mean an object hierarchy of some sort. Are you using glPushMatrix() and glPopMatrix()? Proper use of these functions is usually the first step towards applying hierarchical transforms.

Another potential problem is order of operations. Generally you want to rotate and then translate, which translates into calling glTranslate*() before glRotate*() in your code. This is a common thing to get wrong, and usually results in objects not appearing where they're supposed to.

Maybe you could post just the bits of code where you set up the relevant transforms. The best tags to use for large blocks of code are probably [ source ][ /source ] (without the spaces).

##### Share on other sites
Quote:
 Original post by jykBy tree method I assume you mean an object hierarchy of some sort. Are you using glPushMatrix() and glPopMatrix()? Proper use of these functions is usually the first step towards applying hierarchical transforms.

I am indeed using those methods to form an object hierarchy (Sorry, I've been thrown into the deep end, so unfamiliar with many terms, functions etc).

Quote:
 Original post by jykAnother potential problem is order of operations. Generally you want to rotate and then translate, which translates into calling glTranslate*() before glRotate*() in your code. This is a common thing to get wrong, and usually results in objects not appearing where they're supposed to.

I was putting those the wrong way around, however it hasn't fixed the problem. I wasn't even aware it was an issue, however, so thank you for pointing it out.

Quote:
 Original post by jykMaybe you could post just the bits of code where you set up the relevant transforms. The best tags to use for large blocks of code are probably [ source ][ /source ] (without the spaces).

ok. Here we have the functions for each item on the hierachy:

////////////////////////  My Wheel Function  //////////////////////////void wheel(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, wheel_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT, wheel_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE, wheel_diffuse);  	  glTranslatef(0,-4,0);	  glScalef(0.1, 0.1, 0.1*WHEEL_WIDTH);//Change scale from 1,1,wheel_width      gluSphere(wheel_quad, WHEEL_RADIUS, 30, 30);   glPopMatrix();}////////////////////////  My Tyre Function  ///////////////////////////void tyre(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, tyre_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT,  tyre_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE,  tyre_diffuse);   	  glTranslatef(0,-4,-0.2);      glRotatef(0.0,0, 1.0, 0);//	  glScalef(1,1,1);      gluCylinder(tyre_quad, WHEEL_RADIUS, WHEEL_RADIUS, TYRE_WIDTH, 30, 30);   glPopMatrix();}void tyre_disc_left(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, tyre_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT,  tyre_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE,  tyre_diffuse);   	  glTranslatef(0,-4.0,-0.2);      glRotatef(0.0,0, 1.0, 0);//	  glScalef(1,1,0.1);      gluDisk(tyre_disc_left_quad, WHEEL_RADIUS/TYRE_WIDTH_DIVIDER, WHEEL_RADIUS, 30, 30);   glPopMatrix();}void tyre_disc_right(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, tyre_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT,  tyre_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE,  tyre_diffuse);   	  glTranslatef(0,-4,0.2);     glRotatef(00.0,0, 1.0, 0);//	  glScalef(1,1,0.1);      gluDisk(tyre_disc_right_quad, WHEEL_RADIUS/TYRE_WIDTH_DIVIDER, WHEEL_RADIUS, 30, 30);   glPopMatrix();}

with a display function that looks like this

void display(void){    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);    glLoadIdentity();    glColor3f(1.0, 1.0, 1.0);//    traverse(&torso_node);    traverse(&wheel_node);    glutSwapBuffers();}

and the traverse function (unaltered from that given to us by the lecturer)

void traverse(treenode* root){   if(root==NULL) return;   glPushMatrix();   glMultMatrixf(root->m);   root->f();   if(root->child!=NULL) traverse(root->child);   glPopMatrix();   if(root->sibling!=NULL) traverse(root->sibling);}

and the hierarchy set up as per:

////////////////////////  My own quadrics  ////////////////////////////		wheel_quad = gluNewQuadric();		gluQuadricDrawStyle(wheel_quad, GLU_FILL);						tyre_quad = gluNewQuadric();		gluQuadricDrawStyle(tyre_quad, GLU_FILL);		tyre_disc_left_quad = gluNewQuadric();		gluQuadricDrawStyle(tyre_disc_left_quad, GLU_FILL);		tyre_disc_right_quad = gluNewQuadric();		gluQuadricDrawStyle(tyre_disc_right_quad, GLU_FILL);[snip...]////////////////////////  My own Tree  ////////////////////////////////////////////////////////  Start with the wheel  ///////////////////////		glLoadIdentity();        glTranslatef(0,-4.0,0);        glRotatef(theta[0], 0.0, 1.0, 0.0);		glGetFloatv(GL_MODELVIEW_MATRIX,wheel_node.m);		wheel_node.f = wheel;		wheel_node.sibling = NULL;		wheel_node.child =  &tyre_node;//&head_node;		glLoadIdentity();		////////////////////////  Next the tyre  //////////////////////////////		glLoadIdentity();        glTranslatef(0,0,-0.2);		glRotatef(theta[1], 0, 1, 0);		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_node.m);		tyre_node.f = tyre;		tyre_node.sibling = NULL;		tyre_node.child = &tyre_disc_left_node;		glLoadIdentity();////////////////////////  Add the Tyre Rims  //////////////////////////		glLoadIdentity(); 	    glTranslatef(0, 0,0);		glRotatef(theta[2], 0, 1, 0);//change this?		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_disc_left_node.m);		tyre_node.f = tyre_disc_left;		tyre_node.sibling = NULL;		tyre_node.child = &tyre_disc_right_node;		glLoadIdentity();		glLoadIdentity(); 	    glTranslatef(0,0,0.4);		glRotatef(theta[3], 0, 1, 0);//change this?		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_disc_right_node.m);		tyre_node.f = tyre_disc_right;		tyre_node.sibling = NULL;		tyre_node.child = NULL;		glLoadIdentity();

As mentioned the compilable example is as [link removed by spudtheimpaler: posted this a while ago, need space on the server]

Hopefully the above will help to clarify :) This has brought me to a complete halt and I know it is simply my annoyance that is blinding me to the obvious answer.

Many thanks :)

Mitch

[Edited by - spudtheimpaler on May 21, 2006 12:37:29 PM]

##### Share on other sites
Solved.

glLoadIdentity(); 	    glTranslatef(0, 0,0);		glRotatef(theta[2], 0, 1, 0);//change this?		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_disc_left_node.m);		tyre_node.f = tyre_disc_left;		tyre_node.sibling = NULL; //**		tyre_node.child = &tyre_disc_right_node;		glLoadIdentity();

//** tyre_node.sibling etc should be tyre__disc_left_node.blah

Thanks for your help though :)

Mitch.

1. 1
Rutin
26
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002086
×