Namratha and sweekruthi worked on this existing project. The modification done to the sinking ship project that has been done is the ice berg becomes two pieces... both the pieces move down and sink.
Here are the snaps:
Moving....
Collison....
Pieces of iceberg and ship sinking....
I just want to add something to explain how this pieces of ice cube and their rotation was achieved.
Here is the code which does the trick.
/* TO DRAW ICEBERG */
void ice()
{
glPushMatrix();
glTranslated(450,50,0.0);
glScaled(10,10,0);
glColor3f(0.0,1.0,1.0);
if(c>0) // This flag is used to indicate if ice berg is
{glPushMatrix(); // intact or split into two after collision
glTranslated(0,x,0); //move the ice bergs down all the while rotating them.
glPushMatrix();
glTranslated(7,2,0.0);
glRotated(-x,0,0,1); // clockwise for the right piece.
glTranslated(-7,-2,0.0);
glBegin(GL_POLYGON);
glVertex2f(7,2);
glVertex2f(8,3);
glVertex2f(11,18);
glVertex2f(12,19);
glVertex2f(12,3);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslated(12,3,0.0);
glRotated(x,0,0,1); // anti clock wise for the left piece.
glTranslated(-12,-3,0.0);
glBegin(GL_POLYGON);
glVertex2f(12,3);
glVertex2f(12,19);
glVertex2f(17,18);
glVertex2f(18,3);
glVertex2f(19,3);
glEnd();
glPopMatrix();
glPopMatrix();
}
else // if ice berg is intact draw one piece
{ // without any transformations
glBegin(GL_POLYGON);
glVertex2f(7,2);
glVertex2f(8,3);
glVertex2f(11,18);
glVertex2f(12,19);
glVertex2f(12,3);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(12,3);
glVertex2f(12,19);
glVertex2f(17,18);
glVertex2f(18,3);
glVertex2f(19,3);
glEnd();
}
glPopMatrix();
}
The variable c is global and it is set in the display function
like this...
if(b>250)
{
c+=10;
display3();
}
Here is the complete
code.