Ejemplo n.º 1
0
/* X-Y平面に、ミートカーソルを描画する関数 */
void PrintEllipse(double r, int n, double x, double y, double z){
	PrintCircle(0.01, 10, x, y, z);
	glNormal3f(0.0, 0.0, 1.0);
	glBegin(GL_LINE_LOOP);
	glVertex3d(x + r, y, z);
	glVertex3d(x + 0.02, y, z);
	glEnd();
	glBegin(GL_LINE_LOOP);
	glVertex3d(x - r, y, z);
	glVertex3d(x - 0.02, y, z);
	glEnd();
	glBegin(GL_LINE_LOOP);
	glVertex3d(x, y + (r - 0.07), z);
	glVertex3d(x, y + 0.02, z);
	glEnd();
	glBegin(GL_LINE_LOOP);
	glVertex3d(x, y - 0.02, z);
	glVertex3d(x, y - (r - 0.07), z);
	glEnd();
	glBegin(GL_LINE_LOOP);
	for (int i = 0; i < n; i++){
		glVertex3f(x + r * cos(2.0 * 3.14926535 * ((double)i / n)), y + (r - 0.07) * sin(2.0 * 3.14926535 * ((double)i / n)), z);
	}
	glEnd();
}
Ejemplo n.º 2
0
void MakeCircle(char Array0[16], char Array1[16], char Array2[16],
		char Array3[16], char Array4[16], char Array5[16], char Array6[16],
		char Array7[16], char Array8[16], char Array9[16], char Array10[16],
		char Array11[16], char Array12[16], char Array13[16], char Array14[16],
		char Array15[16]) {
//deze methode stelt de een dataelement van het type fullcircle in om dan doorgestuurd te worden naar
//de LED strip, dus eigenlijk het genereren van een jagged array
	char jagged[16][16];
	for (int i = 0; i < 16; i++) {
		jagged[0][i] = Array0[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[1][i] = Array1[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[2][i] = Array2[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[3][i] = Array3[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[4][i] = Array4[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[5][i] = Array5[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[6][i] = Array6[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[7][i] = Array7[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[8][i] = Array8[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[9][i] = Array9[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[10][i] = Array10[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[11][i] = Array11[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[12][i] = Array12[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[13][i] = Array13[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[14][i] = Array14[i];
	}
	for (int i = 0; i < 16; i++) {
		jagged[15][i] = Array15[i];
	}
	//de jagged array wordt meteen doorgestuurd naar de LED's
	PrintCircle(jagged);
}
Ejemplo n.º 3
0
void TestPolygon()
{
	Point point[7] = {
		{ 100, 100 },
		{ 100, 600 },
		{ 200, 600 },
		//{ 200, 350 },
		{ 500, 350 },
		{ 500, 600 },
		{ 600, 600 },
		{ 600, 100 },
	};

	Polygon* polygon = CreatePolygon(7, point);
	PrintPolygon(polygon);

/*
	for (int i = 0; i < 50; ++i)
	{
		Point point = { (rand() % (800 * 10000) / 10000.f), (rand() % (640 * 10000) / 10000.f) };
		printf("circle(%f, %f, %f, \"%s\");\n", point.x, point.y, 5.f, PointInPolygon(&polygon, &point) ? "red" : "yellow");
	}*/

	Circle circle[200] = { 0 };
	for (int i = 0; i < 200; ++i)
	{
		float x = (rand() % (800 * 10000) / 10000.f);
		float y = (rand() % (640 * 10000) / 10000.f);
		float r = 20.f;
		circle[i].c.x = x;
		circle[i].c.y = y;
		circle[i].r = r;
	}

	for (int i = 0; i < 200; ++i)
	{
		PrintCircle(circle[i], IsCircleIntersectPolygon(&circle[i], polygon));
	}

	DeletePolygon(&polygon);
}
Ejemplo n.º 4
0
/*
* ディスプレイ関数
*/
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();
}