Пример #1
0
 private void PrepNodeForDelete()
 {
     this.trajectory.Clear();
     this.timeOfHit         = string.Empty;
     this.ESN               = string.Empty;
     this.carryPoint        = null;
     this.clubTypeID        = string.Empty;
     this.carry             = 0f;
     this.side              = 0f;
     this.maxHeight         = 0f;
     this.travelTime        = 0f;
     this.clubSpeed         = 0f;
     this.smashFactor       = 0f;
     this.attackAngle       = 0f;
     this.launchAngle       = 0f;
     this.descentAngle      = 0f;
     this.backSpin          = 0f;
     this.horizontalAngle   = 0f;
     this.sideSpin          = 0f;
     this.totalSpeedMPH     = 0f;
     this.offline           = 0f;
     this.roll              = 0f;
     this.spinAxis          = 0f;
     this.totalSpin         = 0f;
     this.carryPosX         = 0f;
     this.carryPosY         = 0f;
     this.totalPosX         = 0f;
     this.totalPosY         = 0f;
     this.courseConditionId = 0;
     this.clubName          = string.Empty;
     this.dataIsNotDeleted  = false;
 }
Пример #2
0
    public void AddPointOffset(Vector3 point, float time)
    {
        TFlightPoint tFlightPoint = new TFlightPoint()
        {
            location = point + new Vector3(118.54f, 0.02f, 0f),
            time     = time
        };

        this.trajectory.Add(tFlightPoint);
    }
Пример #3
0
    public void AddPoint(Vector3 point, float time)
    {
        TFlightPoint tFlightPoint = new TFlightPoint()
        {
            location = point,
            time     = time
        };

        this.trajectory.Add(tFlightPoint);
    }
Пример #4
0
 public void AddBallCurrentPoint()
 {
     if (this.ballTransform != null)
     {
         Vector3 vector3 = this.ballTransform.position - this.prev;
         this.isMoving = vector3.sqrMagnitude > 0.0001f;
         this.prev     = this.ballTransform.position;
         if (this.isMoving)
         {
             float        single       = Time.time - float.Parse(this.timeOfHit);
             TFlightPoint tFlightPoint = new TFlightPoint()
             {
                 time     = single,
                 location = this.ballTransform.position
             };
             this.AddPoint(this.ballTransform.position, single);
         }
     }
 }
Пример #5
0
    public static List <TFlightPoint> GenerateMissingTrajectory(TFlightData data)
    {
        if (data == null)
        {
            Debug.LogError("Data is null: Empty trajectory generated");
            return(new List <TFlightPoint>());
        }
        CBallFlightManager instance = CBallFlightManager.GetInstance();

        if (instance == null)
        {
            Debug.LogError("Flight Manager is null: Empty trajectory generated");
            return(new List <TFlightPoint>());
        }
        if (WeatherManager.instance != null)
        {
            instance.SetWeather(WeatherManager.instance.altitude, WeatherManager.instance.temperature, WeatherManager.instance.humindity, WeatherManager.barometer, WeatherManager.instance.windSpeed, (double)WeatherManager.instance.windDirection);
        }
        else
        {
            instance.SetWeather(0, 70, 50, WeatherManager.barometer, 0, 90);
        }
        //GrassManager.instance.SetGrassType((GrassManager.GrassType)data.courseConditionId);
        instance.CalculateCollision((double)data.totalSpeedMPH, (double)data.launchAngle, (double)data.horizontalAngle, (double)data.backSpin, (double)data.sideSpin);
        Vector3             vector3        = new Vector3(118.5399f, 0.06167692f, 0f);
        BallTrajectory      ballTrajectory = instance.CalculateFlightTrajectory(vector3, (double)data.totalSpeedMPH, (double)data.launchAngle, (double)data.backSpin, (double)(-1f * data.sideSpin), (double)data.side, data.isLefty, null);
        List <TFlightPoint> tFlightPoints  = new List <TFlightPoint>();

        for (int i = 0; i < ballTrajectory.m_points.Count; i++)
        {
            TFlightPoint tFlightPoint = new TFlightPoint()
            {
                location = ballTrajectory.m_points[i].pos,
                time     = ballTrajectory.m_points[i].time
            };
            tFlightPoints.Add(tFlightPoint);
            if (ballTrajectory.firstBounceFrame == i)
            {
                data.carryPoint = tFlightPoint;
            }
        }
        return(tFlightPoints);
    }
