PDA

View Full Version : using camera, but objects are being drawn above my view



Andrew Davey
04-27-2004, 07:29 AM
I am using gluLookAt and have got a camera working, but my objects seen to get drawn in the sky. When they should in fact be drawn on the ground.

the picture shows my problem.
http://www.tb21.co.uk/images/picture.JPG

Can anyone think of the problem. My display for that sub window is:


void sTree_display(void){


glClearColor(0.4,0.4,0.9,0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//reset the position to 0,0,0
glLoadIdentity();

gluLookAt(cam_pos.x,cam_pos.y,cam_pos.z,cam_view.x ,cam_view.y,cam_view.z,0,1,0);

glPushMatrix();
//draw a ground
sTree_ground();

glPushMatrix();
//draw the sun
sun_drawSun();


glPushMatrix();
//loop through the trees
for(tree_loop=0;tree_loop<treeCount;tree_loop++){

if(tree_loop==treeCount+1){
//ignore

}else{

glColor3f(tree[tree_loop]->treeColour.r,tree[tree_loop]->treeColour.g,tree[tree_loop]->treeColour.b);


sTree_drawTree(tree[tree_loop]);


if(!tree[tree_loop]->endBool){
//this checks if there are any branches and then increments the branch origY
if(tree[tree_loop]->branchCount > 0) error = sTree_moveBranchesUpTrunk(tree[tree_loop]);
//ammend the dirBias of the given tree
sun_ammendBias(tree[tree_loop]);

if(error) printf("hmmm\n");
}//endBool

}//if(i==br+1)

}//for(treearray)

glPopMatrix();
glPopMatrix();
glPopMatrix();
//swap the buffers to display what just got drawn.
glutSwapBuffers();

}//sTree_display(VOID)Can someone see an obvious problem??? or at least have an educated guess. Cheers.

04-27-2004, 10:07 AM
I don't see any glTranslate calls,so I assume there are inside the draw* calss.In that case,you're handling the matrix stack the wrong way.You push the matrix,draw the sun,and then you draw the trees without restoring the matrix.No wonder the trees are drawn in the sky,just like the sun!
The proper way to do things is:

glPushMatrix();
PlaceObject();
DrawObject();
glPopMatrix();

Andrew Davey
04-27-2004, 10:47 AM
oops. No i didnt do what you assumed and the order for push and pop was also wrong.

Cheers it worked and helped.