Esempio n. 1
0
    HitBall addHitBall(GameObject obj)
    {
        HitBall hit = new HitBall(obj);

        m_HitArray.Add(hit);
        return(hit);
    }
Esempio n. 2
0
    //------------------------HitRay interaction operations---------------------------

    // change it into function-seleciton
    void RayHit_Navigation(Hand hand, HitBall m_ControllBall_R, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            if (m_pointer != null)
            {
                m_pointer.SetActive(true);
                m_pointer_comp.EnableTeleport();
            }
            else
            {
                m_pointer = new GameObject("MyPointer");
                m_pointer.transform.SetParent(transform);
                m_pointer.transform.localPosition = Vector3.zero;
                m_pointer.transform.localRotation = Quaternion.identity;
                // initialize the pointer component
                m_pointer_comp = m_pointer.AddComponent <Pointer>();
                UnityEngine.Object obj     = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrows.mat");
                Material           goodmat = obj as Material;
                m_pointer_comp.goodTeleMat = goodmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrowsBad.mat");
                Material badmat = obj as Material;
                m_pointer_comp.badTeleMat = badmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/TeleportHighlight.prefab");
                GameObject telhigh = obj as GameObject;
                m_pointer_comp.teleportHighlight = telhigh;
                m_pointer_comp.pointerType       = Pointer.PointerType.Parabola;
            }
            break;

        case IFuncType.Update:
            m_pointer.transform.position = m_ControllBall_R.transform.position;
            Debug.Log(m_ControllBall_R.transform.position);
            //m_pointer.transform.position = GMS.toVec3(hand.Fingers[1].bones[3].NextJoint);
            m_pointer.transform.rotation = Quaternion.FromToRotation(Vector3.forward, m_ControllBall_R.direc.normalized);
            //m_pointer.transform.rotation = UnityQuaternionExtension.ToQuaternion(hand.Fingers[1].bones[3].Rotation);
            break;

        case IFuncType.Close:
            if (m_pointer != null)
            {
                m_pointer.SetActive(false);
                m_pointer_comp.DisableTeleport();
                // move current camera position
                Vector3 cur_pos = m_camera.transform.position;
                m_camera.transform.position = m_pointer_comp.hit_out.point;
                m_camera.transform.position.Set(m_camera.transform.position.x, cur_pos.y, m_camera.transform.position.z);
            }
            break;

        default:
            break;
        }
    }
Esempio n. 3
0
    void SetUpComponents()
    {
        //club components
        followMouseComponent   = club.GetComponent <FollowMouse>();
        rotateTowardsComponent = club.GetComponent <RotateTowardsBall>();
        swingMeterComponent    = club.GetComponentInChildren <SwingForceMeter>();
        hitBallComponent       = club.GetComponentInChildren <HitBall>();

        //stage components
        navigateStageComponent = stage.GetComponent <NavigateStage>();

        //ball
        ballRB = ball.GetComponent <Rigidbody>();
    }
Esempio n. 4
0
    public void CheckCurrentEvent(IEventType CurrentEventType, IEventType LastEventType, HandPair hands,
                                  HitBall m_ControllBall_L, HitBall m_ControllBall_R)
    {
        switch (CurrentEventType)
        {
        case IEventType.NoAction:
            break;

        case IEventType.Navigation_RayHit:
            if (LastEventType == CurrentEventType)
            {
                CurrentEventType = m_ControllBall_R.radius < 0.15 ?
                                   IEventType.Navigation_RayHit : IEventType.Selection_Single;
            }
            break;

        case IEventType.Selection_Single:
            if (LastEventType == CurrentEventType)
            {
                CurrentEventType = m_ControllBall_R.radius < 0.15 ?
                                   IEventType.Navigation_RayHit : IEventType.Selection_Single;
            }
            break;

        case IEventType.Manipulation_Rotation:
            if (LastEventType == CurrentEventType)
            {
                CurrentEventType = m_ControllBall_L.radius < 0.15 ?
                                   IEventType.Manipulation_Rotation : IEventType.Manipulation_Stroll;
            }
            break;

        case IEventType.Manipulation_Stroll:
            if (LastEventType == CurrentEventType)
            {
                CurrentEventType = m_ControllBall_L.radius < 0.15 ?
                                   IEventType.Manipulation_Rotation : IEventType.Manipulation_Stroll;
            }
            break;

        default:
            break;
        }
    }