Пример #6
0
    public void LaunchBall(float launchAngle, float horizontalAngle, float totalSpeed_MPS, float attackAngle, float clubSpeed, float smashFactor, float side, string clubName,
                           float flightDuration, float maxHeight, float backSpin, float sideSpin, float spinAxis, float totalSpin, bool isNotReplay)
    {
        bool isHandnessLefty = false;
        int  currentGrassType;

        if (launchAngle < 0f)
        {
            launchAngle = 0f;
        }
        if (this.PreBallLaunchDelegate != null)
        {
            this.PreBallLaunchDelegate();
        }
        if (this.m_ballTransform != null)
        {
            float totalSpeedMPS = totalSpeed_MPS * 2.2369f;
            this.m_launchPosition = this.m_ball.transform.position;
            Vector3 mLaunchPosition = this.m_launchPosition;
            Vector3 vector3         = mLaunchPosition;
            this.m_restingPosition = mLaunchPosition;
            this.m_landedPosition  = vector3;
            CBallFlightManager.GetInstance().CalculateCollision((double)totalSpeedMPS, (double)launchAngle, (double)horizontalAngle, (double)backSpin, (double)sideSpin);
            if (CGameManager.instance == null)
            {
                isHandnessLefty = (!LoginManager.IsUserLoggedIn ? false : LoginManager.UserData.IsLefty);
            }
            else
            {
                //isHandnessLefty = CGameManager.instance.UiHolder.GameSettings.IsHandnessLefty;
            }
            bool flag = isHandnessLefty;
            //List<SimulationGreen> simulationGreens = this.GenerateGreensDataFromScene(this.m_launchPosition);
            BallTrajectory ballTrajectory = CBallFlightManager.GetInstance().CalculateFlightTrajectory(this.m_launchPosition, (double)(totalSpeed_MPS * 2.2369f), (double)launchAngle, (double)backSpin, (double)(sideSpin * -1f), (double)horizontalAngle, flag, null);


            BallTrajectory.Point endPoint = ballTrajectory.m_points[ballTrajectory.firstBounceFrame];

            foreach (BallTrajectory.Point point in ballTrajectory.m_points)
            {
                if (point.pos.y > maxHeight)
                {
                    maxHeight = point.pos.y;
                }
            }

            golfballHitData data = new golfballHitData();
            data.endPoint        = endPoint.pos;
            data.time            = endPoint.time;
            data.maxHeight       = maxHeight;
            data.speed           = totalSpeedMPS;
            data.launchAngle     = launchAngle;
            data.horizontalAngle = horizontalAngle;
            data.backSpin        = backSpin;
            data.sideSpin        = sideSpin;
            data.ball            = m_ball;

            GameEntry.GameCore.HitGolfBall(data);
            UnityEngine.Debug.Log(string.Format("最大高度:{0},飞行时间{1},速度{2},发射角度{3},偏转角度{4}", maxHeight, endPoint.time, totalSpeedMPS, launchAngle, horizontalAngle));


            this.SetBallTracerColor();
            TFlightData tFlightDatum = new TFlightData();

            tFlightDatum.ESN             = (string.IsNullOrEmpty(ApplicationDataManager.instance.ESN) ? "NOESN" : string.Copy(ApplicationDataManager.instance.ESN));
            tFlightDatum.esnShotId       = ApplicationDataManager.instance.GenerateLocalEsnID();
            tFlightDatum.timeOfHit       = Time.time.ToString();
            tFlightDatum.dateOfHit       = DateTime.Now;
            tFlightDatum.ballTransform   = this.m_ballTransform;
            tFlightDatum.attackAngle     = attackAngle;
            tFlightDatum.clubSpeed       = (float)CBallFlightManager.GetInstance().SpeedMPH;
            tFlightDatum.descentAngle    = CBallFlightManager.GetInstance().DescentAngle;
            tFlightDatum.smashFactor     = totalSpeedMPS / tFlightDatum.clubSpeed;
            tFlightDatum.backSpin        = backSpin;
            tFlightDatum.totalSpeedMPH   = totalSpeedMPS;
            tFlightDatum.totalSpeedMPS   = totalSpeed_MPS;
            tFlightDatum.launchAngle     = launchAngle;
            tFlightDatum.horizontalAngle = horizontalAngle;

            //数据处理
            tFlightDatum.travelTime = flightDuration;
            tFlightDatum.maxHeight  = maxHeight;

            tFlightDatum.side      = side;
            tFlightDatum.sideSpin  = sideSpin;
            tFlightDatum.isLefty   = flag;
            tFlightDatum.spinAxis  = spinAxis;
            tFlightDatum.totalSpin = totalSpin;

            TFlightData tFlightDatum1 = tFlightDatum;
            if (GrassManager.instance == null)
            {
                currentGrassType = 0;
            }
            else
            {
                currentGrassType = (int)GrassManager.instance.CurrentGrassType;
            }
            tFlightDatum1.courseConditionId = currentGrassType;
            TFlightPoint tFlightPoint = new TFlightPoint()
            {
                location = new Vector3(0f, 0f, 0f),
                time     = 0f
            };
            //tFlightDatum.clubName = CGameManager.instance.GetCurrentClubName();
            //tFlightDatum.clubTypeID = Club.GetClubIDFromName(tFlightDatum.clubName);
            tFlightDatum.clubName   = "ClubName";
            tFlightDatum.clubTypeID = "clubTypeID";

            tFlightDatum.flightColor = this.m_ball.tracerColor;
            if (!isNotReplay)
            {
                CFlightDataStorage.instance.ReplayShotData = tFlightDatum;
            }
            else
            {
                CFlightDataStorage.instance.AddFlight(tFlightDatum);
            }
            this.isStoringTFlightData = isNotReplay;
            this.m_ballNotLaunched    = false;
            if (this.OnBallLaunched != null)
            {
                this.OnBallLaunched();
            }
            this.m_ball.SetTrajectory(ballTrajectory);
            //CGameManager.instance.UiHolder.TracerManager.AddBallWithTracer(this.m_ball);
        }
    }
