public GameObject createNewWave() { ///* if (!waveParent.active) { throw new System.ArgumentException("Wave's parent tracker must be tracking to create new wave."); } //*/ //Instantiate prefab Vector3 spawnPos = wandPt1.transform.position + offset; GameObject newWave = Instantiate(wavePrefab, spawnPos, Quaternion.identity); newWave.SetActive(true); allWaves.Add(newWave); newWave.name = "waveHandle_" + allWaves.Count; //Get controller script SineController sineScript = newWave.GetComponent <SineController>(); //Set Child names sineScript.setChildNames(allWaves.Count); //Add WIM Child sineScript.setWIM(); //Get AudioController script AudioController audioScript = newWave.GetComponent <AudioController>(); //Set parent newWave.transform.SetParent(waveParent.transform, true); return(newWave); }
public void setWIM() { if (!in3DManipulation) { return; } //Create WIM Mesh //Instantiate(Object original, Transform parent); waveWIM = Instantiate(this.gameObject, WIM.transform); waveWIM.SetActive(true); //Change name waveWIM.name = "WIMwave_" + this.gameObject.name.Split('_')[1]; //Delete Handles and Audio SineController sineScriptWIM = waveWIM.GetComponent <SineController>(); sineScriptWIM.setWIMNames(); lineWIM = sineScriptWIM.mesh.GetComponent <LineRenderer>(); lineWIM.widthMultiplier = lineRenderer.widthMultiplier / 5f; pivotWIM = sineScriptWIM.pivot; Destroy(sineScriptWIM.freqHandle); Destroy(sineScriptWIM.amplHandle); Destroy(waveWIM.GetComponent <AudioController>()); Destroy(waveWIM.GetComponent <AudioSource>()); Destroy(waveWIM.GetComponent <SineController>()); //Update Scripts WIM.GetComponent <ChildWIM>().addWaveChild(waveWIM, this.gameObject); }
public void Awake() { sineScript = this.GetComponent <SineController>(); samplingFrequency = AudioSettings.outputSampleRate; print("Audio Sample Rate: " + samplingFrequency); waves = new Wave[sineScript.maxParents]; waves[0] = new Wave(sineScript.getFrequency(), sineScript.getAmplitude(), 0f, samplingFrequency); waveCount = 1; if (SceneManager.GetActiveScene().name == "Learn2D") { inLearn2D = true; leftScale = 1f; rightScale = 1f; } else { inLearn2D = false; } camera = GameObject.Find("ARCamera"); }
public void createNewWave() { //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>(); /*newWave.GetComponent<ChildWIM>().enabled = false;*/ //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>(); //Set Object active newWave.SetActive(true); /* For testing * //sineScript.changeFrequency(0.5f); * //sineScript.changeAmplitude(-0.5f); * * sineScript.addCollidedParent(1f, 1f); */ }
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); }
// Start is called before the first frame update void Start() { sineScript = waveHandle.GetComponent <SineController>(); lastY = this.transform.localPosition.y; origin = this.transform.localPosition; SetText(); }
private void OnTriggerEnter(Collider other) { print(this.name + " collided: " + other.name); if (other.name.Split('_')[0] == "pivot") { GameObject otherWave = other.gameObject.transform.parent.gameObject; SineController otherScript = otherWave.GetComponent <SineController>(); //Only combine if both are basewaves and other wave not editing position if (isBaseWave() && otherScript.isBaseWave()) { //Move own freq and amplitude to parent's array if (parentCount == 0) { addCollidedParent(meshFreq, meshAmpl); meshFreq = 1f; meshAmpl = 1f; } float[] otherParents = otherScript.getCollidedParents(); //Add other wave's freq and ampl to this one's parents if (otherScript.parentCount == 0) { addCollidedParent(otherScript.meshFreq, otherScript.meshAmpl); } //Add other wave's parents to this one else { float pFreq, pAmpl; for (int i = 0; i < otherScript.parentCount;) { pFreq = otherParents[i++]; pAmpl = otherParents[i++]; addCollidedParent(pFreq, pAmpl); } } //Destroy the other wave and its WIM child string name = otherWave.name; if (in3DManipulation) { WIM.GetComponent <ChildWIM>().CleanUp(otherScript.waveWIM); } Destroy(otherWave); print("deleted: " + name); //Reset handle positions freqHandle.GetComponent <FrequencyController>().ResetPosition(); amplHandle.GetComponent <AmplitudeController>().ResetPosition(); } } }
public void deleteWave(GameObject wave) { SineController sineScript = wave.GetComponent <SineController>(); //Make sure in correct scene, otherwise there's no WIM wave to even delete if (sineScript.in3DManipulation) { wimScript.CleanUp(sineScript.waveWIM); } print("deleted: " + wave.name); Destroy(wave); }
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 createNewWave(Vector3 spawnPos) { //Instantiate prefab 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();*/ //Get AudioController script AudioController audioScript = newWave.GetComponent <AudioController>(); //Set Object active newWave.SetActive(true); }
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); }