/// <summary> /// 单鱼推球过程中的数据记录,记录完成第一次完成各个单程的时间,及共完成单程的个数 /// </summary> private void DataProcessingOnPushingBall() { MyMission myMission = MyMission.Instance();//当前仿真使命的信息 FishSingleFishPushBallAvoidObstacles fish = Teams[0].Fishes[0]; Ball ball = myMission.EnvRef.Balls[0]; //记录完成每个单程的时间和完成的单程数目 if ((fish.PositionMm.X > (myMission.EnvRef.ObstaclesRect[0].PositionMm.X + fish.BodyLength) && (finishedCountOneWay == 0))) {//判断完成第一次完成第一个单程 finshedTimeOneWay[0] = myMission.ParasRef.TotalSeconds - myMission.ParasRef.RemainingCycles / myMission.ParasRef.MsPerCycle; finishedCountOneWay = 1; } else if ((fish.PositionMm.X > (myMission.EnvRef.ObstaclesRect[9].PositionMm.X + fish.BodyLength) && (finishedCountOneWay == 1))) {//判断完成第一次完成第二个单程 finshedTimeOneWay[1] = myMission.ParasRef.TotalSeconds - myMission.ParasRef.RemainingCycles / myMission.ParasRef.MsPerCycle;; finishedCountOneWay = 2; } else if ((fish.PositionMm.X < (myMission.EnvRef.ObstaclesRect[9].PositionMm.X - fish.BodyLength) && (finishedCountOneWay == 2)) && (ball.PositionMm.X < (myMission.EnvRef.ObstaclesRect[9].PositionMm.X - ball.RadiusMm * 2))) {//判断完成第一次完成第三个单程 finshedTimeOneWay[2] = myMission.ParasRef.TotalSeconds - myMission.ParasRef.RemainingCycles / myMission.ParasRef.MsPerCycle;; finishedCountOneWay = 3; } else if ((fish.PositionMm.X < (myMission.EnvRef.ObstaclesRect[0].PositionMm.X - fish.BodyLength) && (finishedCountOneWay == 3)) && (ball.PositionMm.X < (myMission.EnvRef.ObstaclesRect[0].PositionMm.X - ball.RadiusMm * 2))) {//判断完成第一次完成第四个单程 finshedTimeOneWay[3] = myMission.ParasRef.TotalSeconds - myMission.ParasRef.RemainingCycles / myMission.ParasRef.MsPerCycle;; finishedCountOneWay = 4; } }
/// <summary> /// 单鱼推球避障,机器鱼或者球碰到障碍物的处理 /// </summary> private void HandleWhileFoul() { MyMission myMission = MyMission.Instance();//当前仿真使命的信息 FishSingleFishPushBallAvoidObstacles fish = Teams[0].Fishes[0]; Ball ball = myMission.EnvRef.Balls[0]; //myMission.ParasRef.IsPauseNeeded = true;//这里还待考虑 if (collisionFishAndObstacles) { System.Windows.Forms.MessageBox.Show(" Collision between Fish and Obstacles", "Time - 5s"); CommonPara.RemainingCycles -= 5000 / CommonPara.MsPerCycle; // 有鱼碰到障碍物的犯规情况出现时,将鱼移到已完成单程,进入下一个单程的初始位置; if (finishedCountOneWay == 0) { fish.PositionMm.X = myMission.EnvRef.ObstaclesRect[1].PositionMm.X - myMission.EnvRef.ObstaclesRect[1].LengthMm - fish.BodyLength; fish.PositionMm.Z = myMission.EnvRef.ObstaclesRect[4].PositionMm.Z - myMission.EnvRef.ObstaclesRect[4].WidthMm + fish.BodyWidth; fish.BodyDirectionRad = 0; fish.VelocityDirectionRad = 0; } else if (finishedCountOneWay == 1) { fish.PositionMm.X = myMission.EnvRef.ObstaclesRect[4].PositionMm.X + myMission.EnvRef.ObstaclesRect[4].LengthMm + fish.BodyLength; fish.PositionMm.Z = myMission.EnvRef.ObstaclesRect[4].PositionMm.Z + myMission.EnvRef.ObstaclesRect[4].WidthMm + fish.BodyWidth; fish.BodyDirectionRad = 0; fish.VelocityDirectionRad = 0; } else if (finishedCountOneWay == 2) { fish.PositionMm.X = myMission.EnvRef.ObstaclesRect[9].PositionMm.X + myMission.EnvRef.ObstaclesRect[9].LengthMm + fish.BodyLength; fish.PositionMm.Z = myMission.EnvRef.ObstaclesRect[9].PositionMm.Z + myMission.EnvRef.ObstaclesRect[9].WidthMm + fish.BodyWidth; fish.BodyDirectionRad = (float)Math.PI; fish.VelocityDirectionRad = 0; } else if (finishedCountOneWay == 3) { fish.PositionMm.X = myMission.EnvRef.ObstaclesRect[4].PositionMm.X - myMission.EnvRef.ObstaclesRect[4].LengthMm - fish.BodyLength; fish.PositionMm.Z = myMission.EnvRef.ObstaclesRect[4].PositionMm.Z + myMission.EnvRef.ObstaclesRect[4].WidthMm + fish.BodyWidth; fish.BodyDirectionRad = (float)Math.PI; fish.VelocityDirectionRad = 0; } collisionFishAndObstacles = false; presentCollisionCycle = CommonPara.RemainingCycles; collisionFlag = true; } if (collisionBallAndObstacles) { System.Windows.Forms.MessageBox.Show("Collision between Ball and Obstacles", "Time - 3s"); CommonPara.RemainingCycles -= 3000 / CommonPara.MsPerCycle; // 有球撞到障碍物的犯规情况出现时,球也移到相应的位置 if ((finishedCountOneWay == 0) || (finishedCountOneWay == 1) || (finishedCountOneWay == 2))//完成2个单程之前,球都应该保持在初始位置附近 { //球的初始位置 ball.PositionMm.X = 1030; ball.PositionMm.Z = 0; ball.VelocityMmPs = 0; ball.VelocityDirectionRad = 0; } else if (finishedCountOneWay == 3)//已经只差最后一个单程了,此时球在碰到障碍物设置球在原点 { ball.PositionMm.X = 0; ball.PositionMm.Z = 0; ball.VelocityMmPs = 0; ball.VelocityDirectionRad = 0; } collisionBallAndObstacles = false; presentCollisionCycle = CommonPara.RemainingCycles; collisionFlag = true; } }