Пример #1
0
    public void AddCurve(IM.Number fTime, IM.Number fX_a, IM.Number fX_b, IM.Number fX_c, IM.Number fY_a, IM.Number fY_b, IM.Number fY_c, IM.Number fZ_a, IM.Number fZ_b, IM.Number fZ_c)
    {
        SShootCurve ShootCurve = new SShootCurve();

        ShootCurve.fTime = fTime;
        ShootCurve.fX_a  = fX_a;
        ShootCurve.fX_b  = fX_b;
        ShootCurve.fX_c  = fX_c;
        ShootCurve.fY_a  = fY_a;
        ShootCurve.fY_b  = fY_b;
        ShootCurve.fY_c  = fY_c;
        ShootCurve.fZ_a  = fZ_a;
        ShootCurve.fZ_b  = fZ_b;
        ShootCurve.fZ_c  = fZ_c;

        m_ShootCurveList.Add(ShootCurve);
        m_fTime += fTime;

        IM.Vector3 vFinPos = new IM.Vector3();
        IM.Vector3 vFinVel = new IM.Vector3();

        vFinPos.x = fX_a * fTime * fTime + fX_b * fTime + fX_c;
        vFinPos.y = fY_a * fTime * fTime + fY_b * fTime + fY_c;
        vFinPos.z = fZ_a * fTime * fTime + fZ_b * fTime + fZ_c;

        vFinVel.x = IM.Number.two * fX_a * fTime + fX_b;
        vFinVel.y = IM.Number.two * fY_a * fTime + fY_b;
        vFinVel.z = IM.Number.two * fZ_a * fTime + fZ_b;

        m_vFinPos = vFinPos;
        m_vFinVel = vFinVel;
    }
Пример #2
0
    public bool GetPosition(IM.Number fTimeElapsed, out IM.Vector3 vPos)
    {
        vPos = new IM.Vector3();
        if (m_ShootCurveList.Count == 0)
        {
            return(false);
        }

        if (fTimeElapsed > m_fTime)
        {
            return(false);
        }

        IM.Number fTime     = IM.Number.zero;
        IM.Number fTimePrev = IM.Number.zero;

        //foreach(SShootCurve curve in m_ShootCurveList)
        for (int i = 0; i < m_ShootCurveList.Count; ++i)
        {
            SShootCurve curve = m_ShootCurveList[i];
            fTime += curve.fTime;

            if (fTime >= fTimeElapsed)
            {
                IM.Number fTimeCurve = fTimeElapsed - fTimePrev;

                vPos.x = curve.fX_a * fTimeCurve * fTimeCurve + curve.fX_b * fTimeCurve + curve.fX_c;
                vPos.y = curve.fY_a * fTimeCurve * fTimeCurve + curve.fY_b * fTimeCurve + curve.fY_c;
                vPos.z = curve.fZ_a * fTimeCurve * fTimeCurve + curve.fZ_b * fTimeCurve + curve.fZ_c;

                if (i == 0)     // µÚÒ»ÌõÇúÏßÐèÒªÐÞ¸ÄÆðʼλÖÃ
                {
                    //IM.Number fY = vPos.y;
                    IM.Number fAlpha = fTimeCurve / curve.fTime;
                    vPos += (m_vStartPos - m_vInitPos) * (IM.Number.one - fAlpha);

                    /*
                     * float fTime_Ymax = -curve.fY_b / 2.0f / curve.fY_a;
                     * float fAlpha_Y = fTimeCurve / fTime_Ymax;
                     * if(fAlpha_Y > 1.0f)
                     *  vPos.y = fY;
                     * else
                     *  vPos.y = fY + (m_vStartPos.y - m_vInitPos.y) * (1.0f - fAlpha_Y);
                     */
                }
                return(true);
            }
            fTimePrev = fTime;
        }

        /*
         * if( fTimeElapsed < m_fTime )
         * {
         *      ShootSolution.SShootCurve curve = new ShootSolution.SShootCurve();
         *      ShootSimulation.Instance.CalculateShootCurve(ref curve, m_vFinPos, m_vFinVel);
         *      vPos = curve.GetPosition(fTimeElapsed - fTimePrev);
         *      return true;
         * }
         */

        return(false);
    }
Пример #3
0
    public bool GetEvent(out BallEvent eventId, out Vector3 vecDeltaV, UBasketball ball, UBasket basket, IM.Number fTimeStart, IM.Number fTimeEnd, int iIter)
    {
        eventId   = BallEvent.eNone;
        vecDeltaV = new Vector3();

        if (fTimeStart > m_fTime)
        {
            Debug.LogError("ball shoot solution start time > current time.");
            return(false);
        }

        if (m_bSuccess &&      //&& (iCurveEvent == m_ShootCurveList.Count - 1))
            fTimeEnd > m_fTime)
        {
            eventId = BallEvent.eGoal;
            return(true);
        }

        IM.Number   fTime = IM.Number.zero, fTimePrev = -new IM.Number(0, 001);
        SShootCurve pCurve;

        int iCurve, iCurveStart, iCurveEvent, iCurveEnd;

        iCurve = 0;

        iCurveStart = iCurveEvent = iCurveEnd = m_ShootCurveList.Count;

        foreach (SShootCurve curve in m_ShootCurveList)
        {
            pCurve = curve;
            fTime += pCurve.fTime;

            if (fTime >= fTimeStart && fTimePrev <= fTimeStart)
            {
                iCurveStart = iCurve;
            }

            if (fTime > fTimeEnd && fTimePrev <= fTimeEnd)
            {
                iCurveEnd = iCurve;
                break;
            }

            iCurve++;
            fTimePrev = fTime;
        }

        if (iIter < iCurveEnd - iCurveStart)
        {
            iCurveEvent = iCurveStart + iIter;
            pCurve      = m_ShootCurveList[iCurveEvent];

            IM.Vector3 vecInitVel = new IM.Vector3();
            IM.Vector3 vecFinVel  = new IM.Vector3();
            IM.Vector3 vecPos     = new IM.Vector3();

            vecPos.x = pCurve.fX_a * pCurve.fTime * pCurve.fTime + pCurve.fX_b * pCurve.fTime + pCurve.fX_c;
            vecPos.y = pCurve.fY_a * pCurve.fTime * pCurve.fTime + pCurve.fY_b * pCurve.fTime + pCurve.fY_c;
            vecPos.z = pCurve.fZ_a * pCurve.fTime * pCurve.fTime + pCurve.fZ_b * pCurve.fTime + pCurve.fZ_c;

            vecInitVel.x = IM.Number.two * pCurve.fX_a * pCurve.fTime + pCurve.fX_b;
            vecInitVel.y = IM.Number.two * pCurve.fY_a * pCurve.fTime + pCurve.fY_b;
            vecInitVel.z = IM.Number.two * pCurve.fZ_a * pCurve.fTime + pCurve.fZ_b;

            if (iCurveEvent + 1 >= m_ShootCurveList.Count)
            {
                vecFinVel = m_vFinVel;
            }
            else
            {
                SShootCurve pCurveNext = m_ShootCurveList[iCurveEvent + 1];
                vecFinVel.x = pCurveNext.fX_b;
                vecFinVel.y = pCurveNext.fY_b;
                vecFinVel.z = pCurveNext.fZ_b;
            }

            vecDeltaV = (Vector3)(vecFinVel - vecInitVel);

            if (IM.Math.Abs(vecPos.z - (basket.m_backboard.center.z - ball.m_ballRadius)) < new IM.Number(0, 020))
            {
                eventId = BallEvent.eCollBoard;
            }
            else
            {
                eventId = BallEvent.eCollRim;
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }