private float Evaluate(float slip, WheelFrictionCurvePoint[] curvePoints) { int top = m_arraySize - 1; int bottom = 0; int index = (int)((top + bottom) * 0.5f); WheelFrictionCurvePoint result = curvePoints[index]; //Binary search the curve to find the corresponding t value for the given slip while ((top != bottom && top - bottom > 1)) { if (result.SlipForcePoint.x <= slip) { bottom = index; } else if (result.SlipForcePoint.x >= slip) { top = index; } index = (int)((top + bottom) * 0.5f); result = curvePoints[index]; } float slip1 = curvePoints[bottom].SlipForcePoint.x; float slip2 = curvePoints[top].SlipForcePoint.x; float force1 = curvePoints[bottom].SlipForcePoint.y; float force2 = curvePoints[top].SlipForcePoint.y; float slipFraction = (slip - slip1) / (slip2 - slip1); return(force1 * (1 - slipFraction) + force2 * (slipFraction));; }
private float Evaluate(float slip, WheelFrictionCurvePoint[] curvePoints) { int top = m_arraySize - 1; int bottom = 0; int index = (int)((top + bottom) * 0.5f); WheelFrictionCurvePoint result = curvePoints[index]; //Binary search the curve to find the corresponding t value for the given slip while ((top != bottom && top - bottom > 1)) { if (result.SlipForcePoint.x <= slip) { bottom = index; } else if (result.SlipForcePoint.x >= slip) { top = index; } index = (int)((top + bottom) * 0.5f); result = curvePoints[index]; } float slip1 = curvePoints[bottom].SlipForcePoint.x; float slip2 = curvePoints[top].SlipForcePoint.x; float force1 = curvePoints[bottom].SlipForcePoint.y; float force2 = curvePoints[top].SlipForcePoint.y; float slipFraction = (slip - slip1) / (slip2 - slip1); return force1 * (1 - slipFraction) + force2 * (slipFraction); ; }