/* Takes in a slider name, a sample index, and a t. Based on what the slider name is, will use the values to adjust the position, * and indicator. Both start slider and end slider don't use t parameter. */ public void AdjustSlider(string sliderName, int sampleIndex, float t) { if (String.Equals(sliderName, "StartSlider")) { startSliderSampleIndex = sampleIndex; float samplePercent = (float)startSliderSampleIndex / ((float)dummySampleCount - 1.0f); float newX = (samplePercent * localHalfLength * -2) + localHalfLength; startSlider.transform.localPosition = V3E.SetX(localCenter, newX); } else if (String.Equals(sliderName, "CurrentSlider")) { float samplePercent = (float)sampleIndex / ((float)dummySampleCount - 1.0f); float sliderPercent = t * (1.0f / ((float)dummySampleCount - 1.0f)) + samplePercent; float newX = (sliderPercent * localHalfLength * -2) + localHalfLength; currentSlider.transform.localPosition = V3E.SetX(localCenter, newX); } else if (String.Equals(sliderName, "EndSlider")) { endSliderSampleIndex = sampleIndex; float samplePercent = (float)endSliderSampleIndex / ((float)dummySampleCount - 1.0f); float newX = (samplePercent * localHalfLength * -2) + localHalfLength; endSlider.transform.localPosition = V3E.SetX(localCenter, newX); } else if (String.Equals(sliderName, "GhostSlider")) { float samplePercent = (float)sampleIndex / ((float)dummySampleCount - 1.0f); float sliderPercent = t * (1.0f / ((float)dummySampleCount - 1.0f)) + samplePercent; float newX = (sliderPercent * localHalfLength * -2) + localHalfLength; ghostSlider.transform.localPosition = V3E.SetX(localCenter, newX); } }
/* Takes in a finger trigger position and sliders the closest slider in one dimension relative to the finger * slider position (if the new slider position will be on the slider field). If the slider is the start slider * or the end slider then they will snap to the floored or ceiled sample respectively. Else if the slider is * the current slider, it will adjust the position with a smooth transition using t. */ private void SlideClosestSlider(Vector3 fingerTriggerPosition) { Vector3 worldCenter = transform.TransformPoint(localCenter); // Project point into two dimensions on slider field Vector3 v = fingerTriggerPosition - worldCenter; Vector3 d = Vector3.Project(v, transform.up); Vector3 pointInTwoDimensions = fingerTriggerPosition - d; // Project point into one dimension on slider field Vector3 v2 = pointInTwoDimensions - worldCenter; Vector3 d2 = Vector3.Project(v2, transform.forward); Vector3 pointInOneDimension = pointInTwoDimensions - d2; float testDistance = Vector3.Distance(pointInOneDimension, worldCenter); if (testDistance < worldHalfLength) { if (Vector3.Distance(pointInOneDimension, transform.TransformPoint(V3E.SetX(localCenter, -localHalfLength))) < Vector3.Distance(pointInOneDimension, transform.TransformPoint(V3E.SetX(localCenter, localHalfLength)))) { testDistance *= -1; // Closer to left side, so make negative since Vector3.Distance() is only magnitude } float sliderPercent = (testDistance - worldHalfLength) / (worldHalfLength * -2); if (closestSlider == startSlider) { // Find the floored sample index and adjust the start slider int flooredSampleIndex = (int)Mathf.Floor(sliderPercent * (dummySampleCount - 1)); AdjustSlider("StartSlider", flooredSampleIndex, 0.0f); DMS.AdjustStartAids(flooredSampleIndex); } else if (closestSlider == currentSlider) { // Find the floored sample index, find the t, adjust the current slider, then adjust slider indicator and dummy int flooredSampleIndex = (int)Mathf.Floor(sliderPercent * (dummySampleCount - 1)); if (flooredSampleIndex >= startSliderSampleIndex && flooredSampleIndex <= endSliderSampleIndex) { float flooredSamplePercent = (float)flooredSampleIndex / ((float)dummySampleCount - 1.0f); float t = (sliderPercent - flooredSamplePercent) / (1.0f / ((float)dummySampleCount - 1.0f)); AdjustSlider("CurrentSlider", flooredSampleIndex, t); DMS.DS_Adjust(flooredSampleIndex, t); } } else // end slider // Find the ceiled sample index and adjust end slider { int ceiledSampleIndex = (int)Mathf.Ceil(sliderPercent * (dummySampleCount - 1)); AdjustSlider("EndSlider", ceiledSampleIndex, 0.0f); DMS.AdjustEndAids(ceiledSampleIndex); } } }