// Updates the animated object from controller input.
    private void UpdateHand(SixenseInput.Controller controller)
    {
        if (Hand == SixenseHands.RIGHT && vrGrabHand != null) {
            vrGrabHand.thumbInput = 0f;
            if (controller.GetButton(SixenseButtons.ONE))
                vrGrabHand.thumbInput = 0.5f;
            if (controller.GetButton(SixenseButtons.THREE))
                vrGrabHand.thumbInput = 1f;

            vrGrabHand.indexInput = controller.GetButton(SixenseButtons.BUMPER) ? 1 : 0;
            vrGrabHand.middleInput = controller.Trigger;
            vrGrabHand.ringInput = controller.Trigger;
            vrGrabHand.littleInput = controller.Trigger;
        }

        if (Hand == SixenseHands.LEFT && vrGrabHand != null) {
            vrGrabHand.thumbInput = 0f;
            if (controller.GetButton(SixenseButtons.TWO))
                vrGrabHand.thumbInput = 0.5f;
            if (controller.GetButton(SixenseButtons.FOUR))
                vrGrabHand.thumbInput = 1f;

            vrGrabHand.indexInput = controller.GetButton(SixenseButtons.BUMPER) ? 1 : 0;
            vrGrabHand.middleInput = controller.Trigger;
            vrGrabHand.ringInput = controller.Trigger;
            vrGrabHand.littleInput = controller.Trigger;
        }
    }
    // Updates the animated object from controller input.
    new protected void UpdateAnimationInput(SixenseInput.Controller controller)
    {
        // Point
        if (controller.GetButton(SixenseButtons.BUMPER))
        {
            m_animator.SetBool("Point", true);
        }
        else
        {
            m_animator.SetBool("Point", false);
        }

        // HoldBook
        if (controller.GetButton(SixenseButtons.START))
        {
            m_animator.SetBool("HoldBook", true);
        }
        else
        {
            m_animator.SetBool("HoldBook", false);
        }

        // Fist
        float fTriggerVal = controller.Trigger;
        fTriggerVal = Mathf.Lerp(m_fLastTriggerVal, fTriggerVal, 0.1f);
        m_fLastTriggerVal = fTriggerVal;

        if (fTriggerVal > 0.01f)
        {
            m_animator.SetBool("Fist", true);
        }
        else
        {
            m_animator.SetBool("Fist", false);
        }

        m_animator.SetFloat("FistAmount", fTriggerVal);

        // Idle
        if (m_animator.GetBool("Fist") == false &&
             m_animator.GetBool("HoldBook") == false &&
             m_animator.GetBool("GripBall") == false &&
             m_animator.GetBool("Point") == false)
        {
            m_animator.SetBool("Idle", true);
        }
        else
        {
            m_animator.SetBool("Idle", false);
        }
    }
    protected override void UpdateObject( SixenseInput.Controller controller )
    {
        if (controller.Enabled)
            UpdateHand(controller);

        if (!m_enabled && controller.Trigger > 0.01f) {
            m_enabled = true;

            // delta controller position is relative to this point
            m_baseControllerPosition = new Vector3( controller.Position.x * Sensitivity.x,
                                                   controller.Position.y * Sensitivity.y,
                                                   controller.Position.z * Sensitivity.z );

            // this is the new start position
            m_initialPosition = this.gameObject.transform.localPosition;
        }
        if (m_enabled && controller.GetButton(SixenseButtons.START)) {
            m_enabled = false;
        }

        if ( m_enabled ) {
            UpdatePosition( controller );
            UpdateRotation( controller );
        }
    }
	// Updates the animated object from controller input.
	protected void UpdateAnimationInput( SixenseInput.Controller controller)
	{
		// Point
		if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.ONE) : controller.GetButton(SixenseButtons.TWO) )
		{
			m_animator.SetBool( "Point", true );
		}
		else
		{
			m_animator.SetBool( "Point", false );
		}
		
		// Grip Ball
		if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.TWO) : controller.GetButton(SixenseButtons.ONE)  )
		{
			m_animator.SetBool( "GripBall", true );
		}
		else
		{
			m_animator.SetBool( "GripBall", false );
		}
				
		// Hold Book
		if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.THREE) : controller.GetButton(SixenseButtons.FOUR) )
		{
			m_animator.SetBool( "HoldBook", true );
		}
		else
		{
			m_animator.SetBool( "HoldBook", false );
		}
				
		// Fist
		float fTriggerVal = controller.Trigger;
		fTriggerVal = Mathf.Lerp( m_fLastTriggerVal, fTriggerVal, 0.1f );
		m_fLastTriggerVal = fTriggerVal;
		
		if ( fTriggerVal > 0.01f )
		{
			m_animator.SetBool( "Fist", true );
		}
		else
		{
			m_animator.SetBool( "Fist", false );
		}
		
		m_animator.SetFloat("FistAmount", fTriggerVal);
		
		// Idle
		if ( m_animator.GetBool("Fist") == false &&  
			 m_animator.GetBool("HoldBook") == false && 
			 m_animator.GetBool("GripBall") == false && 
			 m_animator.GetBool("Point") == false )
		{
			m_animator.SetBool("Idle", true);
		}
		else
		{
			m_animator.SetBool("Idle", false);
		}
	}
