Commit cb26e91a authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen

Merge branch 'develop'

parents 0ceb0010 665fb052
using UnityEngine;
using System.Collections;
using VA;
using UnityEngine.UI;
public class LHMAuraMenu : MonoBehaviour {
public Color setcolor;
public Color notsetcolor;
private VAUAuralizationMode auralizationMode;
private string auraMode;
private bool DS;
private bool ER;
private bool DD;
private bool DIR;
private bool AA;
private bool TV;
private bool SC;
private bool DIF;
private bool NF;
private bool DP;
private bool SL;
void Start()
{
auralizationMode = FindObjectOfType<VAUAdapter>().gameObject.GetComponent<VAUAuralizationMode>();
if (auralizationMode == null)
Debug.Log("Global AuralizationMode can't be set: No VAUAuralizationMode on VA-Object.");
auralizationMode.AuraStringChanged += AuralizationMode_AuraStringChanged;
RefreshAuraMode();
}
private void AuralizationMode_AuraStringChanged(string sAuraString)
{
RefreshAuraMode();
}
void RefreshAuraMode()
{
DS = auralizationMode.DirectSound;
ER = auralizationMode.EarlyReflections;
DD = auralizationMode.DiffuseDecay;
DIR = auralizationMode.SourceDirectivity;
AA = auralizationMode.AirAbsorption;
TV = auralizationMode.AtmosphericTemporalVariations;
SC = auralizationMode.Scattering;
DIF = auralizationMode.Diffraction;
NF = auralizationMode.NearFielEffects;
DP = auralizationMode.DopplerShifts;
SL = auralizationMode.SphericalSpreadingLoss;
gameObject.transform.FindChild("DSButton").GetComponent<Image>().color = (DS) ? setcolor : notsetcolor;
gameObject.transform.FindChild("ERButton").GetComponent<Image>().color = (ER) ? setcolor : notsetcolor;
gameObject.transform.FindChild("DDButton").GetComponent<Image>().color = (DD) ? setcolor : notsetcolor;
gameObject.transform.FindChild("DIRButton").GetComponent<Image>().color = (DIR) ? setcolor : notsetcolor;
gameObject.transform.FindChild("AAButton").GetComponent<Image>().color = (AA) ? setcolor : notsetcolor;
gameObject.transform.FindChild("TVButton").GetComponent<Image>().color = (TV) ? setcolor : notsetcolor;
gameObject.transform.FindChild("SCButton").GetComponent<Image>().color = (SC) ? setcolor : notsetcolor;
gameObject.transform.FindChild("DIFButton").GetComponent<Image>().color = (DIF) ? setcolor : notsetcolor;
gameObject.transform.FindChild("NFButton").GetComponent<Image>().color = (NF) ? setcolor : notsetcolor;
gameObject.transform.FindChild("DPButton").GetComponent<Image>().color = (DP) ? setcolor : notsetcolor;
gameObject.transform.FindChild("SLButton").GetComponent<Image>().color = (SL) ? setcolor : notsetcolor;
}
public void AllClicked()
{
auralizationMode.TriggerAuraStringChanged("all");
}
public void DefaultClicked()
{
auralizationMode.TriggerAuraStringChanged("default");
}
public void DSClicked()
{
if (DS)
{
auralizationMode.TriggerAuraStringChanged("-DS");
DS = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+DS");
DS = true;
}
gameObject.transform.Find("DSButton").GetComponent<Image>().color = (DS) ? setcolor : notsetcolor;
}
public void DDClicked()
{
if (DD)
{
auralizationMode.TriggerAuraStringChanged("-DD");
DD = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+DD");
DD = true;
}
gameObject.transform.Find("DDButton").GetComponent<Image>().color = (DD) ? setcolor : notsetcolor;
}
public void DIRClicked()
{
if (DIR)
{
auralizationMode.TriggerAuraStringChanged("-DIR");
DIR = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+DIR");
DIR = true;
}
gameObject.transform.Find("DIRButton").GetComponent<Image>().color = (DIR) ? setcolor : notsetcolor;
}
public void AAClicked()
{
if (AA)
{
auralizationMode.TriggerAuraStringChanged("-AA");
AA = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+AA");
AA = true;
}
gameObject.transform.Find("AAButton").GetComponent<Image>().color = (AA) ? setcolor : notsetcolor;
}
public void TVClicked()
{
if (TV)
{
auralizationMode.TriggerAuraStringChanged("-TV");
TV = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+TV");
TV = true;
}
gameObject.transform.Find("TVButton").GetComponent<Image>().color = (TV) ? setcolor : notsetcolor;
}
public void SCClicked()
{
if (SC)
{
auralizationMode.TriggerAuraStringChanged("-SC");
SC = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+SC");
SC = true;
}
gameObject.transform.Find("SCButton").GetComponent<Image>().color = (SC) ? setcolor : notsetcolor;
}
public void DIFClicked()
{
if (DIF)
{
auralizationMode.TriggerAuraStringChanged("-DIF");
DIF = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+DIF");
DIF = true;
}
gameObject.transform.Find("DIFButton").GetComponent<Image>().color = (DIF) ? setcolor : notsetcolor;
}
public void NFClicked()
{
if (NF)
{
auralizationMode.TriggerAuraStringChanged("-NF");
NF = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+NF");
NF = true;
}
gameObject.transform.Find("NFButton").GetComponent<Image>().color = (NF) ? setcolor : notsetcolor;
}
public void DPClicked()
{
if (DP)
{
auralizationMode.TriggerAuraStringChanged("-DP");
DP = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+DP");
DP = true;
}
gameObject.transform.Find("DPButton").GetComponent<Image>().color = (DP) ? setcolor : notsetcolor;
}
public void SLClicked()
{
if (SL)
{
auralizationMode.TriggerAuraStringChanged("-SL");
SL = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+SL");
SL = true;
}
gameObject.transform.Find("SLButton").GetComponent<Image>().color = (SL) ? setcolor : notsetcolor;
}
public void ERClicked()
{
if (ER)
{
auralizationMode.TriggerAuraStringChanged("-ER");
ER = false;
}
else
{
auralizationMode.TriggerAuraStringChanged("+ER");
ER = true;
}
gameObject.transform.Find("ERButton").GetComponent<Image>().color = (ER) ? setcolor : notsetcolor;
}
}
using UnityEngine;
using System.Collections;
public class LHMTurnAroundMenuController : MonoBehaviour {
public float sensitivity = 100f;
private float distance = -0.03f;
private SteamVR_TrackedController trackedObjeckt;
private SteamVR_Controller.Device device;
private Transform pos;
private Vector3 posoffset;
private Vector2 actPadPos;
private Vector2 lastPadPos;
private float dif;
private bool istouched;
void Start()
{
trackedObjeckt = GetComponentInParent<SteamVR_TrackedController>();
trackedObjeckt.PadTouched += Controller_PadTouched;
trackedObjeckt.PadUntouched += Controller_PadUntouched;
device = SteamVR_Controller.Input((int)trackedObjeckt.controllerIndex);
pos = gameObject.transform.parent.FindChild("Model").transform;
posoffset.Set(0f, distance, 0f);
gameObject.transform.localPosition = posoffset;
}
void LateUpdate()
{
if (istouched)
{
actPadPos = device.GetAxis();
dif = lastPadPos.x - actPadPos.x;
gameObject.transform.RotateAround(pos.position + posoffset, pos.forward, dif * sensitivity);
gameObject.transform.localPosition = posoffset;
lastPadPos = actPadPos;
}
}
private void Controller_PadUntouched(object sender, ClickedEventArgs e)
{
istouched = false;
}
private void Controller_PadTouched(object sender, ClickedEventArgs e)
{
lastPadPos = device.GetAxis();
actPadPos = device.GetAxis();
istouched = true;
}
}
...@@ -22,13 +22,15 @@ namespace VA ...@@ -22,13 +22,15 @@ namespace VA
public bool Connect() public bool Connect()
{ {
bool b = NativeConnectLocalNetClient(_NetClient); bool b = NativeConnectLocalNetClient(_NetClient);
Debug.Assert(b, "Not Connected to VA."); Debug.Assert(b, "Couldn't connect to VA.");
return b; return b;
} }
public bool Connect( string HostIP , int Port ) public bool Connect( string HostIP , int Port )
{ {
return NativeConnectNetClient(_NetClient, HostIP, Port); bool b = NativeConnectNetClient(_NetClient, HostIP, Port);
Debug.Assert(b, "[VAU]Couldn't connect to VA.");
return b;
} }
public bool IsConnected() public bool IsConnected()
...@@ -49,12 +51,9 @@ namespace VA ...@@ -49,12 +51,9 @@ namespace VA
/** /**
* Create a listener (returns ID) * Create a listener (returns ID)
*/ */
public int CreateListener( string Name, int AuraMode, int HRIR ) public int CreateListener( string Name)
{ {
if (!IsConnected()) return NativeCreateListener(_NetClient, Name);
return -1;
return NativeCreateListener(_NetClient, Name, AuraMode, HRIR);
} }
public void SetListenerPosition(int Listener, double x, double y, double z) public void SetListenerPosition(int Listener, double x, double y, double z)
...@@ -99,7 +98,7 @@ namespace VA ...@@ -99,7 +98,7 @@ namespace VA
{ {
int b = NativeLoadHRIRDataset(_NetClient, FilePath, Name); int b = NativeLoadHRIRDataset(_NetClient, FilePath, Name);
Debug.Assert(b != -1); Debug.Assert(b != -1,"[VAU]HRIRDataset konnte nicht geladen werden.");
return b; return b;
} }
...@@ -371,7 +370,7 @@ namespace VA ...@@ -371,7 +370,7 @@ namespace VA
double dUpX, double dUpY, double dUpZ, double dUpX, double dUpY, double dUpZ,
double dVelocityX, double dVelocityY, double dVelocityZ ); double dVelocityX, double dVelocityY, double dVelocityZ );
//[ DllImport( "VANetCSWrapper" ) ] private static extern void NativeGetListenerIDs( IntPtr pClient, std::vector<int>& vListenerIDs ); //[ DllImport( "VANetCSWrapper" ) ] private static extern void NativeGetListenerIDs( IntPtr pClient, std::vector<int>& vListenerIDs );
[ DllImport( "VANetCSWrapper" ) ] private static extern int NativeCreateListener( IntPtr pClient, string sName, int iAuralizationMode, int iHRIRDatasetID ); [ DllImport( "VANetCSWrapper" ) ] private static extern int NativeCreateListener( IntPtr pClient, string sName);
[ DllImport( "VANetCSWrapper" ) ] private static extern int NativeCreateListenerExplicitRenderer( IntPtr pClient, string sName, string sRendererID ); [ DllImport( "VANetCSWrapper" ) ] private static extern int NativeCreateListenerExplicitRenderer( IntPtr pClient, string sName, string sRendererID );
[ DllImport( "VANetCSWrapper" ) ] private static extern void NativeSetActiveListenerExplicitRenderer( IntPtr pClient, int iListenerID, string sRendererID ); [ DllImport( "VANetCSWrapper" ) ] private static extern void NativeSetActiveListenerExplicitRenderer( IntPtr pClient, int iListenerID, string sRendererID );
[ DllImport( "VANetCSWrapper" ) ] private static extern int NativeGetActiveListenerExplicitRenderer( IntPtr pClient, string sRendererID ); [ DllImport( "VANetCSWrapper" ) ] private static extern int NativeGetActiveListenerExplicitRenderer( IntPtr pClient, string sRendererID );
......
...@@ -45,10 +45,10 @@ public class VAUAdapter : MonoBehaviour { ...@@ -45,10 +45,10 @@ public class VAUAdapter : MonoBehaviour {
defaulthrir = _VA.LoadHRIRDataset(DefaultHRIRPath, "DefaultHRIR"); defaulthrir = _VA.LoadHRIRDataset(DefaultHRIRPath, "DefaultHRIR");
defaultdirectivity = _VA.LoadDirectivity(DefaultDirectivityPath, "DefaultDirectivity"); defaultdirectivity = _VA.LoadDirectivity(DefaultDirectivityPath, "DefaultDirectivity");
_VA.SetGlobalAuralizationMode(GlobalAuralizationMode); _VA.SetGlobalAuralizationMode(GlobalAuralizationMode);
Debug.Log("Connect to Server: " + HostIP); Debug.Log("[VAU]Connect to Server: " + HostIP);
} }
else else
Debug.Log("Already connected."); Debug.Log("[VAU]Already connected.");
} }
public static int DefaultHRIR public static int DefaultHRIR
...@@ -93,14 +93,14 @@ public class VAUAdapter : MonoBehaviour { ...@@ -93,14 +93,14 @@ public class VAUAdapter : MonoBehaviour {
VAUSoundSource[] SoundSources = FindObjectsOfType<VAUSoundSource>(); VAUSoundSource[] SoundSources = FindObjectsOfType<VAUSoundSource>();
foreach (VAUSoundSource SoundSource in SoundSources) foreach (VAUSoundSource SoundSource in SoundSources)
{ {
Debug.Log("SoundSouce " + SoundSource.ID + " deleted."); Debug.Log("[VAU]SoundSouce " + SoundSource.ID + " deleted.");
_VA.DeleteSoundSource(SoundSource.ID); _VA.DeleteSoundSource(SoundSource.ID);
} }
VAUListener[] Listeners = FindObjectsOfType<VAUListener>(); VAUListener[] Listeners = FindObjectsOfType<VAUListener>();
foreach (VAUListener Listener in Listeners) foreach (VAUListener Listener in Listeners)
{ {
Debug.Log("Listener " + Listener.ID + " deleted."); Debug.Log("[VAU]Listener " + Listener.ID + " deleted.");
_VA.DeleteListener(Listener.ID); _VA.DeleteListener(Listener.ID);
} }
if (GetComponent<VAUAuralizationMode>() != null) if (GetComponent<VAUAuralizationMode>() != null)
......
...@@ -157,6 +157,32 @@ public class VAUAuralizationMode : MonoBehaviour { ...@@ -157,6 +157,32 @@ public class VAUAuralizationMode : MonoBehaviour {
} }
} }
public void TriggerAuraStringChanged(string externAuraString)
{
if (externAuraString == "+DS") DirectSound = true;
if (externAuraString == "-DS") DirectSound = false;
if (externAuraString == "+ER") EarlyReflections = true;
if (externAuraString == "-ER") EarlyReflections = false;
if (externAuraString == "+DD") DiffuseDecay = true;
if (externAuraString == "-DD") DiffuseDecay = false;
if (externAuraString == "+DIR") SourceDirectivity = true;
if (externAuraString == "-DIR") SourceDirectivity = false;
if (externAuraString == "+AA") AirAbsorption = true;
if (externAuraString == "-AA") AirAbsorption = false;
if (externAuraString == "+TV") AtmosphericTemporalVariations = true;
if (externAuraString == "-TV") AtmosphericTemporalVariations = false;
if (externAuraString == "+SC") Scattering = true;
if (externAuraString == "-SC") Scattering = false;
if (externAuraString == "+DIF") Diffraction = true;
if (externAuraString == "-DIF") Diffraction = false;
if (externAuraString == "+NF") NearFielEffects = true;
if (externAuraString == "-NF") NearFielEffects = false;
if (externAuraString == "+DP") DopplerShifts = true;
if (externAuraString == "-DP") DopplerShifts = false;
if (externAuraString == "+SL") SphericalSpreadingLoss = true;
if (externAuraString == "-SL") SphericalSpreadingLoss = false;
AuraStringChanged(externAuraString);
}
AuralizationMode UpdateAuraModeSettings() AuralizationMode UpdateAuraModeSettings()
{ {
AuralizationMode am = new AuralizationMode(); AuralizationMode am = new AuralizationMode();
......
using UnityEngine; using UnityEngine;
using System; using System.Linq;
using System.Collections; using System.Collections;
using VA; using VA;
...@@ -14,9 +14,12 @@ public class VAUListener : MonoBehaviour { ...@@ -14,9 +14,12 @@ public class VAUListener : MonoBehaviour {
private Quaternion q; private Quaternion q;
private Transform t; private Transform t;
private AudioReverbZone[] reverbZones; private AudioReverbZone[] reverbZones;
private AudioReverbZone[] shadowReverbZones; private float currentArtificialReverberationTime = 0f;
private double currentArtificialReverberationTime = 1; private float shadowReverbTime;
public delegate void ReverbTimeChangedDelegate(double reverbTime);
public event ReverbTimeChangedDelegate ReverbTimeChanged;
public int ID public int ID
{ {
get get
...@@ -29,13 +32,14 @@ public class VAUListener : MonoBehaviour { ...@@ -29,13 +32,14 @@ public class VAUListener : MonoBehaviour {
void Start() void Start()
{ {
_VA = VAUAdapter.VA; _VA = VAUAdapter.VA;
Listener = _VA.CreateListener(listenername, 0, VAUAdapter.DefaultHRIR); Listener = _VA.CreateListener(listenername);
listenername += " " + Listener; listenername += " " + Listener;
_VA.SetListenerAuralizationMode(Listener, "all"); _VA.SetListenerAuralizationMode(Listener, "all");
Debug.Log(listenername + " created"); Debug.Log("[VAU]" + listenername + " created");
_VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR); _VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR);
SetListenerPositionOrientation(); SetListenerPositionOrientation();
_VA.SetArtificalReverbarationTime(VAAudioRenderer, 2); _VA.SetArtificalReverbarationTime(VAAudioRenderer, 2.0f);
reverbZones = FindObjectsOfType(typeof(AudioReverbZone)) as AudioReverbZone[];
} }
void OnEnable() void OnEnable()
...@@ -66,42 +70,42 @@ public class VAUListener : MonoBehaviour { ...@@ -66,42 +70,42 @@ public class VAUListener : MonoBehaviour {
void SetActiveReverbZones() void SetActiveReverbZones()
{ {
double actReverbTime = currentArtificialReverberationTime;
reverbZones = FindObjectsOfType(typeof(AudioReverbZone)) as AudioReverbZone[];
if (reverbZones == shadowReverbZones)
return;
if (reverbZones == null) if (reverbZones == null)
{
if (actReverbTime != currentArtificialReverberationTime)
_VA.SetArtificalReverbarationTime(VAAudioRenderer, actReverbTime);
return; return;
}
shadowReverbZones = reverbZones; float actReverbTime = 0f;
int i = 0; int i = 0;
foreach (AudioReverbZone reverbZone in reverbZones) foreach (AudioReverbZone reverbZone in reverbZones)
{ {
float actdistance = Vector3.Distance(reverbZone.transform.position, gameObject.transform.position); if (i >= maxreverbZones)
if (actdistance < reverbZone.maxDistance) break;
float actDistance = Vector3.Distance(reverbZone.transform.position, gameObject.transform.position);
if ((actDistance < reverbZone.maxDistance))
{ {
if (i <= maxreverbZones) if (actDistance > reverbZone.minDistance)
{ {
actReverbTime += reverbZone.decayTime; actReverbTime += reverbZone.decayTime * (reverbZone.maxDistance - actDistance) / (reverbZone.maxDistance - reverbZone.minDistance);
i++;
} }
if (actdistance > reverbZone.minDistance) else
{ {
actReverbTime += reverbZone.decayTime;
} }
i++;
} }
} }
if (shadowReverbTime == actReverbTime)
return;
if ( i > 0) shadowReverbTime = actReverbTime;
if (i > 0)
actReverbTime /= i; actReverbTime /= i;
if( actReverbTime != currentArtificialReverberationTime) if (ReverbTimeChanged != null)
_VA.SetArtificalReverbarationTime(VAAudioRenderer, actReverbTime); ReverbTimeChanged(actReverbTime);
_VA.SetArtificalReverbarationTime(VAAudioRenderer, actReverbTime);
} }
void OnListenerAuralizationModeChanged(string AuraMode) void OnListenerAuralizationModeChanged(string AuraMode)
......
...@@ -48,6 +48,7 @@ public class VAUSoundSource : MonoBehaviour { ...@@ -48,6 +48,7 @@ public class VAUSoundSource : MonoBehaviour {
directivity = VAUAdapter.DefaultDirectivity; directivity = VAUAdapter.DefaultDirectivity;
else else
directivity = _VA.LoadDirectivity(directivitypath, "SoundSource " + SoundSource + " Directivity"); directivity = _VA.LoadDirectivity(directivitypath, "SoundSource " + SoundSource + " Directivity");
_VA.SetSoundSourceDirectivity(SoundSource, directivity);
if (GetComponent<AudioSource>() != null) if (GetComponent<AudioSource>() != null)
{ {
...@@ -55,15 +56,15 @@ public class VAUSoundSource : MonoBehaviour { ...@@ -55,15 +56,15 @@ public class VAUSoundSource : MonoBehaviour {
{ {
SignalSource = _VA.CreateAudiofileSignalSource(AssetDatabase.GetAssetPath(GetComponent<AudioSource>().clip), this.name + "_signal"); SignalSource = _VA.CreateAudiofileSignalSource(AssetDatabase.GetAssetPath(GetComponent<AudioSource>().clip), this.name + "_signal");
_VA.SetSoundSourceSignalSource(SoundSource, SignalSource); _VA.SetSoundSourceSignalSource(SoundSource, SignalSource);
Debug.Log(SignalSource + " connected to SoundSource " + SoundSource); Debug.Log("[VAU]" + SignalSource + " connected to SoundSource " + SoundSource);
_VA.SetAudiofileSignalSourcePlaybackAction(SignalSource, "PLAYING"); _VA.SetAudiofileSignalSourcePlaybackAction(SignalSource, "PLAYING");
_VA.SetAudiofileSignalSourceIsLooping(SignalSource, islooping); _VA.SetAudiofileSignalSourceIsLooping(SignalSource, islooping);
} }
else else
Debug.Log("No clip on AudioSource of GameObject: " + gameObject.name); Debug.Log("[VAU]No clip on AudioSource of GameObject: " + gameObject.name);
} }
else else
Debug.Log("No AudioSource on GameObject: " + gameObject.name); Debug.Log("[VAU]No AudioSource on GameObject: " + gameObject.name);
if (GetComponent<VAUAuralizationMode>() != null) if (GetComponent<VAUAuralizationMode>() != null)
{ {
GetComponent<VAUAuralizationMode>().AuraStringChanged += OnSoundSourceAuralizationModeChanged; GetComponent<VAUAuralizationMode>().AuraStringChanged += OnSoundSourceAuralizationModeChanged;
......
namespace VRTK
{
using UnityEngine;
using System.Collections;
using VA;
public class VAUVRTKOnTeleportMute : MonoBehaviour {
public float mutetime = 0.2F;
private float mutetimecounter;