Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In my code, I want to implement collision detection and for that i need to calculate bounding box for each object. Now, I am dynamically calculating the positions of objects in my code and hence not able to figure out how to retrieve that positions in array to compare for collision detection.

for (int k = 0; k < 10; k++)
{
    distance_x = 0.4 * cos(angle1*3.14 / 180);
    distance_y = 0.4 * sin(angle1*3.14 / 180);
    angle1 += 60;
    glPushMatrix();
    glRotatef(i, 0.0f, 0.0f, 1.0f);
    glTranslatef(distance_x, distance_y, 0.0f);
    glRotatef(-i, 0.0f, 0.0f, 1.0f);
  // how to retrieve the min, max cordinates for comparing collision detection?
    if (bounding_box)
        DrawRectangle(-0.05, -0.05, 2 * 0.05, 2 * 0.05, GL_LINE);      //this is a bounding box around circle which are rotating around central object
    DrawCircle(0.05, 0.0f, 0.0f, mode);
    glPopMatrix();
}


for (int k = 0; k < 10; k++)
{
    distance_x = 0.4 * cos(angle1*3.14 / 180);
    distance_y = 0.4 * sin(angle1*3.14 / 180);
    angle1 += 60;
    glPushMatrix();
    glRotatef(-j, 0.0f, 0.0f, 1.0f);
    glTranslatef(0.12f, 0.12f, 0.0f);
    glRotatef(j, 0.0f, 0.0f, 1.0f);
    glPushMatrix();
    glRotatef(j, 0.0f, 0.0f, 1.0f);
    glTranslatef(distance_x, distance_y, 0.0f);
    glRotatef(-j, 0.0f, 0.0f, 1.0f);
    if (bounding_box)    //this is a bounding box around circle which are rotating around circles drawn above
        DrawRectangle(-0.05, 0, 2 * 0.05, 0.05, GL_LINE);
    DrawTriangle(0.0f, 0.05f, -0.05f, 0.0f, 0.05f, 0, mode);
    glPopMatrix();
    glPopMatrix();
}
share|improve this question
    
It's all about code refactoring : have object with x,y, angle1 property, an update and a draw function, and build the bbox in the update. Use a math lib to compute coordinates, then use those transformed coordinates to draw directly without any glRotate or like. –  GameAlchemist Sep 13 '13 at 20:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.