public static void Quantize()

in Networked Physics/Assets/Scripts/AvatarState.cs [290:419]


    public static void Quantize( ref AvatarState state, out AvatarStateQuantized quantized )
    {
        quantized.client_index = state.client_index;

        quantized.head_position_x = (int) Math.Floor( state.head_position.x * Constants.UnitsPerMeter + 0.5f );
        quantized.head_position_y = (int) Math.Floor( state.head_position.y * Constants.UnitsPerMeter + 0.5f );
        quantized.head_position_z = (int) Math.Floor( state.head_position.z * Constants.UnitsPerMeter + 0.5f );

        Snapshot.QuaternionToSmallestThree( state.head_rotation,
                                            out quantized.head_rotation_largest,
                                            out quantized.head_rotation_a,
                                            out quantized.head_rotation_b,
                                            out quantized.head_rotation_c );

        quantized.left_hand_position_x = (int) Math.Floor( state.left_hand_position.x * Constants.UnitsPerMeter + 0.5f );
        quantized.left_hand_position_y = (int) Math.Floor( state.left_hand_position.y * Constants.UnitsPerMeter + 0.5f );
        quantized.left_hand_position_z = (int) Math.Floor( state.left_hand_position.z * Constants.UnitsPerMeter + 0.5f );

        Snapshot.QuaternionToSmallestThree( state.left_hand_rotation,
                                            out quantized.left_hand_rotation_largest,
                                            out quantized.left_hand_rotation_a,
                                            out quantized.left_hand_rotation_b,
                                            out quantized.left_hand_rotation_c );

        quantized.left_hand_grip_trigger = (int) Math.Floor( state.left_hand_grip_trigger * Constants.TriggerMaximum + 0.5f );
        quantized.left_hand_index_trigger = (int) Math.Floor( state.left_hand_index_trigger * Constants.TriggerMaximum + 0.5f );
        quantized.left_hand_pointing = state.left_hand_pointing;
        quantized.left_hand_thumbs_up = state.left_hand_thumbs_up;

        if ( state.left_hand_holding_cube )
        {
            quantized.left_hand_holding_cube = true;

            quantized.left_hand_cube_id = state.left_hand_cube_id;
            quantized.left_hand_authority_sequence = state.left_hand_authority_sequence;
            quantized.left_hand_ownership_sequence = state.left_hand_ownership_sequence;

            quantized.left_hand_cube_local_position_x = (int) Math.Floor( state.left_hand_cube_local_position.x * Constants.UnitsPerMeter + 0.5f );
            quantized.left_hand_cube_local_position_y = (int) Math.Floor( state.left_hand_cube_local_position.y * Constants.UnitsPerMeter + 0.5f );
            quantized.left_hand_cube_local_position_z = (int) Math.Floor( state.left_hand_cube_local_position.z * Constants.UnitsPerMeter + 0.5f );

            Snapshot.QuaternionToSmallestThree( state.left_hand_cube_local_rotation,
                                                out quantized.left_hand_cube_local_rotation_largest,
                                                out quantized.left_hand_cube_local_rotation_a,
                                                out quantized.left_hand_cube_local_rotation_b,
                                                out quantized.left_hand_cube_local_rotation_c );
        }
        else
        {
            quantized.left_hand_holding_cube = false;
            quantized.left_hand_cube_id = -1;
            quantized.left_hand_authority_sequence = 0;
            quantized.left_hand_ownership_sequence = 0;
            quantized.left_hand_cube_local_position_x = 0;
            quantized.left_hand_cube_local_position_y = 0;
            quantized.left_hand_cube_local_position_z = 0;
            quantized.left_hand_cube_local_rotation_largest = 0;
            quantized.left_hand_cube_local_rotation_a = 0;
            quantized.left_hand_cube_local_rotation_b = 0;
            quantized.left_hand_cube_local_rotation_c = 0;
        }

        quantized.right_hand_position_x = (int) Math.Floor( state.right_hand_position.x * Constants.UnitsPerMeter + 0.5f );
        quantized.right_hand_position_y = (int) Math.Floor( state.right_hand_position.y * Constants.UnitsPerMeter + 0.5f );
        quantized.right_hand_position_z = (int) Math.Floor( state.right_hand_position.z * Constants.UnitsPerMeter + 0.5f );

        Snapshot.QuaternionToSmallestThree( state.right_hand_rotation,
                                            out quantized.right_hand_rotation_largest,
                                            out quantized.right_hand_rotation_a,
                                            out quantized.right_hand_rotation_b,
                                            out quantized.right_hand_rotation_c );

        quantized.right_hand_grip_trigger = (int) Math.Floor( state.right_hand_grip_trigger * Constants.TriggerMaximum + 0.5f );
        quantized.right_hand_index_trigger = (int) Math.Floor( state.right_hand_index_trigger * Constants.TriggerMaximum + 0.5f );
        quantized.right_hand_pointing = state.right_hand_pointing;
        quantized.right_hand_thumbs_up = state.right_hand_thumbs_up;

        if ( state.right_hand_holding_cube )
        {
            quantized.right_hand_holding_cube = true;

            quantized.right_hand_cube_id = state.right_hand_cube_id;
            quantized.right_hand_authority_sequence = state.right_hand_authority_sequence;
            quantized.right_hand_ownership_sequence = state.right_hand_ownership_sequence;

            quantized.right_hand_cube_local_position_x = (int) Math.Floor( state.right_hand_cube_local_position.x * Constants.UnitsPerMeter + 0.5f );
            quantized.right_hand_cube_local_position_y = (int) Math.Floor( state.right_hand_cube_local_position.y * Constants.UnitsPerMeter + 0.5f );
            quantized.right_hand_cube_local_position_z = (int) Math.Floor( state.right_hand_cube_local_position.z * Constants.UnitsPerMeter + 0.5f );

            Snapshot.QuaternionToSmallestThree( state.right_hand_cube_local_rotation,
                                                out quantized.right_hand_cube_local_rotation_largest,
                                                out quantized.right_hand_cube_local_rotation_a,
                                                out quantized.right_hand_cube_local_rotation_b,
                                                out quantized.right_hand_cube_local_rotation_c );
        }
        else
        {
            quantized.right_hand_holding_cube = false;
            quantized.right_hand_cube_id = -1;
            quantized.right_hand_authority_sequence = 0;
            quantized.right_hand_ownership_sequence = 0;
            quantized.right_hand_cube_local_position_x = 0;
            quantized.right_hand_cube_local_position_y = 0;
            quantized.right_hand_cube_local_position_z = 0;
            quantized.right_hand_cube_local_rotation_largest = 0;
            quantized.right_hand_cube_local_rotation_a = 0;
            quantized.right_hand_cube_local_rotation_b = 0;
            quantized.right_hand_cube_local_rotation_c = 0;
        }

        quantized.voice_amplitude = (int) Math.Floor( state.voice_amplitude * Constants.VoiceMaximum + 0.5f );

        // clamp everything

        Snapshot.ClampPosition( ref quantized.head_position_x, ref quantized.head_position_y, ref quantized.head_position_z );

        Snapshot.ClampPosition( ref quantized.left_hand_position_x, ref quantized.left_hand_position_y, ref quantized.left_hand_position_z );

        Snapshot.ClampPosition( ref quantized.right_hand_position_x, ref quantized.right_hand_position_y, ref quantized.right_hand_position_z );

        if ( quantized.left_hand_holding_cube )
        {
            Snapshot.ClampLocalPosition( ref quantized.left_hand_cube_local_position_x, ref quantized.left_hand_cube_local_position_y, ref quantized.left_hand_cube_local_position_z );
        }

        if ( quantized.right_hand_holding_cube )
        {
            Snapshot.ClampLocalPosition( ref quantized.right_hand_cube_local_position_x, ref quantized.right_hand_cube_local_position_y, ref quantized.right_hand_cube_local_position_z );
        }                  
    }