56 if (fFrame <= keys.front().frame) {
57 pPrev = &keys.front();
59 pNext = &keys.front();
62 const Key<T> &last = keys.back();
63 if (last.
frame <= fFrame) {
67 const int nSize =
static_cast<int>(keys.size());
68 return fFrame == last.
frame ? nSize - 1 : nSize;
71 int nHigh =
static_cast<int>(keys.size()) - 1;
72 while (nLow + 1 < nHigh) {
73 const int nMiddle = (nLow + nHigh) >> 1;
74 const Key<T> &middle = keys.at(nMiddle);
75 if (fFrame == middle.
frame) {
81 if (middle.
frame < fFrame) {
87 pPrev = &keys.at(nLow);
88 pNext = &keys.at(nHigh);
89 fRatio = (fFrame - keys.at(nLow).frame) / (keys.at(nHigh).frame - pPrev->
frame);
104 if (fRatio == 0.0f) {
106 }
else if (fRatio == 1.0f) {
109 const float fInverse = 1.0f - fRatio;
111 out.
x = b.
x * fRatio + a.
x * fInverse;
112 out.
y = b.
y * fRatio + a.
y * fInverse;
113 out.
z = b.
z * fRatio + a.
z * fInverse;
126 if (fRatio == 0.0f) {
128 }
else if (fRatio == 1.0f) {
131 out.
x = (b.
x - a.
x) * fRatio + a.
x;
132 out.
y = (b.
y - a.
y) * fRatio + a.
y;
145 const float fInverse = 1.0f - fRatio;
146 out.
r = b.
r * fRatio + a.
r * fInverse;
147 out.
g = b.
g * fRatio + a.
g * fInverse;
148 out.
b = b.
b * fRatio + a.
b * fInverse;
149 out.
a = b.
a * fRatio + a.
a * fInverse;
160inline void Interp(
float fA,
float fB,
float fRatio,
float &fOut) {
161 fOut = (fB - fA) * fRatio + fA;
178void Interp(T *pA, [[maybe_unused]] T *pB, [[maybe_unused]]
float fRatio, T *&pOut) {
197 AtFrame(keys, fFrame, pPrev, pNext, fRatio);
198 if (pPrev !=
nullptr) {
212 return keys.empty() ? 0.0f : keys.front().frame;
224 return keys.empty() ? 0.0f : keys.back().frame;
362 const int nSize =
static_cast<int>(values.size());
364 for (
const T &value : values) {
388 values.resize(nSize, T());
389 for (T &value : values) {
484 stream <<
"(frame:" << key.
frame <<
" value:" << key.
value <<
")";
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
void ReadEndian(void *pData, int nBytes)
Read a value of 2, 4, 8, or 16 bytes, reversing its bytes unless the stream is little endian.
void WriteEndian(const void *pData, int nBytes)
Write a value of 2, 4, 8, or 16 bytes, reversing its bytes unless the stream is little endian.
Text output stream.
Definition prnstream.h:16
Rotation quaternion, stored as the vector part followed by the scalar part.
Definition quaternion.h:19
float x
Definition quaternion.h:47
float z
Definition quaternion.h:49
float y
Definition quaternion.h:48
float w
Definition quaternion.h:50
float FirstFrame(const std::vector< Key< T > > &keys)
Report the frame of the first key, or 0 for no keys.
Definition key.h:211
BinStream & operator<<(BinStream &stream, const Key< T > &key)
Write a key as its value followed by its frame.
Definition key.h:419
void InterpKeys(const std::vector< Key< T > > &keys, float fFrame, T &out)
Interpolate keys at a frame.
Definition key.h:193
BinStream & operator>>(BinStream &stream, Key< T > &key)
Read a key the key writer wrote.
Definition key.h:450
void ReadKeyValue(BinStream &stream, float &fValue)
Read a float key value.
Definition key.h:292
void WriteKeyValue(BinStream &stream, float fValue)
Write a float key value.
Definition key.h:233
float LastFrame(const std::vector< Key< T > > &keys)
Report the frame of the last key, or 0 for no keys.
Definition key.h:223
int AtFrame(const std::vector< Key< T > > &keys, float fFrame, const Key< T > *&pPrev, const Key< T > *&pNext, float &fRatio)
Find the keys around a frame.
Definition key.h:46
void Interp(const Vector3 &a, const Vector3 &b, float fRatio, Vector3 &out)
Blend two vectors, taking either end exactly at a position of 0 or 1.
Definition key.h:103
Linear colour with four float components.
Definition color.h:12
float b
Definition color.h:15
float r
Definition color.h:13
float g
Definition color.h:14
float a
Definition color.h:16
One keyframe of an animation channel, a value at a frame.
Definition key.h:21
float frame
Definition key.h:23
T value
Definition key.h:22
Two-component vector, used for texture coordinates.
Definition vector2.h:12
float x
Definition vector2.h:13
float y
Definition vector2.h:14
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14
float x
Definition vector3.h:15
float y
Definition vector3.h:16
float z
Definition vector3.h:17