resonance 1.0.1
Loading...
Searching...
No Matches
transanim.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4
5#include "math/quaternion.h"
6#include "rnd/animatable.h"
7#include "rnd/drawable.h"
8// Included for kXfmRowFloatCount, which this header uses by value, rather than for Transformable.
9#include "rnd/transformable.h"
10
11struct Vector3;
12namespace Rnd {
13class Dbg;
14class Object;
15class Stream;
16} // namespace Rnd
17
18namespace Rnd {
19
27constexpr unsigned kCopyShareFrames = 0x100;
28
49class TransAnim : public Animatable, public Drawable {
50public:
59 static TransAnim *(*sNew)(const HxStr &name);
60
62 enum Interp {
65 };
66
73
87 class TransKey {
88 public:
108 void ComputeSplineTangents(const TransKey *pPrev, const TransKey *pNext);
109
123 void EvaluateSpline(const TransKey *pNext, float *pOut, float flT) const;
124
137 Vector3 EvaluateSplineDerivative(const TransKey *pNext, float flT) const;
138
147 bool operator<(const TransKey &other) const {
148 return mFrame < other.mFrame;
149 }
150
155 float mFrame;
156 };
157
165 class RotKey {
166 public:
187 void ComputeSplineTangents(const RotKey *pPrev, const RotKey *pNext);
188
203 void EvaluateSpline(const RotKey *pNext, Quat &out, float flT) const;
204
214 bool operator<(const RotKey &other) const {
215 return mFrame < other.mFrame;
216 }
217
222 float mFrame;
223 };
224
234 explicit TransAnim(const HxStr &name);
235
242 virtual ~TransAnim();
243
251 virtual const HxStr &ClassName() const;
252
264 virtual float FilteredFrameEnd();
265
277 virtual float StartFrame();
278
286 virtual void DumpText(Dbg &sink);
287
299 virtual void Save(Stream &stream);
300
316 virtual void Load(Stream &stream);
317
331 virtual void Replace(Object *pFrom, Object *pTo);
332
341 virtual void Copy(const Object *pSource, unsigned nFlags);
342
368 void EvalFrame(float flFrame, float *pXfm, int nResetEmpty);
369
394 void Normalize();
395
408 void SetRepeatTrans(int nRepeat);
409
420 void SetTrans(Transformable *pTrans);
421
434
445 return mFramesOwner;
446 }
447
448protected:
460 virtual void SetFrameSelf(float flFrame);
461
462private:
471 void ClearKeys();
472
481 void AddRefObjects();
482
491 void ReleaseObjects();
492
493 // Declared in recovered offset order. The transformable this animation drives.
494 Transformable *mTrans; // +0x2c
495 // Interpolation mode per channel, one of the Interp values.
496 int mRotInterp; // +0x30
497 int mTransInterp; // +0x34
498 int mScaleInterp; // +0x38
499
500public:
507 std::list<RotKey> mRotKeys;
508
509private:
510 std::list<TransKey> mTransKeys; // +0x40
511 std::list<TransKey> mScaleKeys; // +0x44
512 // The object whose keyframes drive this one, which is this object when it owns its frames.
513 TransAnim *mFramesOwner; // +0x48
514 int mRepeatTrans; // +0x4c
515 int mFollowPath; // +0x50
516};
517
531float Length(const TransAnim::TransKey &first, const TransAnim::TransKey &next);
532
545
558
571
583
591
592} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Rotation quaternion, stored as the vector part followed by the scalar part.
Definition quaternion.h:17
Animatable()
Construct an animatable with no children, no filters, and a zero frame.
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Drawable()
Construct a visible drawable with no children.
Base of every object the renderer can load, resolve by name, and serialise.
Definition object.h:43
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
One keyframe of the rotation channel.
Definition transanim.h:165
float mShape[kXfmRowFloatCount]
Definition transanim.h:221
float mFrame
Definition transanim.h:222
bool operator<(const RotKey &other) const
Order keyframes by frame.
Definition transanim.h:214
void ComputeSplineTangents(const RotKey *pPrev, const RotKey *pNext)
Build the two Kochanek-Bartels tangents of this keyframe from its neighbours.
void EvaluateSpline(const RotKey *pNext, Quat &out, float flT) const
Evaluate the spherical Bezier segment from this keyframe to pNext.
Quat mTangentOut
Definition transanim.h:220
Quat mQuat
Definition transanim.h:218
Quat mTangentIn
Definition transanim.h:219
One keyframe of the translation or the scale channel.
Definition transanim.h:87
void ComputeSplineTangents(const TransKey *pPrev, const TransKey *pNext)
Build the two Kochanek-Bartels tangents of this keyframe from its neighbours.
bool operator<(const TransKey &other) const
Order keyframes by frame.
Definition transanim.h:147
float mValue[kXfmRowFloatCount]
Definition transanim.h:151
float mShape[kXfmRowFloatCount]
Definition transanim.h:154
Vector3 EvaluateSplineDerivative(const TransKey *pNext, float flT) const
Evaluate the derivative of the segment EvaluateSpline() traces.
void EvaluateSpline(const TransKey *pNext, float *pOut, float flT) const
Evaluate the cubic Hermite segment from this keyframe to pNext.
float mTangentOut[kXfmRowFloatCount]
Definition transanim.h:153
float mFrame
Definition transanim.h:155
float mTangentIn[kXfmRowFloatCount]
Definition transanim.h:152
Animation that drives one transformable from three keyframe channels.
Definition transanim.h:49
Interp
Interpolation a channel applies between two keyframes.
Definition transanim.h:62
@ kInterpTCB
Definition transanim.h:64
@ kInterpLinear
Definition transanim.h:63
TransAnim(const HxStr &name)
Construct an animation with no target and three empty channels that it owns.
void SetRepeatTrans(int nRepeat)
Set whether the translation channel repeats.
TransAnim * GetFramesOwner() const
Report the object whose keyframes drive this one.
Definition transanim.h:444
void Normalize()
Redistribute the frames owner's translation keys to an even speed.
virtual void SetFrameSelf(float flFrame)
Write the transform this frame evaluates to into mTrans.
virtual void Load(Stream &stream)
Replace this object's state from stream.
void EvalFrame(float flFrame, float *pXfm, int nResetEmpty)
Evaluate the three channels at a frame into a transform.
void SetFramesOwner(TransAnim *pOwner)
Make another animation the one whose keyframes drive this one.
ShapeComponent
Floats of a keyframe's shape triple, labelled by the dumpers at 0x004f9160.
Definition transanim.h:68
@ kShapeBias
Definition transanim.h:71
@ kShapeContinuity
Definition transanim.h:70
@ kShapeTension
Definition transanim.h:69
void SetTrans(Transformable *pTrans)
Make a transformable the target this animation drives.
virtual float FilteredFrameEnd()
Report the last frame the frames owner's three channels animate to.
virtual void Replace(Object *pFrom, Object *pTo)
Retarget mTrans and mFramesOwner when either addresses pFrom.
virtual ~TransAnim()
Drop this object's references and every reference held on it.
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy the targets, the interpolation modes, the flags, and the channels from pSource.
virtual const HxStr & ClassName() const
Report the registered class name, "TransAnim".
virtual void DumpText(Dbg &sink)
Write a description of this object to sink.
virtual float StartFrame()
Report the first frame the frames owner's three channels animate from.
std::list< RotKey > mRotKeys
The rotation keyframes, kept in frame order.
Definition transanim.h:507
virtual void Save(Stream &stream)
Write the revision, both bases, both target names, the three channels, and the flags.
Mix-in for an object with a local and a world transform.
Definition transformable.h:38
The rendering engine.
Definition animhelper.h:3
constexpr unsigned kCopyShareFrames
Bit of the Copy() flags word that makes the copy share the source's keyframes.
Definition transanim.h:27
constexpr int kXfmRowFloatCount
Floats in one transform row.
Definition transformable.h:15
void RegisterTransAnimClass()
Point TransAnim::sNew at NewTransAnim() and register the "TransAnim" class with Rnd::Manager.
HxStr g_transAnimClassName
Registered class name of Rnd::TransAnim, the string "TransAnim".
TransAnim * NewTransAnimThroughHook(const HxStr &name)
Build a transform animation through the creator hook.
TransAnim * NewTransAnim(const HxStr &name)
Allocate and construct a transform animation, the base creator of the "TransAnim" class.
float Length(const Vector2 &v)
Report the length of a two-component vector.
Object * CreateRegisteredTransAnim(const HxStr &name)
Build a transform animation for the registered "TransAnim" class by calling through TransAnim::sNew.
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:12