/// <summary> /// Retrieves recently computed displacement and restarts computations on a new position. /// </summary> /// <param name="x">World space coordinate.</param> /// <param name="z">World space coordinate.</param> /// <param name="mode">Determines if the computations should be completed on the current thread if necessary. May hurt performance, but setting it to false may cause some 'flickering'.</param> /// <param name="forces">Wave force vector.</param> /// <returns></returns> public Vector3 GetAndReset(float x, float z, ComputationsMode mode, out Vector3 forces) { switch (mode) { case ComputationsMode.ForceCompletion: { if (!finished) { finished = true; ComputationStep(true); } break; } case ComputationsMode.Normal: { if (!finished && !float.IsNaN(previousResult.x)) { forces = previousForces; return(previousResult); } previousResult = this.displaced; previousForces = this.forces; break; } } finished = true; if (!enqueued) { WaterAsynchronousTasks.Instance.AddWaterSampleComputations(this); enqueued = true; water.OnSamplingStarted(); } Vector3 result = this.displaced; result.y += water.transform.position.y; forces = this.forces; this.x = x; this.z = z; this.displaced.x = x; this.displaced.y = 0.0f; this.displaced.z = z; this.forces.x = 0.0f; this.forces.y = 0.0f; this.forces.z = 0.0f; this.time = water.Time; this.finished = false; return(result); }
/// <summary> /// Retrieves recently computed displacement and restarts computations on a new position. /// </summary> /// <param name="x">World space coordinate.</param> /// <param name="z">World space coordinate.</param> /// <param name="mode">Determines if the computations should be completed on the current thread if necessary. May hurt performance, but setting it to false may cause some 'flickering'.</param> /// <returns></returns> public Vector3 GetAndReset(float x, float z, ComputationsMode mode = ComputationsMode.Normal) { Vector3 forces; return(GetAndReset(x, z, mode, out forces)); }
/// <summary> /// Retrieves recently computed displacement and restarts computations on a new position. /// </summary> /// <param name="origin"></param> /// <param name="mode"></param> /// <returns></returns> public Vector3 GetAndReset(Vector3 origin, ComputationsMode mode = ComputationsMode.Normal) { return(GetAndReset(origin.x, origin.z, mode)); }