| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- #ifndef CURVE_H_
- #define CURVE_H_
- namespace gameplay
- {
- /**
- * Represents an n-dimensional curve.
- */
- class Curve
- {
- friend class Animation;
- friend class AnimationClip;
- friend class AnimationController;
- friend class MeshSkin;
- public:
- /**
- * Types of interpolation.
- *
- * Defines how the points in the curve are connected.
- *
- * Note: InterpolationType::BEZIER requires control points and InterpolationType::HERMITE requires tangents.
- */
- enum InterpolationType
- {
- /**
- * Bezier Interpolation.
- *
- * Requires that two control points are set for each segment.
- */
- BEZIER,
- /**
- * B-Spline Interpolation.
- *
- * Uses the points as control points, and the curve is guaranteed to only pass through the
- * first and last point.
- */
- BSPLINE,
- /**
- * Flat Interpolation.
- *
- * A form of Hermite interpolation that generates flat tangents for you. The tangents have a value equal to 0.
- */
- FLAT,
- /**
- * Hermite Interpolation.
- *
- * Requires that two tangents for each segment.
- */
- HERMITE,
- /**
- * Linear Interpolation.
- */
- LINEAR,
- /**
- * Smooth Interpolation.
- *
- * A form of Hermite interpolation that generates tangents for each segment based on the points prior to and after the segment.
- */
- SMOOTH,
- /**
- * Discrete Interpolation.
- */
- STEP,
- /**
- * Quadratic-In Interpolation.
- */
- QUADRATIC_IN,
-
- /**
- * Quadratic-Out Interpolation.
- */
- QUADRATIC_OUT,
- /**
- * Quadratic-In-Out Interpolation.
- */
- QUADRATIC_IN_OUT,
- /**
- * Quadratic-Out-In Interpolation.
- */
- QUADRATIC_OUT_IN,
- /**
- * Cubic-In Interpolation.
- */
- CUBIC_IN,
-
- /**
- * Cubic-Out Interpolation.
- */
- CUBIC_OUT,
-
- /**
- * Cubic-In-Out Interpolation.
- */
- CUBIC_IN_OUT,
-
- /**
- * Cubic-Out-In Interpolation.
- */
- CUBIC_OUT_IN,
- /**
- * Quartic-In Interpolation.
- */
- QUARTIC_IN,
- /**
- * Quartic-Out Interpolation.
- */
- QUARTIC_OUT,
- /**
- * Quartic-In-Out Interpolation.
- */
- QUARTIC_IN_OUT,
- /**
- * Quartic-Out-In Interpolation.
- */
- QUARTIC_OUT_IN,
- /**
- * Quintic-In Interpolation.
- */
- QUINTIC_IN,
-
- /**
- * Quintic-Out Interpolation.
- */
- QUINTIC_OUT,
-
- /**
- * Quintic-In-Out Interpolation.
- */
- QUINTIC_IN_OUT,
-
- /**
- * Quintic-Out-In Interpolation.
- */
- QUINTIC_OUT_IN,
-
- /**
- * Sine-In Interpolation.
- */
- SINE_IN,
-
- /**
- * Sine-Out Interpolation.
- */
- SINE_OUT,
-
- /**
- * Sine-In-Out Interpolation.
- */
- SINE_IN_OUT,
-
- /**
- * Sine-Out-In Interpolation.
- */
- SINE_OUT_IN,
- /**
- * Exponential-In Interpolation.
- */
- EXPONENTIAL_IN,
- /**
- * Exponential-Out Interpolation.
- */
- EXPONENTIAL_OUT,
- /**
- * Exponential-In-Out Interpolation.
- */
- EXPONENTIAL_IN_OUT,
- /**
- * Exponential-Out-In Interpolation.
- */
- EXPONENTIAL_OUT_IN,
- /**
- * Circular-In Interpolation.
- */
- CIRCULAR_IN,
- /**
- * Circular-Out Interpolation.
- */
- CIRCULAR_OUT,
- /**
- * Circular-In-Out Interpolation.
- */
- CIRCULAR_IN_OUT,
- /**
- * Circular-Out-In Interpolation.
- */
- CIRCULAR_OUT_IN,
- /**
- * Elastic-In Interpolation.
- */
- ELASTIC_IN,
- /**
- * Elastic-Out Interpolation.
- */
- ELASTIC_OUT,
- /**
- * Elastic-In-Out Interpolation.
- */
- ELASTIC_IN_OUT,
- /**
- * Elastic-Out-In Interpolation.
- */
- ELASTIC_OUT_IN,
- /**
- * Overshoot-In Interpolation.
- */
- OVERSHOOT_IN,
- /**
- * Overshoot-Out Interpolation.
- */
- OVERSHOOT_OUT,
- /**
- * Overshoot-In-Out Interpolation.
- */
- OVERSHOOT_IN_OUT,
- /**
- * Overshoot-Out-In Interpolation.
- */
- OVERSHOOT_OUT_IN,
- /**
- * Bounce-In Interpolation.
- */
- BOUNCE_IN,
- /**
- * Bounce-Out Interpolation.
- */
- BOUNCE_OUT,
- /**
- * Bounce-In-Out Interpolation.
- */
- BOUNCE_IN_OUT,
- /**
- * Bounce-Out-In Interpolation.
- */
- BOUNCE_OUT_IN
- };
- /**
- * Constructs a new curve and the specified parameters.
- *
- * @param pointCount The number of points in the curve.
- * @param componentCount The number of float component values per key value.
- */
- Curve(unsigned int pointCount, unsigned int componentCount);
- /**
- * Destructor.
- */
- ~Curve();
- /**
- * Gets the number of points in the curve.
- *
- * @return The number of points in the curve.
- */
- unsigned int getPointCount() const;
- /**
- * Gets the number of float component values per points.
- *
- * @return The number of float component values per point.
- */
- unsigned int getComponentCount() const;
- /**
- * Returns the start time for the curve.
- *
- * @return The curve's start time.
- */
- float getStartTime() const;
- /**
- * Returns the end time for the curve.
- *
- * @return The curve's end time.
- */
- float getEndTime() const;
- /**
- * Sets the given point values on the curve the curve.
- *
- * @param index The index of the point.
- * @param time The time for the key.
- * @param value The point to add.
- * @param type The curve interpolation type.
- */
- void setPoint(unsigned int index, float time, float* value, InterpolationType type);
- /**
- * Sets the given point on the curve for the specified index and the specified parameters.
- *
- * @param index The index of the point.
- * @param time The time of the point within the curve.
- * @param value The value of the point to copy the data from.
- * @param type The curve interpolation type.
- * @param inValue The tangent approaching the point.
- * @param outValue The tangent leaving the point.
- */
- void setPoint(unsigned int index, float time, float* value, InterpolationType type, float* inValue, float* outValue);
- /**
- * Sets the tangents for a point on the curve specified by the index.
- *
- * @param index The index of the point.
- * @param type The curve interpolation type.
- * @param inValue The tangent approaching the point.
- * @param outValue The tangent leaving the point.
- */
- void setTangent(unsigned int index, InterpolationType type, float* inValue, float* outValue);
-
- /**
- * Evaluates the curve at the given position value (between 0.0 and 1.0 inclusive).
- *
- * @param time The position to evaluate the curve at.
- * @param dst The evaluated value of the curve at the given time.
- */
- void evaluate(float time, float* dst) const;
- /**
- * Linear interpolation function.
- */
- static float lerp(float t, float from, float to);
- private:
- /**
- * Defines a single point within a curve.
- */
- class Point
- {
- public:
- /** The time of the point within the curve. */
- float time;
- /** The value of the point. */
- float* value;
- /** The value of the tangent when approaching this point (from the previous point in the curve). */
- float* inValue;
- /** The value of the tangent when leaving this point (towards the next point in the curve). */
- float* outValue;
- /** The type of interpolation to use between this point and the next point. */
- InterpolationType type;
- /**
- * Constructor.
- */
- Point();
- /**
- * Destructor.
- */
- ~Point();
- };
- /**
- * Constructor.
- */
- Curve();
- /**
- * Constructor.
- */
- Curve(const Curve& copy);
- /**
- * Bezier interpolation function.
- */
- void interpolateBezier(float s, Point* from, Point* to, float* dst) const;
- /**
- * Bspline interpolation function.
- */
- void interpolateBSpline(float s, Point* c0, Point* c1, Point* c2, Point* c3, float* dst) const;
- /**
- * Hermite interpolation function.
- */
- void interpolateHermite(float s, Point* from, Point* to, float* dst) const;
- /**
- * Hermite interpolation function.
- */
- void interpolateHermiteFlat(float s, Point* from, Point* to, float* dst) const;
- /**
- * Hermite interpolation function.
- */
- void interpolateHermiteSmooth(float s, unsigned int index, Point* from, Point* to, float* dst) const;
- /**
- * Linear interpolation function.
- */
- void interpolateLinear(float s, Point* from, Point* to, float* dst) const;
- /**
- * Quaternion interpolation function.
- */
- void interpolateQuaternion(float s, float* from, float* to, float* dst) const;
-
- /**
- * Determines the current keyframe to interpolate from based on the specified time.
- */
- int determineIndex(float time) const;
- /**
- * Sets the offset for the beginning of a Quaternion piece of data within the curve's value span at the specified
- * index. The next four components of data starting at the given index will be interpolated as a Quaternion.
- * This function will assert an error if the given index is greater than the component size subtracted by the four components required
- * to store a quaternion.
- *
- * @param index The index of the Quaternion rotation data.
- */
- void setQuaternionOffset(unsigned int index);
- /**
- * Gets the InterpolationType value for the given string ID
- *
- * @param interpolationId The string representation of the InterpolationType
- * @return the InterpolationType value; -1 if the string does not represent an InterpolationType.
- */
- static int getInterpolationType(const char* interpolationId);
- unsigned int _pointCount; // Number of points on the curve.
- unsigned int _componentCount; // Number of components on the curve.
- unsigned int _componentSize; // The component size (in bytes).
- unsigned int* _quaternionOffset; // Offset for the rotation component.
- Point* _points; // The points on the curve.
- };
- inline static float bezier(float eq0, float eq1, float eq2, float eq3, float from, float out, float to, float in);
- inline static float bspline(float eq0, float eq1, float eq2, float eq3, float c0, float c1, float c2, float c3);
- inline static float hermite(float h00, float h01, float h10, float h11, float from, float out, float to, float in);
- inline static float hermiteFlat(float h00, float h01, float from, float to);
- inline static float hermiteSmooth(float h00, float h01, float h10, float h11, float from, float out, float to, float in);
- inline static float lerpInl(float s, float from, float to);
- }
- #include "Curve.inl"
- #endif
|