Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

knealeaj

Please help

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Everyone, I am currently writing a pool game and have drawn a pool table using a number of quads. The problem is that when the camera is directed at certain angles the quads have triangles sticking out of them and change size and number depending on the angle. I have fiddled around with gluPerspective but with no joy. Does anyone Know what the problem is and how to fix it?? Thanks Andy K

Share this post


Link to post
Share on other sites
Advertisement
could you be rendering your objects inside-out or maybe your push and pop commands for your modelview stack arn''t matching up, its really hard to tell without further detail on your problem. Are you importing your geometry from a file? please list some more details on your problem and maybe some code snippits for use to anylize your problem. thanks

Share this post


Link to post
Share on other sites
Here''s the initialisation code and the code that draws the walls in the room and the cushions of the table:



glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glFrontFace(GL_CCW);

// Now setup LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); // setup the ambient element
glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLight); // the diffuse element
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); // place the light in the world

// Enable the light
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);



glEnable(GL_TEXTURE_2D);






////////////////////////////////////////////////////////////////



void Background::Draw()
{

//Points for the quads for the table and the cushions

float backPoints[40][3] = { {-600.0,500.0,-600.0},{600.0,500.0,-600.0},{600.0,-100.0,-600.0},{-600.0,-100.0,-600.0},
{-600.0,500.0,600.0},{600.0,500.0,600.0},{600.0,-100.0,600.0},{-600.0,-100.0,600.0},
{-500.0,500.0,-600.0},{-500.0,500.0,600.0},{-500.0,-100.0,600.0},{-500.0,-100.0,-600.0},
{500.0,500.0,-600.0},{500.0,500.0,600.0},{500.0,-100.0,600.0},{500.0,-100.0,-600.0},
{500.0,-100.0,-600.0},{-500.0,-100.0,-600.0},{-500.0,-100.0,600.0},{500.0,-100.0,600.0},
{500.0,500.0,-600.0},{-500.0,500.0,-600.0},{-500.0,500.0,600.0},{500.0,500.0,600.0},
{-20.0,0.0,0.0},{-20.0,0.0,-500.0},{-20.0,10.0,-500.0},{-20.0,10.0,0.0},
{0.0,0.0,0.0},{-20.0,0.0,0.0},{-20.0,0.0,-500.0},{0.0,0.0,-500.0},
{0.0,10.0,0.0},{0.0,10.0,-500.0},{-20.0,10.0,-500.0},{-20.0,10.0,0.0},
{-20.0,0.0,0.0},{0.0,10.0,0.0},{0.0,10.0,-500.0},{-20.0,0.0,-500.0}};

glPushMatrix();


for(int i =0 ;i < 6; i++)
{
int a ; //use to repeat the texture of the floor in the scene

if(i == 4)
a = 4;
else a = 0;

glColor3f(1.0,1.0,1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, wallTex.texID);
glBegin(GL_QUADS);
glTexCoord2f(0.0,1.0+a);
glVertex3fv(backPoints[i+3*i]);
glTexCoord2f(1.0+a,1.0+a);
glVertex3fv(backPoints[i+1+3*i]);
glTexCoord2f(1.0+a,0.0);
glVertex3fv(backPoints[i+2+3*i]);
glTexCoord2f(0.0,0.0);
glVertex3fv(backPoints[i+3+3*i]);
glEnd();
glDisable(GL_TEXTURE_2D);
}

glPopMatrix();








for(int k = 0;k < 4;k++)
{glPushMatrix();
if((k == 0)||(k == 1))
{
glTranslatef(250.0*k,0.0,-500.0*k);
glRotatef(180.0*k,0.0,1.0,0.0);
}

if((k == 2)||(k == 3))
{

glScalef(0.58,1.0,1.0);
glTranslatef(465.0,0.0,0.0);

if( k == 3)
{
k=4; //use k = 4 to rotate cusion by 180.0 degrees

//x and z axis have been changed so tranlation on the x will give a
//translation on the z axis of the scene
glTranslatef(395.0,0.0,-500.0);
}

glRotatef(45.0*k,0.0,1.0,0.0);
}





for(int j =6 ;j <10; j++)
{
glEnable(GL_TEXTURE_2D);
switch(j)
{
case 6:
{

glBindTexture(GL_TEXTURE_2D, wallTex[9].texID);
}break;
case 7:
{

glBindTexture(GL_TEXTURE_2D, wallTex[8].texID);
}break;
case 8:
{
if((k == 0)||(k == 1))
{
glBindTexture(GL_TEXTURE_2D, wallTex[6].texID);
}

if((k == 2)||(k ==3)||(k==4))
glBindTexture(GL_TEXTURE_2D, wallTex[9].texID);

}break;
case 9:
{

glBindTexture(GL_TEXTURE_2D, wallTex[8].texID);
}break;
}//end switch



glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex3fv(backPoints[j+3*j]);
glTexCoord2f(1.0,0.0);
glVertex3fv(backPoints[j+1+3*j]);
glTexCoord2f(1.0,1.0);
glVertex3fv(backPoints[j+2+3*j]);
glTexCoord2f(0.0,1.0);
glVertex3fv(backPoints[j+3+3*j]);
glEnd();
glDisable(GL_TEXTURE_2D);



}



}

glPopMatrix();


Help if you can




Share this post


Link to post
Share on other sites
In your following code, i''m not sure what your doing, but your pushing 4 times onto the current stack (probably the modelview) and when your function ends it only pops once, so it looks like one problem is that your getting a stack overflow (I think most implementation support a stack depth of 32).


for(int k = 0;k < 4;k++)
{

glPushMatrix();
if((k == 0)||(k == 1))
{
glTranslatef(250.0*k,0.0,-500.0*k);
glRotatef(180.0*k,0.0,1.0,0.0);
}



Additionally you have a push and pop stack when you draw your initiail geometry but, it looks like your not modifing the stack in your draw methods, so you can take these out (you only need to push the stack when you have code that alters the top of it and you want to save (and evenually revert to) the transform before you make alterations.



glPushMatrix(); <-- not needed since your not making any changes to stack in code below


for(int i =0 ;i < 6; i++)
{
int a ; //use to repeat the texture of the floor in the scene


....
}

glPopMatrix(); <---not needed


anyways i hope this helps

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You will also want to take the int a; declaration out of the loop as you don''t need to declare the variable more than once and this is just a waste of time. You should also move your backpoints array out of the draw method and into a member variable of background as you don''t want to reassign 120 floating point numbers each time you draw.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!