public void createSquareWave() { //Instantiate prefab Vector3 spawnPos = this.transform.position + new Vector3(-10f, 0, 20f); GameObject newWave = Instantiate(wavePrefab, spawnPos, Quaternion.identity); allWaves.Add(newWave); newWave.name = "waveHandle_" + allWaves.Count; //Get controller script SineController sineScript = newWave.GetComponent <SineController>(); //Add material and Shader sineScript.mesh.GetComponent <MeshRenderer>().material = new Material(waveShader); /*sineScript.setMaterial();*/ //Add WIM Child /*sineScript.setWIM();*/ //Get AudioController script AudioController audioScript = newWave.GetComponent <AudioController>(); //Add parents //https://en.wikipedia.org/wiki/Square_wave //Using the equation under fourier analysis int noiseReduce = 20; //The greater this number, the more square the wave for (int i = 1; i < noiseReduce; i += 2) { sineScript.addCollidedParent(0.2f * (2 * Mathf.PI * (float)i), 1f / (float)i); //the 0.2f is so the mesh looks right } //Set Object active newWave.SetActive(true); }
public void createSquareWave() { //Get prefab GameObject newWave = createNewWave(); SineController sineScript = newWave.GetComponent <SineController>(); //Add parents //https://en.wikipedia.org/wiki/Square_wave //Using the equation under fourier analysis int noiseReduce = 6; //The greater this number, the more square the wave for (int i = 1; i < noiseReduce; i += 2) { sineScript.addCollidedParent((float)i, 1f / (float)i); //the 0.2f is so the mesh looks right } }
public void createTriWave() { //Get prefab GameObject newWave = createNewWave(); SineController sineScript = newWave.GetComponent <SineController>(); //Add parents //https://en.wikipedia.org/wiki/Triangle_wave //Using first function under harmonics int harmonics = 10; //The greater this number, the more triangle the wave for (int i = 0; i < harmonics - 1; i++) { int mode = (2 * i) + 1; sineScript.addCollidedParent(mode, Mathf.Pow(-1f, i) * Mathf.Pow(mode, -2)); //the 0.3f is so the mesh looks right } }
public void createSawWave() { //Get prefab GameObject newWave = createNewWave(); SineController sineScript = newWave.GetComponent <SineController>(); //Add parents //https://en.wikipedia.org/wiki/Sawtooth_wave //Using the x_sawtooth(t) equation int noiseReduce = 4; //The greater this number, the more sawtooth the wave for (int i = 1; i < noiseReduce; i++) { sineScript.addCollidedParent((float)i, -1f * Mathf.Pow(-1f, i) * (1f / (float)i)); //the 0.3f is so the mesh looks right //the extra -1f is to invert the entire wave } }
public void createTriWave() { //Instantiate prefab Vector3 spawnPos = this.transform.position + new Vector3(-10f, 0, 20f); GameObject newWave = Instantiate(wavePrefab, spawnPos, Quaternion.identity); allWaves.Add(newWave); newWave.name = "waveHandle_" + allWaves.Count; //Get controller script SineController sineScript = newWave.GetComponent <SineController>(); //Add material and Shader sineScript.mesh.GetComponent <MeshRenderer>().material = new Material(waveShader); /*sineScript.setMaterial();*/ //Add WIM Child /*sineScript.setWIM();*/ //Get AudioController script AudioController audioScript = newWave.GetComponent <AudioController>(); //Add parents //https://en.wikipedia.org/wiki/Triangle_wave //Using first function under harmonics int harmonics = 10; //The greater this number, the more triangle the wave for (int i = 0; i < harmonics - 1; i++) { int mode = (2 * i) + 1; sineScript.addCollidedParent(0.3f * (2 * Mathf.PI * mode), Mathf.Pow(-1f, i) * Mathf.Pow(mode, -2)); //the 0.3f is so the mesh looks right } //Set Object active newWave.SetActive(true); }