-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundSound.cs
99 lines (80 loc) · 3.25 KB
/
BackgroundSound.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using StereoKit;
using StereoKit.Framework;
using System;
namespace VRConchRepublic
{
public class BackgroundSound : IStepper
{
Sound wavesSound;
SoundInst wavesSoundInst;
Sound musicSound;
SoundInst musicSoundInst;
Sound blueFireworkSound;
Sound yellowFireworkSound;
Sound pinkFireworkSound;
public bool Enabled => true;
public bool Initialize()
{
wavesSound = Sound.FromFile("Smallwavesbeach.mp3");
musicSound = Sound.FromFile("happy-steeldrum.mp3");
blueFireworkSound = Sound.FromFile("FireWorks.mp3");
yellowFireworkSound = Sound.FromFile("FireWorks2.mp3");
pinkFireworkSound = Sound.FromFile("FireWorks3.mp3");
return true;
}
public void PlayOnceShotFireworks(Vec3 fireworkPosition, float Volume, string fireworkColor)
{
//Trying to find a position that is in the direction of, but a bit closer than the firework.
var soundPosition = Vec3.Lerp(Vec3.Zero, fireworkPosition, 0.055f);
switch (fireworkColor)
{
case "Blue":
blueFireworkSound.Play(soundPosition, Volume);
break;
case "Yellow":
yellowFireworkSound.Play(soundPosition, Volume);
break;
case "Pink":
pinkFireworkSound.Play(soundPosition, Volume);
break;
}
}
public void Step()
{
if (!wavesSoundInst.IsPlaying)
{
wavesSoundInst = wavesSound.Play(Vec3.Zero, 0.75f);
}
if (!musicSoundInst.IsPlaying)
{
musicSoundInst = musicSound.Play(Vec3.Zero, 0.75f);
}
Hierarchy.Push(World.BoundsPose.ToMatrix());
//Move the Ocean Waves sound in a figure8 pattern
//From: https://gamedev.stackexchange.com/questions/43691/how-can-i-move-an-object-in-an-infinity-or-figure-8-trajectory
//scale = 2 / (3 - cos(2 * t));
//x = scale * cos(t);
//y = scale * sin(2 * t) / 2;
float scale = 2 / (3 - (float)Math.Cos(2 * Time.Totalf));
float x = scale * (float)Math.Cos(Time.Totalf);
float z = scale * (float)Math.Sin(2 * Time.Totalf) / 2;
Vec3 atWaveSound = V.XYZ(x, 1.5f, z);
wavesSoundInst.Position = Hierarchy.ToWorld(atWaveSound);
//Helper to see where the sound is being 'drawn'
// Default.MeshSphere.Draw(Default.Material, Matrix.TS(atWaveSound, 0.2f));
//Move the music in a circular pattern
float musicScale = 1.5f;
Vec3 atMusicSound = V.XYZ((float)Math.Sin(Time.Totalf) * musicScale, 3, (float)Math.Cos(Time.Totalf) * musicScale);
musicSoundInst.Position = Hierarchy.ToWorld(atMusicSound);
//Helper to see where the sound is being 'drawn'
// Default.MeshSphere.Draw(Default.Material, Matrix.TS(atMusicSound, 0.2f));
Hierarchy.Pop();
}
public void Shutdown()
{
wavesSoundInst.Stop();
musicSoundInst.Stop();
}
}
}