void Update() { // Update the existing contacts. for (var i = 0; i < _contacts.Length; i++) { // If the contact is alive, try retrieving the latest state. if (_contacts[i].IsValid) { _contacts[i] = TouchInput.GetContact(_contacts[i].ID); } // Update the target spray. UpdateTarget(_targets[i], _contacts[i]); } // Add new entries to the contact array. var newEntries = TouchInput.NewContacts; for (var i1 = 0; i1 < newEntries.Length; i1++) { // Find an unsed contact. for (var i2 = 0; i2 < _contacts.Length; i2++) { if (!_contacts[i2].IsValid) { // Start using this one. _contacts[i2] = newEntries[i1]; UpdateTarget(_targets[i2], _contacts[i2]); break; } } } }
void Update() { // Update the existing contacts. for (var i = 0; i < kMaxContacts; i++) { // If the contact is alive, try retrieving the latest state. if (_contacts[i].IsValid) { _contacts[i] = TouchInput.GetContact(_contacts[i].ID); } UpdateIndicator(_indicators[i], _contacts[i]); SwitchParticle(_indicators[i], _contacts[i].IsValid); } // Add new entries to the contact array. var newEntries = TouchInput.NewContacts; for (var i1 = 0; i1 < newEntries.Length; i1++) { // Find an unsed contact. for (var i2 = 0; i2 < _contacts.Length; i2++) { if (!_contacts[i2].IsValid) { // Start using this one. Don't enable the particle system // at this point to avoid particle emission by jump. _contacts[i2] = newEntries[i1]; UpdateIndicator(_indicators[i2], _contacts[i2]); break; } } } }
void Update() { foreach (var osc in _oscillators) { osc.Contact = TouchInput.GetContact(osc.Contact.ID); } foreach (var newContact in TouchInput.NewContacts) { for (var i = 0; i < _oscillators.Length; i++) { if (!_oscillators[i].Contact.IsValid) { _oscillators[i].Contact = newContact; break; } } } foreach (var osc in _oscillators) { var c = osc.Contact; if (c.IsValid) { osc.Frequency = 55.0f * Mathf.Pow(2, c.X * 4); osc.Amplitude = Mathf.Clamp01(c.Force * 5); osc.Modulation = c.Y; } else { osc.Amplitude = 0; } } }
void Update() { // Update the first contact point. if (_contact1.IsValid) { _contact1 = TouchInput.GetContact(_contact1.ID); } else { _contact1 = TouchInput.GetContactExclude(_contact2.ID); } // Update the second contact point. if (_contact2.IsValid) { _contact2 = TouchInput.GetContact(_contact2.ID); } else { _contact2 = TouchInput.GetContactExclude(_contact1.ID); } // Dual touch mode? var dual = _contact1.IsValid && _contact2.IsValid; // Calculate the centroid of the input points. var input = Vector2.Lerp( new Vector2(_contact1.X, _contact1.Y), new Vector2(_contact2.X, _contact2.Y), dual ? 0.5f : (_contact1.IsValid ? 0 : 1) ); // Calculate the angle of the input points. var angle = dual ? Mathf.Atan2(_contact2.Y - _contact1.Y, _contact2.X - _contact1.X) : 0; // The total sum of the input force. var force = (_contact1.Force + _contact2.Force) * (dual ? 1 : 2); // Apply the input as Euler angles. transform.rotation = Quaternion.Euler(new Vector3( 90 - input.y * 180, input.x * 180 - 90, angle * Mathf.Rad2Deg )); // Apply the input to the renderer properties. _renderer.LineCount = (int)(_originalCount * Mathf.Clamp01(force * 10)); _renderer.Length = _originalLength * (1 + 1 * Mathf.Clamp01(force * 10 - 2)); }
void Update() { if (_contact1.IsValid) { _contact1 = TouchInput.GetContact(_contact1.ID); } else { _contact1 = TouchInput.GetContactExclude(_contact2.ID); } if (_contact2.IsValid) { _contact2 = TouchInput.GetContact(_contact2.ID); } else { _contact2 = TouchInput.GetContactExclude(_contact1.ID); } var input = Vector2.Lerp( new Vector2(_contact1.X, _contact1.Y), new Vector2(_contact2.X, _contact2.Y), _contact2.Force / (_contact1.Force + _contact2.Force + 0.00001f) ); var tan = Mathf.Atan2( _contact2.Y - _contact1.Y, _contact2.X - _contact1.X ); transform.rotation = Quaternion.Euler(new Vector3( 90 - input.y * 180, input.x * 180 - 90, tan * Mathf.Rad2Deg )); var force = _contact1.Force + _contact2.Force; _renderer.Throttle = Mathf.Clamp01(force * 10); _renderer.LengthAmplitude = 1 + 2 * Mathf.Clamp01(force * 10 - 2); }
void Update() { var dt = Time.deltaTime; var dx = 1.0f / _dimensions.y; // Update contact points. for (var i = 0; i < _contacts.Length; i++) { var updated = TouchInput.GetContact(_contacts[i].ID); if (_contacts[i].IsValid && updated.IsValid) { _forceOrigins[i] = MakeForceOrigin(updated); _forceVectors[i] = MakeForceVector(_contacts[i], updated); } else { _forceOrigins[i] = new Vector4(1e+5f, 0, 0, 0); _forceVectors[i] = Vector3.zero; } _contacts[i] = updated; } // Append newly entered contact points. foreach (var newContact in TouchInput.NewContacts) { for (var i = 0; i < _contacts.Length; i++) { if (!_contacts[i].IsValid) { _contacts[i] = newContact; break; } } } // Common variables _compute.SetFloat("Time", Time.time); _compute.SetFloat("DeltaTime", dt); // Advection _compute.SetTexture(Kernels.Advect, "U_in", VFB.V1); _compute.SetTexture(Kernels.Advect, "W_out", VFB.V2); _compute.Dispatch(Kernels.Advect, ThreadCountX, ThreadCountY, 1); // Diffuse setup var dif_alpha = dx * dx / (_viscosity * dt); _compute.SetFloat("Alpha", dif_alpha); _compute.SetFloat("Beta", 4 + dif_alpha); Graphics.CopyTexture(VFB.V2, VFB.V1); _compute.SetTexture(Kernels.Jacobi2, "B2_in", VFB.V1); // Jacobi iteration for (var i = 0; i < 20; i++) { _compute.SetTexture(Kernels.Jacobi2, "X2_in", VFB.V2); _compute.SetTexture(Kernels.Jacobi2, "X2_out", VFB.V3); _compute.Dispatch(Kernels.Jacobi2, ThreadCountX, ThreadCountY, 1); _compute.SetTexture(Kernels.Jacobi2, "X2_in", VFB.V3); _compute.SetTexture(Kernels.Jacobi2, "X2_out", VFB.V2); _compute.Dispatch(Kernels.Jacobi2, ThreadCountX, ThreadCountY, 1); } // Add external force _compute.SetVectorArray("ForceOrigins", _forceOrigins); _compute.SetVectorArray("ForceVectors", _forceVectors); _compute.SetTexture(Kernels.Force, "W_out", VFB.V2); _compute.Dispatch(Kernels.Force, ThreadCountX, ThreadCountY, 1); // Projection setup _compute.SetTexture(Kernels.PSetup, "W_in", VFB.V2); _compute.SetTexture(Kernels.PSetup, "DivW_out", VFB.V3); _compute.SetTexture(Kernels.PSetup, "P_out", VFB.P1); _compute.Dispatch(Kernels.PSetup, ThreadCountX, ThreadCountY, 1); // Jacobi iteration _compute.SetFloat("Alpha", -dx * dx); _compute.SetFloat("Beta", 4); _compute.SetTexture(Kernels.Jacobi1, "B1_in", VFB.V3); for (var i = 0; i < 20; i++) { _compute.SetTexture(Kernels.Jacobi1, "X1_in", VFB.P1); _compute.SetTexture(Kernels.Jacobi1, "X1_out", VFB.P2); _compute.Dispatch(Kernels.Jacobi1, ThreadCountX, ThreadCountY, 1); _compute.SetTexture(Kernels.Jacobi1, "X1_in", VFB.P2); _compute.SetTexture(Kernels.Jacobi1, "X1_out", VFB.P1); _compute.Dispatch(Kernels.Jacobi1, ThreadCountX, ThreadCountY, 1); } // Projection finish _compute.SetTexture(Kernels.PFinish, "W_in", VFB.V2); _compute.SetTexture(Kernels.PFinish, "P_in", VFB.P1); _compute.SetTexture(Kernels.PFinish, "U_out", VFB.V1); _compute.Dispatch(Kernels.PFinish, ThreadCountX, ThreadCountY, 1); // Apply the velocity field to the color buffer. _shaderSheet.SetVectorArray("_ForceOrigins", _forceOrigins); _shaderSheet.SetVectorArray("_ForceVectors", _forceVectors); _shaderSheet.SetTexture("_VelocityField", VFB.V1); Graphics.Blit(_colorRT1, _colorRT2, _shaderSheet, 0); // Swap the color buffers. var temp = _colorRT1; _colorRT1 = _colorRT2; _colorRT2 = temp; }