Esempio n. 5
0
    //---------------------Manipulation interaction operations------------------------
    void RotateObject(Hand hand, HitBall m_ControllBall_L, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            originDirec = m_ControllBall_L.direc;
            originQ.SetFromToRotation(originDirec, originDirec);
            break;

        case IFuncType.Update:


            // check is too close to center
            if (m_ControllBall_L.radius < 0.05)
            {
                originDirec = m_ControllBall_L.direc;
                originQ.SetFromToRotation(originDirec, originDirec);
                return;
            }

            nextDirec = m_ControllBall_L.direc;
            nextQ.SetFromToRotation(originDirec, nextDirec);

            //Debug.Log(Vector3.Dot(originDirec.normalized, nextDirec.normalized));

            // check if two vector is very similar
            if (Vector3.Dot(originDirec.normalized, nextDirec.normalized) > 0.999)
            {
                return;
            }

            GameObject a = GameObject.Find("CubeTest");
            Quaternion q = Quaternion.Slerp(originQ, nextQ, Time.deltaTime * 10);

            LineRender lr = a.GetComponent <LineRender>();
            if (Mathf.Abs(q.x) > Mathf.Abs(q.y) && Mathf.Abs(q.x) > Mathf.Abs(q.z))
            {
                q.y = 0f; q.z = 0f;
                lr.DrawXCycline();
            }
            else if (Mathf.Abs(q.y) > Mathf.Abs(q.z))
            {
                q.x = 0f; q.z = 0f;
                lr.DrawYCycline();
            }
            else
            {
                q.x = 0f; q.y = 0f;
                lr.DrawZCycline();
            }

            //if (orginRotationAxis != CurrentRotationAxis)
            //{
            //    orginRotationAxis = CurrentRotationAxis;
            //    originDirec = nextDirecl
            //}
            a.transform.rotation = q * a.transform.rotation;

            originDirec = nextDirec;
            originQ     = nextQ;
            break;

        case IFuncType.Close:
            break;

        default:
            break;
        }
    }