Exemplo n.º 5
0
    // Updates the animated object from controller input.
    protected void UpdateAnimationInput( SixenseInput.Controller controller)
    {
        // Tools can only be used by the right hand
        if (Hand == SixenseHands.RIGHT)
        {
            if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.ONE) : controller.GetButton(SixenseButtons.TWO) )
            {
                if(!m_toolPressed) {
                    NextTool();
                    Debug.Log ("What");
                }

                m_toolPressed = true;
                m_animator.SetBool( "Point", true );
            }
            else
            {
                m_toolPressed = false;
                m_animator.SetBool( "Point", false );
            }
        }
        else
        {
            // Grip Ball
            if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.TWO) : controller.GetButton(SixenseButtons.ONE)  )
            {
                m_animator.SetBool( "GripBall", true );
            }
            else
            {
                m_animator.SetBool( "GripBall", false );
            }

            // Hold Book
            if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.THREE) : controller.GetButton(SixenseButtons.FOUR) )
            {
                m_animator.SetBool( "HoldBook", true );
            }
            else
            {
                m_animator.SetBool( "HoldBook", false );
            }
        }

        // Fist
        float fTriggerVal = controller.Trigger;
        if (fTriggerVal > 0.01f) {
            if (Hand == SixenseHands.RIGHT)
            {
                if(m_tool && !m_isActivating) {
                    m_tool.Activate();
                    m_isActivating = true;
                }
            }
            else
            {
                m_pickupZone.Grab();
            }
        }
        else
        {
            if (Hand == SixenseHands.RIGHT)
            {
                m_isActivating = false;
            }
            else
            {
                m_pickupZone.Drop();
            }
        }

        fTriggerVal = Mathf.Lerp( m_fLastTriggerVal, fTriggerVal, 0.1f );
        m_fLastTriggerVal = fTriggerVal;

        if ( fTriggerVal > 0.01f )
        {
            m_animator.SetBool( "Fist", true );
        }
        else
        {
            m_animator.SetBool( "Fist", false );
        }

        m_animator.SetFloat("FistAmount", fTriggerVal);

        // Idle
        if ( m_animator.GetBool("Fist") == false &&
             m_animator.GetBool("HoldBook") == false &&
             m_animator.GetBool("GripBall") == false &&
             m_animator.GetBool("Point") == false )
        {
            m_animator.SetBool("Idle", true);
        }
        else
        {
            m_animator.SetBool("Idle", false);
        }
    }
    /*void OnGUI()
    {
        if ( !m_enabled )
        {
            GUI.Box( new Rect( Screen.width / 2 - 100, Screen.height - 40, 200, 30 ),  "Press Start To Move/Rotate" );
        }
    }*/
    protected virtual void UpdateObject(  SixenseInput.Controller controller )
    {
        if ( Input.GetKeyDown (KeyCode.E) || Input.GetKeyDown (KeyCode.F) || Input.GetKeyDown (KeyCode.T)/*controller.GetButtonDown( SixenseButtons.START )*/ )
        {
            // enable position and orientation control
            m_enabled = !m_enabled;

            // delta controller position is relative to this point
            m_baseControllerPosition = new Vector3( -controller.Position.z * Sensitivity.x,
                                                   controller.Position.y * Sensitivity.y,
                                                   controller.Position.x * Sensitivity.z );

            // this is the new start position
            m_initialPosition = this.gameObject.transform.localPosition;

            gameObject.GetComponentInChildren<MeshRenderer>().enabled = m_enabled;
        }

        /*if (m_enabled && controller.GetButtonDown (SixenseButtons.JOYSTICK))
        {
            this.gameObject.transform.Translate(0.0f,controller.JoystickY,controller.JoystickX);
        }*/
        if ( m_enabled )
        {
            //Déplacement du gameObject au joystick
            m_initialPosition += new Vector3(0.0f,controller.JoystickY*0.01f,controller.JoystickX*0.01f);
            Debug.Log(new Vector3(0.0f,controller.JoystickY,controller.JoystickX));

            //Déplacement en profondeur du gameObject via RB RT
            if(controller.GetButton( SixenseButtons.BUMPER )){
               m_initialPosition += new Vector3(0.005f,0.0f,0.0f);
            }else if (controller.GetButton( SixenseButtons.TRIGGER )){
                m_initialPosition -= new Vector3(0.005f,0.0f,0.0f);
            }

            // Rotation suivant l'axe Y via les boutons 1 & 3
            if(controller.GetButton( SixenseButtons.ONE )){
                m_initialRotation.y += 0.005f;
            }else if (controller.GetButton( SixenseButtons.THREE )){
                m_initialRotation.y -= 0.005f;
            }

            // Rotation suivant l'axe Z via les boutons 2 & 4
            /*if(controller.GetButton( SixenseButtons.TWO )){
                m_initialRotation.z += 0.005f;
            }else if (controller.GetButton( SixenseButtons.FOUR )){
                m_initialRotation.z -= 0.005f;
            }*/

            // Modifie la sensibilité via les boutons 2 & 4
            if(controller.GetButton( SixenseButtons.TWO )){
                Sensitivity += new Vector3(0.00001f,0.00001f,0.00001f);
                    /*m_baseControllerPosition = new Vector3( -controller.Position.z * Sensitivity.x,
                                                      	 controller.Position.y * Sensitivity.y,
                                                      	 controller.Position.x * Sensitivity.z );*/
            }else if (controller.GetButton( SixenseButtons.FOUR )){
                if(Sensitivity.x > 0.0f){
                    Sensitivity -= new Vector3(0.00001f,0.00001f,0.00001f);
                    /*m_baseControllerPosition = new Vector3( -controller.Position.z * Sensitivity.x,
                                                       	controller.Position.y * Sensitivity.y,
                                                       	controller.Position.x * Sensitivity.z );*/
                }
            }

            UpdatePosition( controller );

            if (ActivateRotations){
                UpdateRotation( controller );
            }
        }
    }