15 #ifndef MOTIVE_MOTIVATOR_H
16 #define MOTIVE_MOTIVATOR_H
18 #include "motive/processor.h"
64 if (original.
Valid()) {
68 index_ = kMotiveIndexInvalid;
120 MotiveDimension dimensions)
122 InitializeWithDimension(init, engine, dimensions);
125 void InitializeWithDimension(
const MotivatorInit& init, MotiveEngine* engine,
126 MotiveDimension dimensions);
137 void Reset() {
Init(
nullptr, kMotiveIndexInvalid); }
163 MotiveDimension dimensions)
181 MotiveDimension dimensions) {
182 InitializeWithDimension(init, engine, dimensions);
189 MotiveDimension dimensions,
201 MotiveDimension dimensions,
203 const float* target_values,
204 const float* target_velocities) {
205 InitializeWithDimension(init, engine, dimensions);
213 MotiveDimension dimensions,
221 const float* Values()
const {
return Processor().Values(
index_); }
222 void Velocities(
float* out)
const {
225 void Directions(
float* out)
const {
228 void TargetValues(
float* out)
const {
231 void TargetVelocities(
float* out)
const {
234 void Differences(
float* out)
const {
246 return Processor().MotiveShape(
index_);
323 const float* target_velocities,
326 target_velocities, shape);
348 const MotiveProcessorNf& Processor()
const {
349 return *
static_cast<const MotiveProcessorNf*
>(
processor_);
364 template <
class VectorConverter, MotiveDimension kDimensionsParam>
367 typedef VectorConverter C;
368 static const MotiveDimension kDimensions = kDimensionsParam;
369 typedef typename VectorT<C, kDimensions>::type Vec;
370 typedef typename MotiveTargetT<kDimensions>::type Target;
392 InitializeWithDimension(init, engine, kDimensions);
399 InitializeWithDimension(init, engine, kDimensions);
409 MotiveDimension dimensions,
411 const Vec& target_values,
412 const Vec& target_velocities) {
413 InitializeWithDimension(init, engine, dimensions);
422 Vec
Value()
const {
return C::FromPtr(Processor().Values(
index_), Vec()); }
429 Processor().Velocities(
index_, kDimensions, C::ToPtr(r));
438 Processor().Directions(
index_, kDimensions, C::ToPtr(r));
446 Processor().TargetValues(
index_, kDimensions, C::ToPtr(r));
454 Processor().TargetVelocities(
index_, kDimensions, C::ToPtr(r));
464 Processor().Differences(
index_, kDimensions, C::ToPtr(r));
484 Processor().SetTargets(
index_, kDimensions, t.targets());
499 Processor().SetTargetWithShape(
index_, kDimensions, C::ToPtr(target_value),
500 C::ToPtr(target_velocity), shape);
503 MotiveDimension Dimensions()
const {
return kDimensions; }
517 template <
class VectorConverter>
520 typedef VectorConverter C;
521 typedef typename VectorConverter::Matrix4 Mat4;
522 typedef typename VectorConverter::Vector3 Vec3;
531 InitializeWithDimension(init, engine, 1);
540 return reinterpret_cast<const Mat4&
>(Processor().
Value(
index_));
547 const mathfu::vec3 position =
549 return C::FromPtr(&position[0], Vec3());
589 return static_cast<const Mot1f*
>(
613 Processor().SetChildValues(
index_, child_index, 1, &value);
625 Processor().SetChildValues(
index_, child_index, 3, C::ToPtr(value));
634 void SetPlaybackRate(
float playback_rate) {
639 MatrixProcessor4f& Processor() {
640 return *
static_cast<MatrixProcessor4f*
>(
processor_);
642 const MatrixProcessor4f& Processor()
const {
643 return *
static_cast<const MatrixProcessor4f*
>(
processor_);
657 InitializeWithDimension(init, engine, 1);
668 void SetPlaybackRate(
float playback_rate) {
698 std::string CsvHeaderForDebugging()
const {
699 return Processor().CsvHeaderForDebugging(
index_);
701 std::string CsvValuesForDebugging()
const {
702 return Processor().CsvValuesForDebugging(
index_);
704 std::string LocalTransformsForDebugging(BoneIndex bone)
const {
705 return Processor().LocalTransformsForDebugging(
index_, bone);
709 RigProcessor& Processor() {
return *
static_cast<RigProcessor*
>(
processor_); }
710 const RigProcessor& Processor()
const {
711 return *
static_cast<const RigProcessor*
>(
processor_);
716 typedef MotivatorXfTemplate<MathFuVectorConverter, 1> Motivator1f;
717 typedef MotivatorXfTemplate<MathFuVectorConverter, 2> Motivator2f;
718 typedef MotivatorXfTemplate<MathFuVectorConverter, 3> Motivator3f;
719 typedef MotivatorXfTemplate<MathFuVectorConverter, 4> Motivator4f;
720 typedef MatrixMotivator4fTemplate<MathFuVectorConverter> MatrixMotivator4f;
724 #endif // MOTIVE_MOTIVATOR_H
virtual const Motivator * ChildMotivator1f(MotiveIndex index, MotiveChildIndex child_index) const =0
Interface for motivator types that drive a single float value.
Definition: processor.h:264
void SetTargetWithShape(const float *target_values, const float *target_velocities, const MotiveCurveShape &shape)
Definition: motivator.h:322
virtual void SetChildTarget1f(MotiveIndex, MotiveChildIndex, const MotiveTarget1f &)
Set child values. Matrices are composed from child components.
Definition: processor.h:383
void BlendToAnim(const RigAnim &anim, const SplinePlayback &playback)
Definition: motivator.h:664
Vec TargetVelocity() const
Definition: motivator.h:452
virtual int NumChildren(MotiveIndex index) const =0
Get the number of matrix operations performed by this motivator.
MotiveCurveShape MotiveShape() const
Returns the shape of the current curve.
Definition: motivator.h:245
void SetSplines(const CompactSpline *splines, const SplinePlayback &playback)
Definition: motivator.h:282
void Initialize(const MotivatorInit &init, MotiveEngine *engine)
Definition: motivator.h:656
void InitializeWithTarget(const MotivatorInit &init, MotiveEngine *engine, const Target &t)
Definition: motivator.h:397
float ChildValue1f(MotiveChildIndex child_index) const
Definition: motivator.h:566
void InitializeWithSplines(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions, const CompactSpline *splines, const SplinePlayback &playback)
Definition: motivator.h:212
void BlendToOps(const MatrixOpArray &ops, const SplinePlayback &playback)
Definition: motivator.h:630
Utility functions to construct MotiveTargets of dimension >= 2.
Definition: target.h:297
Definition: motivator.h:154
virtual void BlendToAnim(MotiveIndex index, const RigAnim &anim, const motive::SplinePlayback &playback)=0
Smoothly transition to the animation in anim.
virtual void SetPlaybackRate(MotiveIndex index, float playback_rate)=0
Instantly change the playback speed of this animation.
virtual const mathfu::AffineTransform * GlobalTransforms(MotiveIndex index) const =0
void SetSplinesAndTargets(const CompactSpline *const *splines, const SplinePlayback &playback, const MotiveTarget1f *targets)
Definition: motivator.h:337
Drive a 4x4 float matrix from a series of basic transformations.
Definition: motivator.h:518
virtual const mathfu::mat4 & Value(MotiveIndex index) const =0
Get the current matrix value from the processor.
virtual MotiveTime TimeRemaining(MotiveIndex index) const =0
Return the time remaining in the current matrix animation.
A MotiveProcessor processes all instances of one type of Motivator.
Definition: processor.h:58
MotiveTime TimeRemaining() const
Definition: motivator.h:554
MotiveTime TimeRemaining() const
Definition: motivator.h:696
Vec Direction() const
Definition: motivator.h:436
void InitializeWithTargetShape(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions, const MotiveCurveShape &shape, const Vec &target_values, const Vec &target_velocities)
Definition: motivator.h:407
Animation for a RigMotivator. Drives a fully rigged model.
Definition: anim.h:72
bool ValidMotivator(MotiveIndex index, const Motivator *motivator) const
Definition: processor.h:128
virtual MotivatorType Type() const =0
A target curve shape for the motivator.
Definition: target.h:29
void SetChildValue1f(MotiveChildIndex child_index, float value)
Definition: motivator.h:612
~Motivator()
Remove ourselves from the MotiveProcessor when we're deleted.
Definition: motivator.h:83
Vec3 Position() const
Definition: motivator.h:546
bool Valid() const
Definition: motivator.h:95
Vec3 ChildValue3f(MotiveChildIndex child_index) const
Definition: motivator.h:580
Motivator(const Motivator &original)
Definition: motivator.h:63
const RigAnim * DefiningAnim() const
Definition: motivator.h:690
void Initialize(const MotivatorInit &init, MotiveEngine *engine)
Initialize to the type specified by init.
Definition: motivator.h:530
MotivatorXfTemplate(const MotivatorInit &init, MotiveEngine *engine)
Definition: motivator.h:379
void RemoveMotivator(MotiveIndex index)
void Init(MotiveProcessor *processor, MotiveIndex index)
These should only be called by MotiveProcessor!
Definition: motivator.h:133
virtual void BlendToOps(MotiveIndex, const MatrixOpArray &, const motive::SplinePlayback &)
Smoothly transition to the operations specified in ops.
Definition: processor.h:390
MotiveDimension Dimensions() const
Definition: motivator.h:116
MotiveTime TargetTime() const
Definition: motivator.h:240
Hold and update all animation data.
Definition: engine.h:36
void SetTargets(const MotiveTarget1f *targets)
Definition: motivator.h:307
void Invalidate()
Definition: motivator.h:87
const Mat4 & Value() const
Definition: motivator.h:537
void SetChildTarget1f(MotiveChildIndex child_index, const MotiveTarget1f &t)
Definition: motivator.h:601
virtual void ChildValues(MotiveIndex index, MotiveChildIndex child_index, MotiveChildIndex count, float *values) const =0
Get current values of the components that create the matrix.
friend class MotiveProcessor
Definition: motivator.h:130
Vec TargetValue() const
Definition: motivator.h:444
MotivatorNf(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions, const MotiveTarget1f *ts)
Definition: motivator.h:168
Parameters to specify how a spline should be traversed.
Definition: compact_spline.h:590
void SetSplineTime(MotiveTime time)
Definition: motivator.h:289
Vec Difference() const
Definition: motivator.h:462
MotivatorXfTemplate(const MotivatorInit &init, MotiveEngine *engine, const Target &t)
Definition: motivator.h:384
MotiveDimension Dimensions(MotiveIndex index) const
Definition: processor.h:153
MotivatorNf()
Definition: motivator.h:158
Drives a value towards a target value, or along a path.
Definition: motivator.h:47
void Initialize(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions)
Definition: motivator.h:180
Definition: motivator.h:647
const Mot1f * ChildMotivator1f(MotiveChildIndex child_index) const
Definition: motivator.h:588
void TransferMotivator(MotiveIndex index, Motivator *new_motivator)
Set the current and/or target state for a one-dimensional Motivator.
Definition: target.h:98
MotivatorNf(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions)
Definition: motivator.h:162
int NumChildren() const
Definition: motivator.h:558
Motivator & operator=(const Motivator &original)
Definition: motivator.h:74
Represent a smooth curve in a small amount of memory.
Definition: compact_spline.h:73
void InitializeWithTargetShape(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions, const MotiveCurveShape &shape, const float *target_values, const float *target_velocities)
Definition: motivator.h:199
MotiveTime SplineTime() const
Definition: motivator.h:256
const mathfu::AffineTransform * GlobalTransforms() const
Definition: motivator.h:675
void Splines(const CompactSpline **splines) const
Definition: motivator.h:260
Vec Velocity() const
Definition: motivator.h:427
void Initialize(const MotivatorInit &init, MotiveEngine *engine)
Initialize to the motion algorithm specified by init.
Definition: motivator.h:391
void SetTarget(const Target &t)
Definition: motivator.h:483
MotiveProcessor * processor_
Definition: motivator.h:143
virtual const RigAnim * DefiningAnim(MotiveIndex index) const =0
Return the animation that defines the rig.
void SetChildValue3f(MotiveChildIndex child_index, const Vec3 &value)
Definition: motivator.h:624
void InitializeWithTargets(const MotivatorInit &init, MotiveEngine *engine, MotiveDimension dimensions, const MotiveTarget1f *targets)
Definition: motivator.h:188
void SetTargetWithShape(const Vec &target_value, const Vec &target_velocity, const MotiveCurveShape &shape)
Definition: motivator.h:497
MotivatorXfTemplate()
Definition: motivator.h:375
Vec Value() const
Definition: motivator.h:422
MotivatorType Type() const
Definition: motivator.h:108
void SetSplinePlaybackRate(float playback_rate)
Definition: motivator.h:298
Animate a vector of floating-point values.
Definition: motivator.h:365
bool Sane() const
Definition: motivator.h:100
void SetSpline(const CompactSpline &spline, const SplinePlayback &playback)
Definition: motivator.h:270
virtual void SetPlaybackRate(MotiveIndex index, float playback_rate)=0
Instantly change the playback speed of this animation.
MotiveIndex index_
Definition: motivator.h:148