Esempio n. 1
0
    void drop()
    {
        grabbing = false;

        if (grabbedObject != null)
        {
            grabbedObject.GetComponent <Rigidbody>().isKinematic = false;
            grabbedObject.transform.parent = null;

            Vector3 accel    = new Vector3(0, 0, 0);
            Vector3 angAccel = new Vector3(0, 0, 0);

            nodeState.TryGetVelocity(out accel);

            Debug.Log("accel" + accel.ToString());
            Debug.Log("angAccel" + angAccel.ToString());

            nodeState.TryGetAngularVelocity(out angAccel);

            grabbedObject.GetComponent <Rigidbody>().velocity        = accel;
            grabbedObject.GetComponent <Rigidbody>().angularVelocity = angAccel;

            grabbedObject = null;
        }
    }
 void GetValue()
 {
     acceleration.Value        = _nodeState.TryGetAcceleration(out _acceleration) ? _acceleration : Vector3.zero;
     velocity.Value            = _nodeState.TryGetVelocity(out _velocity) ? _velocity : Vector3.zero;
     angularAcceleration.Value = _nodeState.TryGetAngularAcceleration(out _angularAcceleration) ? _angularAcceleration : Vector3.zero;
     angularVelocity.Value     = _nodeState.TryGetAngularVelocity(out _angularVelocity) ? _angularVelocity : Vector3.zero;
 }
Esempio n. 3
0
    void Update()
    {
        if (NodeTitle_Text != null)
        {
            NodeTitle_Text.text = m_Node.ToString();
        }

        var nodeStates = new List <XRNodeState>();

        UnityEngine.XR.InputTracking.GetNodeStates(nodeStates);

        XRNodeState?state = null;

        foreach (XRNodeState nodeState in nodeStates)
        {
            if (nodeState.nodeType == m_Node)
            {
                state = nodeState;
                break;
            }
        }

        if (state.HasValue)
        {
            XRNodeState node = state.Value;
            Vector3     tempVector;
            Quaternion  tempQuaternion;

            // Translation Information
            SetImageColor(Position_Image, node.TryGetPosition(out tempVector));
            Position_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(Velocity_Image, node.TryGetVelocity(out tempVector));
            Velocity_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(Acceleration_Image, node.TryGetAcceleration(out tempVector));
            Acceleration_Text.text = Vector3ToFieldText(tempVector);

            // Rotation Information
            SetImageColor(Rotation_Image, node.TryGetRotation(out tempQuaternion));
            Rotation_Text.text = QuaternionToFieldText(tempQuaternion);
            SetImageColor(AngularVelocity_Image, node.TryGetAngularVelocity(out tempVector));
            AngularVelocity_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(AngularAcceleration_Image, node.TryGetAngularAcceleration(out tempVector));
            AngularAcceleration_Text.text = Vector3ToFieldText(tempVector);
        }
        else
        {
            // Translation Information
            SetImageColor(Position_Image, false);
            SetImageColor(Velocity_Image, false);
            SetImageColor(Acceleration_Image, false);

            // Rotation Information
            SetImageColor(Rotation_Image, false);
            SetImageColor(AngularVelocity_Image, false);
            SetImageColor(AngularAcceleration_Image, false);
        }
    }
Esempio n. 4
0
    public static bool TryGetThrownObjectVelAngVel(XRNodeState throwingControllerState, Vector3 thrownObjectCenterOfMass, out Vector3 objectVelocity, out Vector3 objectAngularVelocity)
    {
        Vector3 controllerPos, controllerVelocity, controllerAngularVelocity;

        if (!throwingControllerState.TryGetPosition(out controllerPos) ||
            !throwingControllerState.TryGetVelocity(out controllerVelocity) ||
            !throwingControllerState.TryGetAngularVelocity(out controllerAngularVelocity))
        {
            objectVelocity = objectAngularVelocity = default(Vector3);
            return(false);
        }

        GetThrownObjectVelAngVel(controllerPos, controllerVelocity, controllerAngularVelocity, thrownObjectCenterOfMass, out objectVelocity, out objectAngularVelocity);
        return(true);
    }
Esempio n. 5
0
        public void Update(XRNodeState nodeState)
        {
            _position            = Vector3.zero;
            _rotation            = new Quaternion();
            _acceleration        = Vector3.zero;
            _angularAcceleration = Vector3.zero;
            _velocity            = Vector3.zero;
            _angularVelocity     = Vector3.zero;

            isTracked = nodeState.tracked;

            if (nodeState.TryGetPosition(out _position))
            {
                position = _position;
            }

            if (nodeState.TryGetRotation(out _rotation))
            {
                rotation = _rotation;
            }

            if (nodeState.TryGetVelocity(out _velocity))
            {
                velocity = _velocity;
            }

            if (nodeState.TryGetAngularVelocity(out _angularVelocity))
            {
                angularVelocity = _angularVelocity;
            }

            if (nodeState.TryGetAcceleration(out _acceleration))
            {
                acceleration = _acceleration;
            }

            if (nodeState.TryGetAngularAcceleration(out _angularAcceleration))
            {
                angularAcceleration = _angularAcceleration;
            }
        }