• Advertisement
Sign in to follow this  

little help

This topic is 1862 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

I am doing the for loop to draw the bricks across the top of the screen. I am sorry for being kind of dense. I just don't understand how to get the collision detection to work.

Share this post


Link to post
Share on other sites
Advertisement
It means that if you remove “for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {” then none of the collidable bricks are drawn?
Then the problem is not in the graphics code. You will need to post your collision-detection code.


L. Spiro

Share this post


Link to post
Share on other sites

void Timer(int value)
{
if(x > windowWidth)
{
xstep = -xstep;
}

if( x < -windowWidth)
{
xstep=-xstep;
}

if(y > windowHeight)
{
ystep=-ystep;
}

if(y < -windowHeight)
{
ystep=-ystep;
}

x += xstep;
y += ystep*0.75f;

paddle_collision();

glutPostRedisplay();

glutTimerFunc(10,Timer,1);
}

here is my collision detection code

Share this post


Link to post
Share on other sites
I see no collision code there at all.



Us: Provide more information.
You: Here is 30% of the information you requested.
Us: Provide more information.




L. Spiro

Share this post


Link to post
Share on other sites
ok here is the collision detection I am using

if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f)
{
bricks[3][5]=0;
glColor3f(0.0f,0.0f,0.0f);
glRectf(3.0f,4.0f,5.0f,3.5f);
}

in this code the screen blinks on and off and on again.

Share this post


Link to post
Share on other sites
I have integrated spiros code into my code but it still does not do collision detection.
[source = c++]
void drawScene() {

glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,_textureId_four);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {
if ( g_bBlock.m_bActive ) {
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(g_bBlock.m_fX, g_bBlock.m_fY, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+2.0f, g_bBlock.m_fY, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+2.0f, g_bBlock.m_fY-0.5f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(g_bBlock.m_fX, g_bBlock.m_fY-0.5f , 0.0f);
glEnd();
}
}

glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,_textureId_three);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {
if ( g_bBlock.m_bActive ) {
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(g_bBlock.m_fX, g_bBlock.m_fY-0.5f, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+2.0f, g_bBlock.m_fY-0.5f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+2.0f, g_bBlock.m_fY-1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(g_bBlock.m_fX, g_bBlock.m_fY-1.0f, 0.0f);
glEnd();
}
}

glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,_textureId);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {
if ( g_bBlock.m_bActive ) {
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(g_bBlock.m_fX, g_bBlock.m_fY-1.0f, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+2.0f, g_bBlock.m_fY-1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+2.0f, g_bBlock.m_fY-1.5f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(g_bBlock.m_fX, g_bBlock.m_fY-1.5f, 0.0f);
glEnd();
}
}

glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,_textureId_two);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//draw paddle
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(-1.0f+j, -4.5f, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(1.0f+j, -4.5f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(1.0f+j, -5.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f+j, -5.0f, 0.0f);
glEnd();

glDisable(GL_TEXTURE_2D);

if(x>=3.0f && x<=5.0f && y>=3.5f && y<=4.0f)
{
bricks[3][5]=0;
glColor3f(0.0f,0.0f,0.0f);
glRectf(3.0f,4.0f,5.0f,3.5f);
}

//draw ball
glColor3f(1.0f,1.0f,1.0f);

glRectf(x,y,x+rsize,y-rsize);

glutSwapBuffers();
}
[/source]
I made some adjustments to her code.

Share this post


Link to post
Share on other sites
Look at the rendering code.
if ( g_bBlock.m_bActive ) {

Do you not understand what this does?
Obviously if you want a brick to stop being drawn you have to set this to false.


L. Spiro

Share this post


Link to post
Share on other sites
this is a Boolean array object if it is true then it draws a brick, if it is false then it does not draw a brick. my question is where do I put this code into.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement