void GameWindow::paintEvent(QPaintEvent *){ QPainter painter(this); QPen pen; // Label home territory pen.setColor(Qt::blue); pen.setWidth(2); painter.setPen(pen); painter.setFont(QFont("Arial", 16)); painter.drawText( homeX+150, 40, "Allied Waters"); // Label enemy territory pen.setColor(Qt::red); pen.setWidth(2); painter.setPen(pen); painter.drawText( enemyX+150, 40, "Enemy Waters"); // Draw the seas pen.setColor(Qt::blue); QBrush brush; brush.setColor(Qt::cyan); brush.setStyle(Qt::Dense4Pattern); painter.setBrush(brush); painter.setPen(pen); painter.drawRect( homeX, homeY, 400, 400); painter.drawRect( enemyX, enemyY, 400, 400); brush.setStyle(Qt::NoBrush); painter.setBrush(brush); // Draw webs on the seas drawWeb( painter, homeX, homeY, 80, 5); drawWeb( painter, enemyX, enemyY, 80, 5); drawFire( fireX, fireY); // Draw ships if( isServer ){ Ship s = Ship( homeX, homeY, 3); s.blocks[1]=KILLED; drawShip(s); } else { Ship s = Ship( homeX, homeY, 3); drawShip(s); } }
// We are going to override (is that the right word?) the draw() // method of ModelerView to draw out SampleModel void SampleModel::draw() { // This call takes care of a lot of the nasty projection // matrix stuff. Unless you want to fudge directly with the // projection matrix, don't bother with this ... ModelerView::draw(); // draw the floor setAmbientColor(.1f,.1f,.1f); setDiffuseColor(1, 1, 1); //drawSphere(6.0); // drawTwoBalls(); drawWeb(9, 15); setDiffuseColor(0.5f, 0.4f, 0.4f); #define DETAIL (VAL(LEVEL_OF_DETAIL)) if (currMood != VAL(MOOD)) { setMood(); currMood = VAL(MOOD); } if (VAL(ANIMATE)) { animate(); } // whole glPushMatrix(); glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS)); glTranslated(0, 1.5, 0); glRotated(VAL(SPIDER_ROTATE_Z), 0, 0, 1); if (DETAIL >= 1) { // belly glPushMatrix(); glTranslated(1.5, 0, 0); glScaled(1.1, 0.7, 0.8); drawSphere(1.2); // spinneret if (DETAIL >= 2) { glPushMatrix(); glTranslated(1.1, 0, 0); glRotated(VAL(SPINNERET_ROTATE_Y), 0, 1, 0); // 90 glRotated(VAL(SPINNERET_ROTATE_X), 1, 0, 0); // 0 drawCylinder(0.3, 0.2, 0); glPopMatrix(); } glPopMatrix(); } if (DETAIL >= 1) { // body if (DETAIL >= 2) { glPushMatrix(); glRotated(VAL(BODY_ROTATE_Z), 0, 0, 1); glPushMatrix(); glScaled(1.3, 1, 1); drawSphere(0.5); glPopMatrix(); // legs if (DETAIL >= 3) { // left legs glPushMatrix(); glTranslated(0, 0, 0.3); if (DETAIL >= 4) { // left 1 glPushMatrix(); glRotated(VAL(LEFT_LEG_1_1_ROTATE_Y), 0, 1, 0); // -60 glRotated(VAL(LEFT_LEG_1_1_ROTATE_X), 1, 0, 0); // -30 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(LEFT_LEG_1_2_ROTATE_Y), 0, 1, 0); // -40 glRotated(VAL(LEFT_LEG_1_2_ROTATE_X), 1, 0, 0); // 50 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(LEFT_LEG_1_3_ROTATE_Y), 0, 1, 0); // -20 glRotated(VAL(LEFT_LEG_1_3_ROTATE_X), 1, 0, 0); // 20 drawCylinder(2, 0.1, 0); // drawSphere(0.2); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // left 2 glPushMatrix(); glRotated(VAL(LEFT_LEG_2_1_ROTATE_Y), 0, 1, 0); // -30 glRotated(VAL(LEFT_LEG_2_1_ROTATE_X), 1, 0, 0); // -25 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(LEFT_LEG_2_2_ROTATE_Y), 0, 1, 0); // -30 glRotated(VAL(LEFT_LEG_2_2_ROTATE_X), 1, 0, 0); // 40 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(LEFT_LEG_2_3_ROTATE_Y), 0, 1, 0); // -20 glRotated(VAL(LEFT_LEG_2_3_ROTATE_X), 1, 0, 0); // 30 drawCylinder(1.5, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // left 3 glPushMatrix(); glRotated(VAL(LEFT_LEG_3_1_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(LEFT_LEG_3_1_ROTATE_X), 1, 0, 0); // -30 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(LEFT_LEG_3_2_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(LEFT_LEG_3_2_ROTATE_X), 1, 0, 0); // 50 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(LEFT_LEG_3_3_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(LEFT_LEG_3_3_ROTATE_X), 1, 0, 0); // 40 drawCylinder(1.5, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // left 4 glPushMatrix(); glRotated(VAL(LEFT_LEG_4_1_ROTATE_Y), 0, 1, 0); // 60 glRotated(VAL(LEFT_LEG_4_1_ROTATE_X), 1, 0, 0); // -20 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(LEFT_LEG_4_2_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(LEFT_LEG_4_2_ROTATE_X), 1, 0, 0); // 40 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(LEFT_LEG_4_3_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(LEFT_LEG_4_3_ROTATE_X), 1, 0, 0); // 20 drawCylinder(2, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // right legs glPushMatrix(); glTranslated(0, 0, -0.3); if (DETAIL >= 4) { // right 1 glPushMatrix(); glRotated(VAL(RIGHT_LEG_1_1_ROTATE_Y), 0, 1, 0); // -60 glRotated(VAL(RIGHT_LEG_1_1_ROTATE_X), 1, 0, 0); // -30 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(RIGHT_LEG_1_2_ROTATE_Y), 0, 1, 0); // -40 glRotated(VAL(RIGHT_LEG_1_2_ROTATE_X), 1, 0, 0); // 50 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(RIGHT_LEG_1_3_ROTATE_Y), 0, 1, 0); // -20 glRotated(VAL(RIGHT_LEG_1_3_ROTATE_X), 1, 0, 0); // 20 drawCylinder(2, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // right 2 glPushMatrix(); glRotated(VAL(RIGHT_LEG_2_1_ROTATE_Y), 0, 1, 0); // -30 glRotated(VAL(RIGHT_LEG_2_1_ROTATE_X), 1, 0, 0); // -25 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(RIGHT_LEG_2_2_ROTATE_Y), 0, 1, 0); // -30 glRotated(VAL(RIGHT_LEG_2_2_ROTATE_X), 1, 0, 0); // 40 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(RIGHT_LEG_2_3_ROTATE_Y), 0, 1, 0); // -20 glRotated(VAL(RIGHT_LEG_2_3_ROTATE_X), 1, 0, 0); // 30 drawCylinder(1.5, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // right 3 glPushMatrix(); glRotated(VAL(RIGHT_LEG_3_1_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(RIGHT_LEG_3_1_ROTATE_X), 1, 0, 0); // -30 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(RIGHT_LEG_3_2_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(RIGHT_LEG_3_2_ROTATE_X), 1, 0, 0); // 50 drawCylinder(1.5, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 1.5); glRotated(VAL(RIGHT_LEG_3_3_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(RIGHT_LEG_3_3_ROTATE_X), 1, 0, 0); // 40 drawCylinder(1.5, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); // right 4 glPushMatrix(); glRotated(VAL(RIGHT_LEG_4_1_ROTATE_Y), 0, 1, 0); // 60 glRotated(VAL(RIGHT_LEG_4_1_ROTATE_X), 1, 0, 0); // -20 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(RIGHT_LEG_4_2_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(RIGHT_LEG_4_2_ROTATE_X), 1, 0, 0); // 40 drawCylinder(2, 0.1, 0.1); if (DETAIL >= 6) { glPushMatrix(); glTranslated(0, 0, 2); glRotated(VAL(RIGHT_LEG_4_3_ROTATE_Y), 0, 1, 0); // 20 glRotated(VAL(RIGHT_LEG_4_3_ROTATE_X), 1, 0, 0); // 20 drawCylinder(2, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); } glPopMatrix(); } if (DETAIL >= 3) { // head glPushMatrix(); glTranslated(-0.6, 0, 0); drawSphere(0.5); if (DETAIL >= 4) { // left tooth glPushMatrix(); glTranslated(-0.3, 0, 0.2); glRotated(VAL(LEFT_TOOTH_ROTATE_Y), 0, 1, 0); drawCylinder(0.25, 0.25, 0.05); glPopMatrix(); // right tooth glPushMatrix(); glTranslated(-0.3, 0, -0.2); glRotated(VAL(RIGHT_TOOTH_ROTATE_Y), 0, 1, 0); drawCylinder(0.25, 0.25, 0.05); glPopMatrix(); // left antenna glPushMatrix(); glTranslated(-0.3, 0, 0.4); glRotated(VAL(LEFT_ANTENNA_ROTATE_Y), 0, 1, 0); // -75 glRotated(VAL(LEFT_ANTENNA_ROTATE_X), 1, 0, 0); // -30 drawCylinder(1, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 1); glRotated(VAL(LEFT_ANTENNA_UPPER_ROTATE_Y), 0, 1, 0); // -30 glRotated(VAL(LEFT_ANTENNA_UPPER_ROTATE_X), 1, 0, 0); // 45 drawCylinder(0.7, 0.1, 0); glPopMatrix(); } glPopMatrix(); // right antenna glPushMatrix(); glTranslated(-0.3, 0, -0.4); glRotated(VAL(RIGHT_ANTENNA_ROTATE_Y), 0, 1, 0); glRotated(VAL(RIGHT_ANTENNA_ROTATE_X), 1, 0, 0); drawCylinder(1, 0.1, 0.1); if (DETAIL >= 5) { glPushMatrix(); glTranslated(0, 0, 1); glRotated(VAL(RIGHT_ANTENNA_UPPER_ROTATE_Y), 0, 1, 0); glRotated(VAL(RIGHT_ANTENNA_UPPER_ROTATE_X), 1, 0, 0); drawCylinder(0.7, 0.1, 0); glPopMatrix(); } glPopMatrix(); } glPopMatrix(); } glPopMatrix(); } } glPopMatrix(); }