void catcher() { try // <=== gcc 2.* fails here { pitcher(); } catch (ball) { /* sleepy catcher doing nothing */ ; } }
/* * ディスプレイ関数 */ static void display(void) { const static GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; /* ���̐F */ const static GLfloat lightpos[] = { 12.0, 16.0, 20.0, 1.0 }; /* �����̈ʒu */ /* ���ʃN���A */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); t = dt * tn; /* ���f���r���[�ϊ��s���̏����� */ glLoadIdentity(); if (batted) gluLookAt(px, py, pz, px, py - 2, pz - 15, 0, 0.8, 0.4); else gluLookAt(0, 0, 0, cam_x, cam_y, cam_z, 0, 1, 0); glLightfv(GL_LIGHT0, GL_POSITION, lightpos); /* 回転 */ glRotated(cam_x_angle, 1.0, 0.0, 0.0); glRotated(cam_y_angle, 0.0, 1.0, 0.0); /* �����̈ʒu���ݒ� */ /* カメラの位置 */ glTranslated(cam_x, cam_y, cam_z); zone(); // ストライクゾーンの描画 myGround(0.0); // 大地の描画 base(); //ホームベースの描画 line(); //塁線の描画 scoreboard(0, -60, 15.0, 3.5, 1.25); //scoreboard(1, -60, 1.7, 1.5, 3.0); //scoreboard(2, -60, 1.1, 0.56, 3.75); //myBox(15, 13, 5, 0, 1, -80); //glPushMatrix(); //glRotated(10, 1.0, 0.0, 0.0); //myPalse(0.0, 5.0, -10.0, 10.0, 8.0, 90); //glPopMatrix(); tn++; /* ピッチャーの描画 */ pitcher(QX, QY - 0.9, QZ); if (batted){ // 打球の軌道計算 px = mx + vx * (t - 2.0); py = my + 0.5 * G * (t - 2.0) * (t - 2.0) + vy * (t - 2.0); pz = 16.0 + 6.5 + 0.5 * az * (t - 2.0) * (t - 2.0) + vz * (t - 2.0); /*px = px_achieve + vx * t; py = py_achieve + 0.5 * G * t * t + vy * t; pz = 18.0 + 0.5 * az * t * t + vz * t;*/ } else { // 投球の軌道計算 px = vx * (t - 2.0) + QX; py = 0.5 * G * (t - 2.0) * (t - 2.0) + vy * (t - 2.0) + QY; pz = 0.5 * az * (t - 2.0) * (t - 2.0) + vz * (t - 2.0) + QZ; } /* 着弾点の x, y座標を計算 */ if (pz < 18.0){ t_achieve = (-vz + sqrt(vz * vz + 2 * az * 18.0)) / az; px_achieve = vx * t_achieve + QX; py_achieve = 0.5 * G * t_achieve * t_achieve + vy * t_achieve + QY; } //printf("t = %f\n", t); //printf("(px, py, pz) = (%f, %f, %f)\n", px, py, pz); //printf("(vx, vy, vz) = (%f, %f, %f)\n", vx, vy, vz); /* 床との衝突 */ if (py < R){ py = R; vy *= -A; } /* スライダー */ if (species == 1 && pz > 12 && pz < 18) { vx += 0.002 * pow(t, 4); } /* カーブ */ if (species == 2 && pz > 12 && pz < 18) { vx += 0.001 * pow(t, 4); vy -= 0.002 * pow(t, 4); } /* スプリット */ if (species == 3 && pz > 12 && pz < 18) { vy -= 0.002 * pow(t, 4); } /* シンカー */ if (species == 4 && pz > 12 && pz < 18) { vx -= 0.001 * pow(t, 4); vy -= 0.002 * pow(t, 4); } /* シュート */ if (species == 5 && pz > 12 && pz < 18) { vx -= 0.002 * pow(t, 4); } /* ライジングキャノン */ if (species == 6 && pz > 12 && pz < 18){ vy += 0.0015 * pow(t, 4); } /* Wボール */ if (species == 7 && pz > 6 && pz < 9){ vy -= 0.04 * pow(t, 4); } else if (species == 7 && pz > 9 && pz < 12){ vy += 0.09 * pow(t, 4); } else if (species == 7 && pz > 12 && pz < 15){ vy -= 0.07 * pow(t, 4); } else if (species == 7 && pz > 15 && pz < 18){ vy += 0.04 * pow(t, 4); } char species_name[][15] = { "STRAIGHT", "SLIDER", "CURVE", "SFF", "SINKER", "SHOOT", "RISING_CANON", "W_BALL" }; /* 球速の表示 */ char str[100], vz_s[4] = { '\0' }, pz_s[4]; if (t > t_achieve - 0.01 && t < t_achieve + 0.01){ vz_achieve = vz; } if (t > t_achieve + 1.8){ sprintf_s(vz_s, "%3d", (int)(vz_achieve * 2.7)); strcpy_s(str, "Speed: "); strcat_s(str, vz_s); strcat_s(str, "km/h"); //strcat_s(str, species[key]); if ((fabs(px_achieve) < 0.3 && py_achieve > 1.0 && py_achieve < 1.7) || (swinged == 1 && hitted == 0)) { strcpy_s(judge, " Judge: STRIKE! Count: S| "); } else if (vz < 0){ strcpy_s(judge, " Judge: HIT! Count: S| "); } else if (!(fabs(px_achieve) < 0.3 && py_achieve > 1.0 && py_achieve < 1.7)) { strcpy_s(judge, " Judge: BALL. Count: S| "); } for (int i = 0; i < s_count; i++)strcat_s(judge, "*"); strcat_s(judge, " B| "); for (int i = 0; i < b_count; i++)strcat_s(judge, "*"); if (out == 1)strcat_s(judge, " BATTER OUT!"); else if (four == 1)strcat_s(judge, " FOUR BALL!"); //else if (az < 0) strcat_s(judge, " HIT!"); strcat_s(str, judge); strcat_s(str, " Species: "); strcat_s(str, species_name[species]); if (batted == 1){ fd = hypot(px, -pz + 18.0); sprintf_s(pz_s, "%3d", (int)(fd)); strcat_s(str, " Frying Distance: "); strcat_s(str, pz_s); strcat_s(str, "m"); } DrawString(str, 500, 200, 100, 10); } /* 着弾点を表示 */ if (pitched){ GLfloat white[] = { 1.f, 1.f, 1.f }; if (t > 1.0 && t < 2.0){ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white); PrintCircle(2.0 - 1.0 * t + R, 100, px_achieve, py_achieve, 18.0); //円を描画 (半径, 分割数, X座標, Y座標, Z座標) } else if (t > 2.0){ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white); PrintCircle(R, 100, px_achieve, py_achieve, 18.0); } if (t < 2.0){ arm_angle = 50 * t * t; } else if (t > 1.8 && t < 2.17){ arm_angle += 2.0 * t * t; } } if (swinged){ bat_angle += VS; } if (bat_angle > 300){ bat_angle = 300; } /* 衝突時の処理 */ if (hitted){ bat_angle_hitted = bat_angle + 400 * (2 * t_achieve - 2 * swinged_time + 2.15); // ボールと衝突時のバットの角度を計算 //th = 10 * PI / 180; th = (2 * (bat_angle_hitted - 180) - phi) * PI / 180; /* 打球のY-Z平面となす角度の計算 */ //r = (200 * (py_achieve - my + 0.1) / 0.125) * PI / 180; /* 打球とX-Z平面となす角度の計算 */ r = 195 * PI / 180; v = -0.3500 / (fabs(mx - px_achieve) + fabs(my - py_achieve)) * 0.5 * 4; px = px_achieve; py = py_achieve; pz = 18.0; az = -0.1; vx = v * sin(th) * cos(r); vy = v * sin(r); vz = v * cos(th) * cos(r); hitted = 0; printf("th = %f\n dt = %f\n",th,t_achieve - swinged_time + 2.0); } if (t > 2.0 && pitched){ glPushMatrix(); glTranslated(px, py, pz); glMaterialfv(GL_FRONT, GL_DIFFUSE, white); glutSolidSphere(R, 16, 8); glPopMatrix(); } /* バッターの描画 */ batter(mx - 1.2, my - 0.6, 18.0); /* バット */ glPushMatrix(); glTranslated(mx - 1.2, my, 18.0); glRotated(bat_angle, 0.0, 1.0, 0.0); glTranslated(-0.8, 0, 0); glEnable(GL_NORMALIZE); GLfloat bat_color[] = { 0.9, 0.7, 0.3, 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, bat_color); glScalef(1.f, 0.07f, 0.05f); displaySphere(0.5f, 0.8f, 0.8f, 0.8f, 0.2f, 0.2f, 0.2f, 10.f); glDisable(GL_NORMALIZE); glPopMatrix(); /* ミートカーソルの表示 */ GLfloat yellow[] = { 1.f, 1.f, 0.f, 1.f }; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, yellow); PrintEllipse(R + 0.1, 100, mx, my, mz); glutSwapBuffers(); }