void Ruler::setUnit(KUnit unit) { m_unit = unit; // approximately 15 points seems to be a good value for the step size switch (m_unit.indexInList(KUnit::ShowAll)) { case KUnit::Millimeter: setStepValue(14.17325288515625502486); // 5.0 mm break; case KUnit::Point: setStepValue(15.0); // 15 pt break; case KUnit::Inch: setStepValue(14.399999999998848); // 0.2 inch break; case KUnit::Centimeter: setStepValue(14.17325288515625502486); // 0.5 cm break; case KUnit::Decimeter: setStepValue(14.17325288515625502486); // 0.05 dm break; case KUnit::Pica: setStepValue(15.00000006000000024); // 1.25 pica break; case KUnit::Cicero: setStepValue(12.84010270181826254741); // 1 cicero break; case KUnit::Pixel: default: setStepValue(15.0); break; } }
TKeyframe<T> TAnimationCurve<T>::evaluateKey(const KeyFrame& lhs, const KeyFrame& rhs, float time) { float length = rhs.time - lhs.time; float t; T leftTangent; T rightTangent; // TODO - Remove zero init for vectors/quaternions by default if (Math::approxEquals(length, 0.0f)) { t = 0.0f; leftTangent = T(); rightTangent = T(); } else { // Resize tangents since we're not evaluating the curve over unit range t = (time - lhs.time) / length; leftTangent = lhs.outTangent * length; rightTangent = rhs.inTangent * length; } TKeyframe<T> output; output.time = time; output.value = Math::cubicHermite(t, lhs.value, rhs.value, leftTangent, rightTangent); output.inTangent = Math::cubicHermiteD1(t, lhs.value, rhs.value, leftTangent, rightTangent); setStepValue(lhs, rhs, output.value); setStepTangent(lhs, rhs, output.inTangent); output.outTangent = output.inTangent; return output; }
T TAnimationCurve<T>::evaluate(float time, bool loop) const { if (mKeyframes.size() == 0) return T(); // Clamp to start or loop if (time < mStart) { if (loop) time = time - std::floor(time / mLength) * mLength; else // Clamping time = mStart; } // Clamp to end or loop if (time > mEnd) { if (loop) time = time - std::floor(time / mLength) * mLength; else // Clamping time = mEnd; } UINT32 leftKeyIdx; UINT32 rightKeyIdx; findKeys(time, leftKeyIdx, rightKeyIdx); // Evaluate curve as hermite cubic spline const KeyFrame& leftKey = mKeyframes[leftKeyIdx]; const KeyFrame& rightKey = mKeyframes[rightKeyIdx]; float length = rightKey.time - leftKey.time; float t; T leftTangent; T rightTangent; // TODO - Remove zero init for vectors/quaternions by default if (Math::approxEquals(length, 0.0f)) { t = 0.0f; leftTangent = T(); rightTangent = T(); } else { // Scale from arbitrary range to [0, 1] t = (time - leftKey.time) / length; leftTangent = leftKey.outTangent * length; rightTangent = rightKey.inTangent * length; } T output = Math::cubicHermite(t, leftKey.value, rightKey.value, leftTangent, rightTangent); setStepValue(leftKey, rightKey, output); return output; }
T TAnimationCurve<T>::evaluate(float time, bool loop) const { if (mKeyframes.size() == 0) return T(); AnimationUtility::wrapTime(time, mStart, mEnd, loop); UINT32 leftKeyIdx; UINT32 rightKeyIdx; findKeys(time, leftKeyIdx, rightKeyIdx); // Evaluate curve as hermite cubic spline const KeyFrame& leftKey = mKeyframes[leftKeyIdx]; const KeyFrame& rightKey = mKeyframes[rightKeyIdx]; float length = rightKey.time - leftKey.time; float t; T leftTangent; T rightTangent; // TODO - Remove zero init for vectors/quaternions by default if (Math::approxEquals(length, 0.0f)) { t = 0.0f; leftTangent = T(); rightTangent = T(); } else { // Scale from arbitrary range to [0, 1] t = (time - leftKey.time) / length; leftTangent = leftKey.outTangent * length; rightTangent = rightKey.inTangent * length; } T output = Math::cubicHermite(t, leftKey.value, rightKey.value, leftTangent, rightTangent); setStepValue(leftKey, rightKey, output); return output; }