Пример #7
0
 public TFlightData()
 {
     this.trajectory = new List <TFlightPoint>();
     this.carryPoint = new TFlightPoint();
     this.carry      = 0f;
 }
Пример #8
0
    public static TFlightTrajectory CalculateAverageTrajectory(IList <TFlightData> shotList, int maxPoints = 100)
    {
        List <Vector3> vector3s;
        TFlightPoint   tFlightPoint;
        List <List <TFlightPoint> > lists = new List <List <TFlightPoint> >();

        foreach (TFlightData tFlightDatum in shotList)
        {
            lists.Add(TFlightData.GenerateMissingTrajectory(tFlightDatum));
        }
        List <List <TFlightPoint> > lists1 = new List <List <TFlightPoint> >();
        List <List <TFlightPoint> > lists2 = new List <List <TFlightPoint> >();

        for (int i = 0; i < lists.Count; i++)
        {
            int num = lists[i].IndexOf(shotList[i].carryPoint);
            lists1.Add(lists[i].GetRange(0, num + 2));
            lists2.Add(lists[i].GetRange(num + 2, lists[i].Count - (num + 2)));
        }
        int num1 = lists1.Min <List <TFlightPoint> >((List <TFlightPoint> list) => list.Count);

        if (num1 > maxPoints)
        {
            num1 = maxPoints;
        }
        int num2 = lists2.Min <List <TFlightPoint> >((List <TFlightPoint> list) => list.Count);

        if (num2 > maxPoints)
        {
            num2 = maxPoints;
        }
        List <Vector3> vector3s1 = new List <Vector3>(new Vector3[num1]);
        List <Vector3> vector3s2 = new List <Vector3>(new Vector3[num2]);

        for (int j = 0; j < num1; j++)
        {
            for (int k = 0; k < lists1.Count; k++)
            {
                float          count = (float)lists1[k].Count / (float)num1;
                int            num3  = (int)((float)j * count);
                List <Vector3> item  = vector3s1;
                vector3s = item;
                int num4 = j;
                int num5 = num4;
                item[num4] = vector3s[num5] + lists1[k][num3].location;
            }
        }
        for (int l = 0; l < num2; l++)
        {
            for (int m = 0; m < lists2.Count; m++)
            {
                float          single = (float)lists2[m].Count / (float)num2;
                int            num6   = (int)((float)l * single);
                List <Vector3> item1  = vector3s2;
                vector3s = item1;
                int num7 = l;
                int num8 = num7;
                item1[num7] = vector3s[num8] + lists2[m][num6].location;
            }
        }
        List <TFlightPoint> tFlightPoints = new List <TFlightPoint>();

        for (int n = 0; n < vector3s1.Count; n++)
        {
            tFlightPoint = new TFlightPoint()
            {
                location = vector3s1[n] / (float)shotList.Count
            };
            tFlightPoints.Add(tFlightPoint);
        }
        List <TFlightPoint> tFlightPoints1 = new List <TFlightPoint>();

        for (int o = 0; o < vector3s2.Count; o++)
        {
            tFlightPoint = new TFlightPoint()
            {
                location = vector3s2[o] / (float)shotList.Count
            };
            tFlightPoints1.Add(tFlightPoint);
        }
        return(new TFlightTrajectory(tFlightPoints, tFlightPoints1));
    }