resonance 1.0.1
Loading...
Searching...
No Matches
keychannel.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4
5#include "math/color.h"
6#include "math/vector3.h"
7
8namespace Rnd {
9class Dbg;
10class Stream;
11} // namespace Rnd
12
13namespace Rnd {
14
34struct ColorKey {
36 float mFrame;
37};
38
48struct FloatKey {
49 float mValue;
50 float mFrame;
51};
52
61struct Vector3Key {
69 mValue.w = 1.0f;
70 }
71
73 float mFrame;
74};
75
92Dbg &DumpColorKeys(Dbg &sink, const std::list<ColorKey> &keys);
93
106Dbg &DumpFloatKeys(Dbg &sink, const std::list<FloatKey> &keys);
107
121Stream &ReadColorKeys(Stream &stream, std::list<ColorKey> &keys);
122
134Stream &WriteColorKeys(Stream &stream, const std::list<ColorKey> &keys);
135
145Stream &WriteFloatKeys(Stream &stream, const std::list<FloatKey> &keys);
146
159Stream &ReadFloatKeys(Stream &stream, std::list<FloatKey> &keys);
160
173Dbg &DumpVector3Keys(Dbg &sink, const std::list<Vector3Key> &keys);
174
187Stream &ReadVector3Keys(Stream &stream, std::list<Vector3Key> &keys);
188
200Stream &operator<<(Stream &stream, const std::list<Vector3Key> &keys);
201
212template <class Key>
213inline float ChannelEndFrame(const std::list<Key> &keys) {
214 if (keys.size() == 0) {
215 return 0.0f;
216 }
217 return keys.back().mFrame;
218}
219
234template <class Key>
235inline void SelectKeyPair(
236 const std::list<Key> &keys, float flFrame, const Key *&pFrom, const Key *&pTo, float &flBlend) {
237 if (flFrame <= keys.front().mFrame) {
238 pFrom = &keys.front();
239 pTo = &keys.front();
240 flBlend = 0.0f;
241 return;
242 }
243 if (keys.back().mFrame <= flFrame) {
244 pFrom = &keys.back();
245 pTo = &keys.back();
246 flBlend = 1.0f;
247 return;
248 }
249
250 typename std::list<Key>::const_iterator itFrom = keys.begin();
251 typename std::list<Key>::const_iterator itTo = itFrom;
252 ++itTo;
253 while (itTo != keys.end() && flFrame > itTo->mFrame) {
254 itFrom = itTo;
255 ++itTo;
256 }
257 pFrom = &*itFrom;
258 pTo = &*itTo;
259 flBlend = (flFrame - itFrom->mFrame) / (itTo->mFrame - itFrom->mFrame);
260}
261
262} // namespace Rnd
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
The rendering engine.
Definition animhelper.h:3
Stream & ReadColorKeys(Stream &stream, std::list< ColorKey > &keys)
Read a channel of colour keyframes from a .rnd stream.
Dbg & DumpColorKeys(Dbg &sink, const std::list< ColorKey > &keys)
Write a channel of colour keyframes to the engine text sink.
Stream & operator<<(Stream &stream, const std::list< Vector3Key > &keys)
Write a channel of vector keyframes to a .rnd stream.
Dbg & DumpFloatKeys(Dbg &sink, const std::list< FloatKey > &keys)
Write a channel of scalar keyframes to the engine text sink.
Stream & ReadFloatKeys(Stream &stream, std::list< FloatKey > &keys)
Read a channel of scalar keyframes from a .rnd stream.
void SelectKeyPair(const std::list< Key > &keys, float flFrame, const Key *&pFrom, const Key *&pTo, float &flBlend)
Select the keyframe pair bracketing a frame, and the blend between the pair.
Definition keychannel.h:235
Stream & WriteColorKeys(Stream &stream, const std::list< ColorKey > &keys)
Write a channel of colour keyframes to a .rnd stream.
Stream & ReadVector3Keys(Stream &stream, std::list< Vector3Key > &keys)
Read a channel of vector keyframes from a .rnd stream.
Dbg & DumpVector3Keys(Dbg &sink, const std::list< Vector3Key > &keys)
Write a channel of vector keyframes to the engine text sink.
float ChannelEndFrame(const std::list< Key > &keys)
Report the frame of the last keyframe of a channel, and zero for an empty channel.
Definition keychannel.h:213
Stream & WriteFloatKeys(Stream &stream, const std::list< FloatKey > &keys)
Write a channel of scalar keyframes to a .rnd stream.
Linear colour with four float components.
Definition color.h:10
One keyframe of a colour channel.
Definition keychannel.h:34
float mFrame
Definition keychannel.h:36
Color mValue
Definition keychannel.h:35
One keyframe of a scalar channel.
Definition keychannel.h:48
float mValue
Definition keychannel.h:49
float mFrame
Definition keychannel.h:50
Vector3 mValue
Definition keychannel.h:72
float mFrame
Definition keychannel.h:73
Vector3Key()
Construct a key whose value has only its padding word set.
Definition keychannel.h:68
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:12