/// <summary> /// 需要将SineWave.pos 转换成uv /// </summary> public void CaluateUV() { Vector2 WaterMinBoundary = new Vector2(-water.width / 2, -water.length / 2); for (int i = 0; i < waves.Count; ++i) { SineWave wave = waves[i]; wave.pos = new Vector2 ( (waves[i].pos.x - WaterMinBoundary.x) / water.xcellsize * water.uvxcellsize, (waves[i].pos.y - WaterMinBoundary.y) / water.ycellsize * water.uvycellsize ); wave.pos.x = Mathf.Clamp(wave.pos.x, 0, 1); wave.pos.y = Mathf.Clamp(wave.pos.y, 0, 1); waves[i] = wave; } }
public override bool InitAndCheckWaveParams(float speed, float viscosity, float d) { sineWavesMonoBehaviour = water.GetComponent <SineWaveMonoBehaviour>(); if (sineWavesMonoBehaviour == null) { return(false); } sineWavesMonoBehaviour.CaluateUV(); int size = sineWavesMonoBehaviour.waves.Count; waves = new List <Vector4>(size); origins = new List <Vector2>(size); timers = new List <float>(size); cycles = new List <float>(size); for (int i = 0; i < size; ++i) { SineWave wave = sineWavesMonoBehaviour.waves[i]; if (wave.T < 0.1f) { wave.T = 0.1f; } //wave.S = speed; Vector2 direction = wave.D; wave.D = direction.normalized; Vector4 WaveParams = Vector4.zero; float AngularFrequency = 2 * Mathf.PI / wave.L; float PhaseConstant = AngularFrequency * wave.S; WaveParams.x = wave.A * PhaseConstant; WaveParams.y = wave.D.x * AngularFrequency; WaveParams.z = wave.D.y * AngularFrequency; WaveParams.w = PhaseConstant; waves.Add(WaveParams); origins.Add(wave.pos); timers.Add(0); cycles.Add(wave.T); } return(true); }