public static void GetCubeState(Rigidbody rigidBody, NetworkInfo networkInfo, ref CubeState cubeState, ref Vector3 origin)
    {
        cubeState.active = !rigidBody.IsSleeping();

        cubeState.authorityIndex    = networkInfo.GetAuthorityIndex();
        cubeState.authoritySequence = networkInfo.GetAuthoritySequence();
        cubeState.ownershipSequence = networkInfo.GetOwnershipSequence();

        Vector3 position = rigidBody.position - origin;

        cubeState.position_x = (int)Math.Floor(position.x * Constants.UnitsPerMeter + 0.5f);
        cubeState.position_y = (int)Math.Floor(position.y * Constants.UnitsPerMeter + 0.5f);
        cubeState.position_z = (int)Math.Floor(position.z * Constants.UnitsPerMeter + 0.5f);

        Snapshot.QuaternionToSmallestThree(rigidBody.rotation,
                                           out cubeState.rotation_largest,
                                           out cubeState.rotation_a,
                                           out cubeState.rotation_b,
                                           out cubeState.rotation_c);

        cubeState.linear_velocity_x = (int)Math.Floor(rigidBody.velocity.x * Constants.UnitsPerMeter + 0.5f);
        cubeState.linear_velocity_y = (int)Math.Floor(rigidBody.velocity.y * Constants.UnitsPerMeter + 0.5f);
        cubeState.linear_velocity_z = (int)Math.Floor(rigidBody.velocity.z * Constants.UnitsPerMeter + 0.5f);

        cubeState.angular_velocity_x = (int)Math.Floor(rigidBody.angularVelocity.x * Constants.UnitsPerMeter + 0.5f);
        cubeState.angular_velocity_y = (int)Math.Floor(rigidBody.angularVelocity.y * Constants.UnitsPerMeter + 0.5f);
        cubeState.angular_velocity_z = (int)Math.Floor(rigidBody.angularVelocity.z * Constants.UnitsPerMeter + 0.5f);

        ClampPosition(ref cubeState.position_x, ref cubeState.position_y, ref cubeState.position_z);

        ClampLinearVelocity(ref cubeState.linear_velocity_x, ref cubeState.linear_velocity_y, ref cubeState.linear_velocity_z);

        ClampAngularVelocity(ref cubeState.angular_velocity_x, ref cubeState.angular_velocity_y, ref cubeState.angular_velocity_z);
    }
Пример #2
0
    void DetachFromHand(ref HandData hand)
    {
        // IMPORTANT: This happens when passing a cube from hand-to-hand
        if (hand.gripObject == null)
        {
            return;
        }

        NetworkInfo networkInfo = hand.gripObject.GetComponent <NetworkInfo>();

        networkInfo.DetachCubeFromPlayer();

#if DEBUG_AUTHORITY
        Debug.Log("client " + context.GetClientIndex() + " released cube " + networkInfo.GetCubeId() + ". ownership sequence is " + networkInfo.GetOwnershipSequence() + ", authority sequence is " + networkInfo.GetAuthoritySequence());
#endif // #if DEBUG_AUTHORITY
    }
Пример #3
0
    public static void Initialize(out AvatarState state, int clientIndex, OvrAvatarDriver.PoseFrame frame, GameObject leftHandHeldObject, GameObject rightHandHeldObject)
    {
        state.client_index = clientIndex;

        state.head_position = frame.headPosition;
        state.head_rotation = frame.headRotation;

        state.left_hand_position   = frame.handLeftPosition;
        state.left_hand_rotation   = frame.handLeftRotation;
        state.left_hand_grip_flex  = frame.handLeftPose.gripFlex;
        state.left_hand_index_flex = frame.handLeftPose.indexFlex;
        state.left_hand_pointing   = frame.handLeftPose.isPointing;
        state.left_hand_thumbs_up  = frame.handLeftPose.isThumbUp;

        if (leftHandHeldObject)
        {
            state.left_hand_holding_cube = true;

            NetworkInfo networkInfo = leftHandHeldObject.GetComponent <NetworkInfo>();

            state.left_hand_cube_id             = networkInfo.GetCubeId();
            state.left_hand_authority_sequence  = networkInfo.GetAuthoritySequence();
            state.left_hand_ownership_sequence  = networkInfo.GetOwnershipSequence();
            state.left_hand_cube_local_position = leftHandHeldObject.transform.localPosition;
            state.left_hand_cube_local_rotation = leftHandHeldObject.transform.localRotation;
        }
        else
        {
            state.left_hand_holding_cube        = false;
            state.left_hand_cube_id             = -1;
            state.left_hand_authority_sequence  = 0;
            state.left_hand_ownership_sequence  = 0;
            state.left_hand_cube_local_position = Vector3.zero;
            state.left_hand_cube_local_rotation = Quaternion.identity;
        }

        state.right_hand_position   = frame.handRightPosition;
        state.right_hand_rotation   = frame.handRightRotation;
        state.right_hand_grip_flex  = frame.handRightPose.gripFlex;
        state.right_hand_index_flex = frame.handRightPose.indexFlex;
        state.right_hand_pointing   = frame.handRightPose.isPointing;
        state.right_hand_thumbs_up  = frame.handRightPose.isThumbUp;

        if (rightHandHeldObject)
        {
            state.right_hand_holding_cube = true;

            NetworkInfo networkInfo = rightHandHeldObject.GetComponent <NetworkInfo>();

            state.right_hand_cube_id             = networkInfo.GetCubeId();
            state.right_hand_authority_sequence  = networkInfo.GetAuthoritySequence();
            state.right_hand_ownership_sequence  = networkInfo.GetOwnershipSequence();
            state.right_hand_cube_local_position = rightHandHeldObject.transform.localPosition;
            state.right_hand_cube_local_rotation = rightHandHeldObject.transform.localRotation;
        }
        else
        {
            state.right_hand_holding_cube        = false;
            state.right_hand_cube_id             = -1;
            state.right_hand_authority_sequence  = 0;
            state.right_hand_ownership_sequence  = 0;
            state.right_hand_cube_local_position = Vector3.zero;
            state.right_hand_cube_local_rotation = Quaternion.identity;
        }

        state.voice_amplitude = frame.voiceAmplitude;
    }