Example #1
0
 /// Updates the room effects of the environment with given |room| properties.
 /// @note This should only be called from the main Unity thread.
 public static void UpdateAudioRoom(FmodGvrAudioRoom room, bool roomEnabled)
 {
     // Update the enabled rooms list.
     if (roomEnabled)
     {
         if (!enabledRooms.Contains(room))
         {
             enabledRooms.Add(room);
         }
     }
     else
     {
         enabledRooms.Remove(room);
     }
     // Update the current room effects to be applied.
     if (enabledRooms.Count > 0)
     {
         FmodGvrAudioRoom currentRoom    = enabledRooms[enabledRooms.Count - 1];
         RoomProperties   roomProperties = GetRoomProperties(currentRoom);
         // Pass the room properties into a pointer.
         IntPtr roomPropertiesPtr = Marshal.AllocHGlobal(roomPropertiesSize);
         Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
         ListenerPlugin.setParameterData(roomPropertiesIndex, GetBytes(roomPropertiesPtr,
                                                                       roomPropertiesSize));
         Marshal.FreeHGlobal(roomPropertiesPtr);
     }
     else
     {
         // Set the room properties to a null room, which will effectively disable the room effects.
         ListenerPlugin.setParameterData(roomPropertiesIndex, GetBytes(IntPtr.Zero, 0));
     }
 }
Example #2
0
    // Returns room properties of the given |room|.
    private static RoomProperties GetRoomProperties(FmodGvrAudioRoom room)
    {
        RoomProperties roomProperties;
        Vector3        position = room.transform.position;
        Quaternion     rotation = room.transform.rotation;
        Vector3        scale    = Vector3.Scale(room.transform.lossyScale, room.size);

        ConvertAudioTransformFromUnity(ref position, ref rotation);
        roomProperties.positionX        = position.x;
        roomProperties.positionY        = position.y;
        roomProperties.positionZ        = position.z;
        roomProperties.rotationX        = rotation.x;
        roomProperties.rotationY        = rotation.y;
        roomProperties.rotationZ        = rotation.z;
        roomProperties.rotationW        = rotation.w;
        roomProperties.dimensionsX      = scale.x;
        roomProperties.dimensionsY      = scale.y;
        roomProperties.dimensionsZ      = scale.z;
        roomProperties.materialLeft     = room.leftWall;
        roomProperties.materialRight    = room.rightWall;
        roomProperties.materialBottom   = room.floor;
        roomProperties.materialTop      = room.ceiling;
        roomProperties.materialFront    = room.frontWall;
        roomProperties.materialBack     = room.backWall;
        roomProperties.reverbGain       = ConvertAmplitudeFromDb(room.reverbGainDb);
        roomProperties.reverbTime       = room.reverbTime;
        roomProperties.reverbBrightness = room.reverbBrightness;
        roomProperties.reflectionScalar = room.reflectivity;
        return(roomProperties);
    }
Example #3
0
    /// Returns whether the listener is currently inside the given |room| boundaries.
    public static bool IsListenerInsideRoom(FmodGvrAudioRoom room)
    {
        // Compute the room position relative to the listener.
        FMOD.VECTOR unused;
        RuntimeManager.LowlevelSystem.get3DListenerAttributes(0, out listenerPositionFmod, out unused,
                                                              out unused, out unused);
        Vector3 listenerPosition = new Vector3(listenerPositionFmod.x, listenerPositionFmod.y,
                                               listenerPositionFmod.z);
        Vector3    relativePosition = listenerPosition - room.transform.position;
        Quaternion rotationInverse  = Quaternion.Inverse(room.transform.rotation);

        // Set the size of the room as the boundary and return whether the listener is inside.
        bounds.size = Vector3.Scale(room.transform.lossyScale, room.size);
        return(bounds.Contains(rotationInverse * relativePosition));
    }