Esempio n. 6
0
    //------------------------HitRay interaction operations---------------------------


    void RayHit_Selection(Hand hand, HitBall m_ControllBall_R, IFuncType type_in)
    {
        switch (type_in)
        {
        case IFuncType.Init:
            if (m_pointer != null)
            {
                m_pointer.SetActive(true);
                m_pointer_comp.EnableTeleport();
                // initialize selection
                GameObject m_camera = GameObject.Find("Main Camera");
                m_camera.AddComponent <HighlightingEffect>();
                objSelected  = new List <GameObject>();
                multiMode    = true;
                pre_selected = null;
            }
            else
            {
                m_pointer = new GameObject("MyPointer");
                m_pointer.transform.SetParent(transform);
                m_pointer.transform.localPosition = Vector3.zero;
                m_pointer.transform.localRotation = Quaternion.identity;
                // initialize the pointer component
                m_pointer_comp = m_pointer.AddComponent <Pointer>();
                UnityEngine.Object obj     = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrows.mat");
                Material           goodmat = obj as Material;
                m_pointer_comp.goodTeleMat = goodmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/ArcArrowsBad.mat");
                Material badmat = obj as Material;
                m_pointer_comp.badTeleMat = badmat;
                obj = AssetDatabase.LoadMainAssetAtPath("Assets/GestureInteraction/InteractionViewInstance/HitRay/MyMaterials/TeleportHighlight.prefab");
                GameObject telhigh = obj as GameObject;
                m_pointer_comp.teleportHighlight = telhigh;
                m_pointer_comp.pointerType       = Pointer.PointerType.Line;
            }
            break;

        case IFuncType.Update:
            m_pointer.transform.position = m_ControllBall_R.transform.position;
            //m_pointer.transform.position = GMS.toVec3(hand.Fingers[1].bones[3].NextJoint);
            m_pointer.transform.rotation = Quaternion.FromToRotation(Vector3.forward, m_ControllBall_R.direc);
            //m_pointer.transform.rotation = UnityQuaternionExtension.ToQuaternion(hand.Fingers[1].bones[3].Rotation);
            // selection
            // #1: add or change object(s) selected
            if (m_pointer_comp.hit_out.collider != null)
            {
                GameObject cur_hit_obj = m_pointer_comp.hit_out.collider.gameObject;

                if (cur_hit_obj == pre_selected)
                {
                    return;
                }

                if (cur_hit_obj.GetComponent <SpectrumController>() == null)
                {
                    // if hit object is not selected before
                    if (!multiMode)
                    {
                        removeAllHighlighting();
                        objSelected.Clear();
                    }
                    objSelected.Add(cur_hit_obj);
                    cur_hit_obj.AddComponent <SpectrumController>();
                }
                else
                {
                    // if hit object is selected before, then we cancel the selection on it
                    // ToDo: it should compared with the last obj. Since in continue-selection, one object can be hit constantly.
                    if (objSelected.Count > 1)
                    {
                        if (cur_hit_obj != pre_selected)
                        {
                            removeHighlighting(cur_hit_obj);
                            objSelected.Remove(cur_hit_obj);
                        }
                    }
                }
                pre_selected = cur_hit_obj;
            }
            else
            {
                pre_selected = null;
            }

            break;

        case IFuncType.Close:
            if (m_pointer != null)
            {
                m_pointer.SetActive(false);
                m_pointer_comp.DisableTeleport();
                removeAllHighlighting();
                objSelected.Clear();
                objSelected = null;
                Destroy(Camera.main.GetComponent <HighlightingEffect>());
            }
            break;

        default:
            break;
        }
    }
Esempio n. 7
0
    public void DoCurrentEvent(IEventType CurrentEventType, IEventType LastEventType, HandPair hands,
                               HitBall m_ControllBall_L, HitBall m_ControllBall_R)
    {
        // Check hands are empty to decide fix or hold on all interaction
        //if (!GMS.CheckHandsData(hands, LastHands, m_OpenFixeFrameData)) return;

        switch (CurrentEventType)
        {
        case IEventType.NoAction:
            return;

            break;

        case IEventType.CancelAction:
            if (LastEventType != IEventType.NoAction)
            {
                if (LastEventType == IEventType.Navigation_RayHit)
                {
                    Action_Navigation_HitRay(hands.R, m_ControllBall_R, IFuncType.Close);
                }

                if (LastEventType == IEventType.Selection_Single)
                {
                    Action_Selection_Single(hands.R, m_ControllBall_R, IFuncType.Close);
                }
            }
            break;

        case IEventType.Navigation_RayHit:
            if (LastEventType != CurrentEventType)
            {
                Action_Navigation_HitRay(hands.R, m_ControllBall_R, IFuncType.Init);
            }
            else
            {
                Action_Navigation_HitRay(hands.R, m_ControllBall_R, IFuncType.Update);
            }
            break;

        case IEventType.Selection_Single:
            if (LastEventType != CurrentEventType)
            {
                Action_Selection_Single(hands.R, m_ControllBall_R, IFuncType.Init);
            }
            else
            {
                Action_Selection_Single(hands.R, m_ControllBall_R, IFuncType.Update);
            }
            break;

        case IEventType.Manipulation_Rotation:
            if (LastEventType != CurrentEventType)
            {
                Action_Manipulation_Rotation(hands.L, m_ControllBall_L, IFuncType.Init);
            }
            else
            {
                Action_Manipulation_Rotation(hands.L, m_ControllBall_L, IFuncType.Update);
            }
            break;

        default:
            break;
        }
    }
