# gluLookAt

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

## Recommended Posts

hello friends,

i am trying to look at the cylinders from behind, not able to succeed.

#include <glut.h>

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);

GLdouble L1=40;
GLdouble L2=30;

glPushMatrix();
glTranslated(0,0,0);
glRotated(0,0,0,0);
glPushMatrix();
glColor3d(0.20,0.0,0.0);
gluCylinder(qobj1,6,4,L1,10,10);
glPopMatrix();
glTranslated(0,0,L1);
glRotated(90,0,1,0);
glColor3d(0.50,0.50,1.0);
gluCylinder(qobj1,4,2,L2,10,10);
glPopMatrix();
glutSwapBuffers();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt (0.0, 0.0, -90.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

regards
roy

##### Share on other sites
If you look at like this:

gluLookAt (0.0, 0.0, 1.0f, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

Does it show the cylinder??

PD: you must change glClear to

glClear(GL_COLOR_BIT|GL_DEPTH_BUFFER);

##### Share on other sites
hello friend,

no it did not show the cylinders?
also where should i call this "glClear(GL_COLOR_BIT|GL_DEPTH_BUFFER);"

thanks

##### Share on other sites
Quote:
 Original post by ROY09also where should i call this "glClear(GL_COLOR_BIT|GL_DEPTH_BUFFER);"

You don't need to, you haven't initialised a depth buffer.

The problem is most likely this:

glRotated(0,0,0,0);

For a start, (0,0,0) is not a valid rotation vector. It'll cause all manner of horrors in the modelview matrix stack, which will (at a guess) collapse all objects into a single point.
Secondly, why rotate anything by zero degrees, or translate something of zero units? They are wasteful, remove them.

void display(){  glClear (GL_COLOR_BUFFER_BIT);  glColor3f (1.0, 1.0, 1.0);  GLdouble L1=40;  GLdouble L2=30;  GLUquadricObj *qobj1 = gluNewQuadric();  gluQuadricDrawstyle(qobj1,GLU_FILL);  glPushMatrix();    glColor3d(0.20,0.0,0.0);    gluCylinder(qobj1,6,4,L1,10,10);  glPopMatrix();  glPushMatrix();    glTranslated(0,0,L1);    glRotated(90,0,1,0);    glColor3d(0.50,0.50,1.0);    gluCylinder(qobj1,4,2,L2,10,10);  glPopMatrix();}

##### Share on other sites
Quote:
 Original post by sssssPD: you must change glClear toglClear(GL_COLOR_BIT|GL_DEPTH_BUFFER);

He doesn't have to do anything of the sort. Depth buffers are optional, and not a requirement. Since he has elected to not initialise a depth buffer, clearing it is would have no effect. You know, back in the good old days we used to do without depth buffers and used poly sorting via BSP trees..... You can do without them (although most people don't do that anymore)

##### Share on other sites
Hi Robert,

i had to use those rotations and translations for later, so i just put that there.
but thanks for ur advice i have removed them now.

btw it's still not working.

any other suggestions that might fix this problem please.

regards

##### Share on other sites
To be honest, you have to struggle through debugging of an openGL code for yourself if you are beginner with it. It's hard but it's worth it. Once you do it, you will have a much better understanding of the thing. If not, well, you will come back with other questions and by doing this, you will learn much slower.

IMHO.

##### Share on other sites
Hi szecs,

i have been struggling with this for very long now...plz help me solve this if u can...i would highly appreciate it.

##### Share on other sites
What do you see?
Nothing drawn? Drawn in wrong place? Screwed? too small? too big? Wrongly oriented?

What thing have you tried so far? Just staring at the code won't do.

You have got a complete Display code. Did you try it?
Do you know what do the parameters of gluLookAt do? Did you try to change values of the parameters? (only one at a time!)

##### Share on other sites
Quote:
 Original post by szecsWhat do you see?Nothing drawn? Drawn in wrong place? Screwed? too small? too big? Wrongly oriented?What thing have you tried so far? Just staring at the code won't do.You have got a complete Display code. Did you try it?Do you know what do the parameters of gluLookAt do? Did you try to change values of the parameters? (only one at a time!)

with the look at command in the program, i see this:

the second cylinder( with length L2) being looked from negative z direction, but it looks as if the first cylinder (with length L1) is still being looked from the
positive z axis.

i am assuming this because if i am looking from behind the first cylinder (with length L1) which i presume being built at the (0,0,0) position, then when the second cylinder is being rotated by 90 abt y axis, i should just be able to some portion of the second cylinder being invisible coz of the first cylinder.

hope i am a bit more clear to you now. please bear with me. thnx

1. 1
Rutin
43
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633398
• Total Posts
3011659
• ### Who's Online (See full list)

There are no registered users currently online

×