Exemple #1
0
    float CalculateGrabDistance()
    {
        ViveGrip_Grabbable grabbable             = grabber.ConnectedGameObject().GetComponent <ViveGrip_Grabbable>();
        Vector3            grabbedAnchorPosition = grabbable.WorldAnchorPosition();

        return(Vector3.Distance(transform.position, grabbedAnchorPosition));
    }
    bool ActiveViveGripObject(GameObject gameObject)
    {
        if (gameObject == null)
        {
            return(false);
        }                                     // Happens with Destroy() sometimes
        ViveGrip_Grabbable    grabbable    = gameObject.GetComponent <ViveGrip_Grabbable>();
        ViveGrip_Interactable interactable = gameObject.GetComponent <ViveGrip_Interactable>();
        bool validGrabbable    = grabbable != null && grabbable.enabled;
        bool validInteractable = interactable != null && interactable.enabled;

        return(validGrabbable || validInteractable);
    }
    Quaternion OrientationChangeFor(GameObject target)
    {
        ViveGrip_Grabbable grabbable = target.GetComponent <ViveGrip_Grabbable>();

        if (grabbable.snapToOrientation)
        {
            // Undo current rotation, apply the orientation, and translate that to controller space
            // ...but in reverse order because thats how Quaternions work
            Quaternion localToController = transform.rotation;
            localToController *= Quaternion.Euler(grabbable.localOrientation);
            return(localToController * Quaternion.Inverse(target.transform.rotation));
        }
        return(Quaternion.identity);
    }
Exemple #4
0
    /// <summary>
    /// 连接关节
    /// </summary>
    /// <param name="jointObject">可配置关节</param>
    /// <param name="desiredObject">关节对象</param>
    /// <param name="offset">偏移</param>
    /// <param name="desiredRotation">想要旋转的角度</param>
    /// <returns>可配置关节</returns>
    public static ConfigurableJoint JointToConnect(GameObject jointObject, Rigidbody desiredObject, Vector3 offset, Quaternion desiredRotation)
    {
        ViveGrip_Grabbable grabbable = desiredObject.gameObject.GetComponent <ViveGrip_Grabbable>();
        ConfigurableJoint  joint     = jointObject.AddComponent <ConfigurableJoint>();

        ViveGrip_JointFactory.SetLinearDrive(joint, desiredObject.mass);
        ViveGrip_JointFactory.ConfigureAnchor(joint, offset, grabbable.applyGripRotation);
        if (grabbable.applyGripRotation)
        {
            ViveGrip_JointFactory.SetAngularDrive(joint, desiredObject.mass);
        }
        joint.targetRotation = desiredRotation;
        joint.connectedBody  = desiredObject;
        return(joint);
    }
Exemple #5
0
    public static ConfigurableJoint JointToConnect(GameObject jointObject, Rigidbody desiredObject, Quaternion controllerRotation)
    {
        ViveGrip_Grabbable grabbable = desiredObject.gameObject.GetComponent <ViveGrip_Grabbable>();
        ConfigurableJoint  joint     = jointObject.AddComponent <ConfigurableJoint>();

        ViveGrip_JointFactory.SetLinearDrive(joint, desiredObject.mass);
        if (grabbable.anchor.enabled)
        {
            ViveGrip_JointFactory.SetAnchor(joint, desiredObject, grabbable.RotatedAnchor());
        }
        if (grabbable.ApplyGripRotation())
        {
            ViveGrip_JointFactory.SetAngularDrive(joint, desiredObject.mass);
        }
        if (grabbable.SnapToOrientation())
        {
            ViveGrip_JointFactory.SetTargetRotation(joint, desiredObject, grabbable.rotation.localOrientation, controllerRotation);
        }
        joint.connectedBody = desiredObject;
        return(joint);
    }