Esempio n. 8
0
 void Start()
 {
     clubHit = GetComponent <HitBall>();
     GetBallFromScene();
     UpdateRotation();
 }
Esempio n. 9
0
    public void HitGround(GameObject ball)
    {
        Vector3 pos = ball.transform.localPosition;

        Vector3 org      = new Vector3(0, 0, 0);
        float   distance = Vector3.Distance(org, pos);

        BallHit ball_hit = ball.GetComponent <BallHit>();

        //HitRecord record = ball_hit.getRecord();
        int num = m_RecordArray.Count;

        for (int i = 0; i < num; i++)
        {
            HitRecord record = m_RecordArray[i];
            if (ball == record.ball)
            {
                record.distance = distance;
                record.ball     = null;

                int index = (m_RecordArray.Count - 1) - i;
                if (index < NumHitRecord)
                {
                    setHitDistance_(distance, m_objHitRecord[index]);
                }
                break;
            }
        }
        //setFlyDistInfo( distance );
        //setLRDistInfo( pos.x );

        //if( m_nGamePhase != GamePhase_HitGround && ball == m_lastHit.obj ){
        //	setGamePhase( GamePhase_HitGround );
        //}
        //GigaTrax.Debug.Log( "Distance: " + distance.ToString("f2") + " m" );
        int num_hit = m_HitArray.Count;

        for (int i = 0; i < num_hit; i++)
        {
            HitBall hit = m_HitArray[i];
            if (hit.obj == ball)
            {
                hit.ground = true;
                hit.dTime  = HitGroundDuration;
                break;
            }
        }

        int num_info = m_HitInfoArray.Count;

        for (int i = 0; i < num_info; i++)
        {
            HitInfo info = m_HitInfoArray[i];
            if (info.ball == ball)
            {
                info.ball     = null;
                info.ground   = true;
                info.distance = distance;
                updateHitInfo(info);

                Destroy(info.objInfo, HitInfoDuration);

                m_HitInfoArray.RemoveAt(i);
                break;
            }
        }

        GameObject ballEffect = Instantiate(prefabBallEffect);

        ballEffect.transform.localPosition = new Vector3(pos.x, 0.05f, pos.z);
        Destroy(ballEffect, 1.0f);
    }
Esempio n. 10
0
    // Update is called once per frame
    void Update()
    {
        PVAResult status = m_PVACtrl.getCamraStatus();

        if (m_status != status)
        {
            m_status = status;

            if (m_bPhaseLog)
            {
                string text;
                switch (m_status)
                {
                case PVAResult.OK:
                    text = "OK"; break;

                case PVAResult.Uninitialize:
                    text = "Uninitialize"; break;

                case PVAResult.NotConnect:
                    text = "NotConnect"; break;

                case PVAResult.AlreadyRegist:
                    text = "AlreadyRegist"; break;

                case PVAResult.RegistNotFound:
                    text = "RegistNotFound"; break;

                case PVAResult.DongleNotFound:
                    text = "DongleNotFound"; break;

                case PVAResult.NoFPS:
                    text = "NoFPS"; break;

                case PVAResult.NoData:
                    text = "NoData"; break;

                default:
                    text = "Unknown"; break;
                }
                GigaTrax.Debug.Log("CamraStatus:" + text);
            }
        }
        if (m_status != PVAResult.OK)
        {
            return;
        }

        if (!m_bPortInit)
        {
            Port_Open();
            Port_DataSend("Y");             /*Motor ON*/
            Port_DataSend("SU23");          /*Upper Wheel*/
            Port_DataSend("SD23");          /*Lower Wheel*/
            m_bPortInit = true;
        }
        switch (m_nSensorPhase)
        {
        case SensorPhase_Busy: {
            int busy;
            busy = m_PVACtrl.getSysInt("Busy");
            if (busy == 0)
            {
                setSensorPhase(SensorPhase_Ready);
            }
            break;
        }

        case SensorPhase_Start: {
            PVAResult ret = m_PVACtrl.getDetect(ref m_detect);
            if (ret == PVAResult.OK)
            {
                m_PVACtrl.endBall();
                setSensorPhase(SensorPhase_Busy);

                HitRecord record = addHitRecord();
                record.strikePosX = m_detect.strike_pos.x;
                record.strikePosY = m_detect.strike_pos.y;

                m_StrikeZoneSize.x = m_PVACtrl.getSysFloat("StrikeZoneWidth");
                m_StrikeZoneSize.y = m_PVACtrl.getSysFloat("StrikeZoneHeight");

                IntPtr pData;
                if ((m_detect.flags & (int)PVAFlg.Hit) != 0)
                {
                    pData = m_detect.hit_path.data;

                    PVADetectData first = (PVADetectData)Marshal.PtrToStructure(pData, typeof(PVADetectData));
                    pData = new IntPtr(pData.ToInt64() + Marshal.SizeOf(typeof(PVADetectData)));
                    PVADetectData last = (PVADetectData)Marshal.PtrToStructure(pData, typeof(PVADetectData));

                    uint  send_time = last.time - first.time;
                    float t         = (float)1000 / (float)send_time;

                    Vector3 dir = new Vector3();
                    dir.x = last.pos.x - first.pos.x;
                    dir.y = last.pos.y - first.pos.y;
                    dir.z = last.pos.z - first.pos.z;
                    float speed = dir.magnitude * t;
                    dir.Normalize();
                    dir.z = -dir.z;

                    Vector3 pos = new Vector3(first.pos.x, first.pos.y, -first.pos.z);

                    record.result = Result_Hit;
                    record.speed  = speed * MPS2KPH;
                    record.ball   = startHit(pos, dir, speed);
                }
                else
                {
                    float half_width  = m_StrikeZoneSize.x * 0.5f;
                    float half_height = m_StrikeZoneSize.y * 0.5f;
                    if (record.strikePosX >= -half_width && record.strikePosX <= half_width &&
                        record.strikePosY >= -half_height && record.strikePosY <= half_height)
                    {
                        record.result = Result_Strike;
                    }
                    else
                    {
                        record.result = Result_Ball;
                    }
                }
                updateStrikeMark();
                updateHitRecord();
            }
            else
            {
                /*if( Input.GetMouseButtonDown(0) ){
                 *      m_PVACtrl.endBall();
                 *      setSensorPhase(SensorPhase_Busy);
                 *
                 *      startHit2();
                 * }*/
            }
            break;
        }
        }

        switch (m_nGamePhase)
        {
        case GamePhase_Busy:
            m_objCamera.fieldOfView = 54;
            m_objPitcher.setAnim(PitcherAnim.Pitcher_Idle);
            if (m_nSensorPhase == SensorPhase_Ready)
            {
                setGamePhase(GamePhase_Ready);
                m_objReady.SetActive(true);
            }
            break;

        case GamePhase_Ready:
            int nBatterSide = m_PVACtrl.getSysInt("BatterSide");
            //int nBatterSide = 1;
            m_objBatter.setBatterSide(nBatterSide);

            if (RawKeyInput.IsKeyDown(RawKey.M))
            {
                if (RawKeyInput.IsKeyDown(RawKey.RightControl) || RawKeyInput.IsKeyDown(RawKey.LeftControl))
                {
                    setGamePhase(GamePhase_CountDonw);
                    //m_objCamera.fieldOfView = 8;
                    m_objCamera.fieldOfView = 9;
                    m_objReady.SetActive(false);
                    m_objGage.SetActive(true);
                    m_bPush        = false;
                    m_bSensorStart = false;
                    m_bPitchMotion = false;
                }
            }
            break;

        case GamePhase_CountDonw: {
            m_dTime -= Time.deltaTime;

            if (!m_bPitchMotion)
            {
                if (m_dTime < PitchMotionTime)
                {
                    m_objPitcher.setAnim(PitcherAnim.Pitcher_Pitch);
                    m_bPitchMotion = true;
                }
            }
            if (!m_bSensorStart)
            {
                if (m_dTime < SensorStartTime)
                {
                    m_PVACtrl.startBall();
                    setSensorPhase(SensorPhase_Start);
                    m_bSensorStart = true;
                }
            }
            if (!m_bPush)
            {
                if (m_dTime < PushTime)
                {
                    Port_DataSend("G");                     /*Push*/
                    m_bPush = true;
                }
            }

            float ratio = m_dTime / CountDonwDuration;
            UnityEngine.UI.Image image = m_objGage.GetComponent <UnityEngine.UI.Image>();
            if (ratio < 0)
            {
                ratio = 0;
            }
            image.fillAmount = ratio;
            //prefabSpeed.text = "ratio: " + ratio.ToString("f2");

            if (ratio == 0)
            {
                //m_PVACtrl.startBall();
                //setSensorPhase( SensorPhase_Start );
                setGamePhase(GamePhase_Start);
                m_objGage.SetActive(false);
            }

            break;
        }

        case GamePhase_Start:
            m_dTime -= Time.deltaTime;

            if (m_dTime <= 0)
            {
                m_PVACtrl.endBall();
                setSensorPhase(SensorPhase_Busy);
                setGamePhase(GamePhase_Busy);
            }
            break;
        }

        int num_hit = m_HitArray.Count;

        if (num_hit != 0)
        {
            m_topView.clearNewTrail();
            m_sideView.clearNewTrail();

            int i = 0;
            while (i < num_hit)
            {
                bool    remove = false;
                HitBall hit    = m_HitArray[i];
                if (hit.ground)
                {
                    hit.dTime -= Time.deltaTime;
                    if (hit.dTime <= 0)
                    {
                        Destroy(hit.obj, 1.0f);
                        remove = true;

                        if (m_lastHit == hit)
                        {
                            if (m_smoothFollow)
                            {
                                m_smoothFollow.setTarget(null);
                            }
                            m_lastHit = null;

                            //resetView();
                            //setGamePhase( GamePhase_Busy );
                        }
                    }
                }
                else
                {
                    Vector3 pos = hit.obj.transform.localPosition;
                    hit.posArray.Add(pos);
                }
                if (remove)
                {
                    m_topView.addOldTrail(hit.posArray);
                    m_sideView.addOldTrail(hit.posArray);

                    m_HitArray.RemoveAt(i);
                    num_hit--;
                }
                else
                {
                    m_topView.addNewTrail(hit.posArray);
                    m_sideView.addNewTrail(hit.posArray);

                    i++;
                }
            }
            if (num_hit == 0)
            {
                resetView();
                setGamePhase(GamePhase_Busy);
                m_objBatter.setAnim(BatterAnim.BatterAnim_Idle);
            }
        }

        int num_info = m_HitInfoArray.Count;

        for (int i = 0; i < num_info; i++)
        {
            HitInfo info = m_HitInfoArray[i];
            updateHitInfo(info);

            info.dTime += Time.deltaTime;
            GameObject objInfo = info.objInfo;

            float ratio = info.dTime / MainSpeedLife;
            float value = 1.0f + (MainSpeedScale - 1.0f) * ratio;
            objInfo.transform.localScale = new Vector3(value, value, value);

            Vector3 pos = objInfo.transform.localPosition;
            pos.y += 0.1f;
            objInfo.transform.localPosition = pos;
        }

        if (m_smoothFollow)
        {
            if (m_smoothFollow.getTarget())
            {
                m_smoothFollow.update();
            }
        }
    }
Esempio n. 11
0
 void SetUpComponents()
 {
     lineRenderer   = GetComponent <LineRenderer>();
     lineBackground = GetComponentsInChildren <LineRenderer>()[1];
     hitBall        = GetComponentInParent <HitBall>();
 }