15 #ifndef MOTIVE_INIT_H_
16 #define MOTIVE_INIT_H_
18 #include "mathfu/constants.h"
19 #include "motive/math/range.h"
20 #include "motive/math/vector_converter.h"
21 #include "motive/util.h"
27 enum MatrixOperationType {
28 kInvalidMatrixOperation,
39 kNumMatrixOperationTypes
43 inline bool RotateOp(MatrixOperationType op) {
44 return kRotateAboutX <= op && op <= kRotateAboutZ;
48 inline bool TranslateOp(MatrixOperationType op) {
49 return kTranslateX <= op && op <= kTranslateZ;
53 inline bool ScaleOp(MatrixOperationType op) {
54 return kScaleX <= op && op <= kScaleUniformly;
60 inline float OperationDefaultValue(MatrixOperationType op) {
61 return ScaleOp(op) ? 1.0f : 0.0f;
67 inline Range RangeOfOp(MatrixOperationType op) {
68 return RotateOp(op) ? kAngleRange : kInvalidRange;
72 const char* MatrixOpName(
const MatrixOperationType op);
111 template <
class BaseT,
class VectorConverter, MotiveDimension kDimensionsParam>
113 static const MotiveDimension kDimensions = kDimensionsParam;
115 typedef VectorConverter C;
116 typedef typename VectorT<C, kDimensions>::type Vec;
119 : BaseT(C::ToPtr(start_values), C::ToPtr(start_derivatives)),
121 start_derivatives(0.0f) {}
124 const Vec& start_derivatives_param)
125 : BaseT(C::ToPtr(start_values), C::ToPtr(start_derivatives)),
126 start_values(start_values_param),
127 start_derivatives(start_derivatives_param) {}
129 const Vec start_values;
130 const Vec start_derivatives;
221 accel_per_difference_(0.0f),
222 wrong_direction_multiplier_(0.0f),
223 max_delta_time_(0) {}
227 return mathfu::Clamp(velocity, -max_velocity_, max_velocity_);
234 return mathfu::Clamp(delta, -max_delta_, max_delta_);
241 return at_target_.
Settled(dist, velocity);
244 const Range& range()
const {
return range_; }
245 void set_range(
const Range& r) { range_ = r; }
246 bool modular()
const {
return modular_; }
247 void set_modular(
bool modular) { modular_ = modular; }
248 float max_velocity()
const {
return max_velocity_; }
249 float max_delta()
const {
return max_delta_; }
250 const Settled1f& at_target()
const {
return at_target_; }
251 Settled1f& at_target() {
return at_target_; }
252 float accel_per_difference()
const {
return accel_per_difference_; }
253 float wrong_direction_multiplier()
const {
254 return wrong_direction_multiplier_;
256 MotiveTime max_delta_time()
const {
return max_delta_time_; }
258 void set_max_velocity(
float max_velocity) { max_velocity_ = max_velocity; }
259 void set_max_delta(
float max_delta) { max_delta_ = max_delta; }
260 void set_at_target(
const Settled1f& at_target) { at_target_ = at_target; }
261 void set_accel_per_difference(
float accel_per_difference) {
262 accel_per_difference_ = accel_per_difference;
264 void set_wrong_direction_multiplier(
float wrong_direction_multiplier) {
265 wrong_direction_multiplier_ = wrong_direction_multiplier;
267 void set_max_delta_time(MotiveTime max_delta_time) {
268 max_delta_time_ = max_delta_time;
295 Settled1f at_target_;
299 float accel_per_difference_;
304 float wrong_direction_multiplier_;
308 MotiveTime max_delta_time_;
328 const Range& range()
const {
return range_; }
329 void set_range(
const Range& r) { range_ = r; }
361 union_type(kUnionInitialValue),
362 initial_value(const_value) {}
367 : init(&init), id(id), type(type), union_type(kUnionEmpty) {}
376 union_type(kUnionInitialValue),
377 initial_value(initial_value) {}
384 union_type(kUnionTarget),
388 const MotivatorInit& init,
const CompactSpline& spline)
392 union_type(kUnionSpline),
395 const MotivatorInit* init;
397 MatrixOperationType type;
398 UnionType union_type;
401 const MotiveTarget1f* target;
402 const CompactSpline* spline;
426 typedef std::vector<MatrixOperationInit> OpVector;
430 static const int kDefaultExpectedNumOps = 8;
436 ops_.reserve(expected_num_ops);
440 void Clear(
int expected_num_ops = kDefaultExpectedNumOps) {
442 ops_.reserve(expected_num_ops);
447 void AddOp(MatrixOpId
id, MatrixOperationType type,
float const_value) {
454 void AddOp(MatrixOpId
id, MatrixOperationType type,
462 float initial_value) {
481 MotiveTime EndTime()
const {
482 MotiveTime end_time = 0;
483 for (
size_t i = 0; i < ops_.size(); ++i) {
485 if (op.union_type == MatrixOperationInit::kUnionSpline) {
487 std::max(end_time, static_cast<MotiveTime>(op.spline->EndX()));
493 const OpVector& ops()
const {
return ops_; }
502 typedef std::vector<MatrixOperationInit> OpVector;
507 const OpVector& ops()
const {
return ops_->ops(); }
521 RigInit(
const RigAnim& defining_anim,
const BoneIndex* bone_parents,
522 BoneIndex num_bones);
523 const RigAnim& defining_anim()
const {
return *defining_anim_; }
524 const mathfu::AffineTransform* bone_transforms()
const {
525 return bone_transforms_;
529 static bool MatchesHierarchy(
const BoneIndex* parents_a, BoneIndex len_a,
530 const BoneIndex* parents_b, BoneIndex len_b);
531 static bool MatchesHierarchy(
const RigAnim& anim,
const BoneIndex* parents_b,
533 static bool MatchesHierarchy(
const RigAnim& anim_a,
const RigAnim& anim_b);
546 const mathfu::AffineTransform* bone_transforms_;
551 #endif // MOTIVE_INIT_H_
SplineInit(const Range &range)
Definition: init.h:326
bool AtTarget(float dist, float velocity) const
Definition: init.h:240
MotivatorInit(MotivatorType type)
The derived class's constructor should set 'type'.
Definition: common.h:95
MatrixOperationInit(MatrixOpId id, MatrixOperationType type, float const_value)
Matrix operation never changes. Always use 'const_value'.
Definition: init.h:356
Animation for a RigMotivator. Drives a fully rigged model.
Definition: anim.h:72
Initialize a MotivatorNf move oscillate over a target.
Definition: init.h:187
Initialize a MotivatorNf to follow a spline.
Definition: init.h:317
MatrixOperationInit(MatrixOpId id, MatrixOperationType type, const MotivatorInit &init, float initial_value)
Definition: init.h:371
void AddOp(MatrixOpId id, MatrixOperationType type, const MotivatorInit &init)
Definition: init.h:454
MatrixOpArray(int expected_num_ops=kDefaultExpectedNumOps)
Definition: init.h:435
void AddOp(MatrixOpId id, MatrixOperationType type, const MotivatorInit &init, const CompactSpline &spline)
Definition: init.h:475
void Clear(int expected_num_ops=kDefaultExpectedNumOps)
Remove all matrix operations from the sequence.
Definition: init.h:440
Base class of Init classes for MotiveProcessors that derive from SimpleProcessorTemplate.
Definition: init.h:81
static RangeT< T > Full()
Returns the complete range. Every T is contained in this range.
Definition: range.h:479
bool Settled(float dist, float velocity) const
Definition: util.h:37
A version of SimpleInit for Motivators with kDimensions. Use this class to initialize a Motivator wit...
Definition: init.h:112
const float * start_values
Definition: init.h:97
Initialize a MatrixMotivator4f to generate its matrix from a series of operations.
Definition: init.h:499
float ClampDelta(float delta) const
Definition: init.h:233
void AddOp(MatrixOpId id, MatrixOperationType type, const MotivatorInit &init, const MotiveTarget1f &target)
Definition: init.h:468
Initialize a MotivatorNf that holds values and velocities that never change.
Definition: init.h:138
Initialize a MotivatorNf move towards a target using spring physics.
Definition: init.h:212
Set the current and/or target state for a one-dimensional Motivator.
Definition: target.h:98
Represent a smooth curve in a small amount of memory.
Definition: compact_spline.h:73
void AddOp(MatrixOpId id, MatrixOperationType type, const MotivatorInit &init, float initial_value)
Definition: init.h:461
float ClampVelocity(float velocity) const
Ensure velocity is within the reasonable limits.
Definition: init.h:226
Initialize a MotivatorNf move towards target using ease-in ease-out math.
Definition: init.h:163
const float * start_derivatives
Definition: init.h:103
MatrixOperationInit(MatrixOpId id, MatrixOperationType type, const MotivatorInit &init)
Matrix operation is driven by Motivator defined by 'init'.
Definition: init.h:365
void AddOp(MatrixOpId id, MatrixOperationType type, float const_value)
Definition: init.h:447
Init params for a basic operation on a matrix.
Definition: init.h:347
Represent an interval on a number line.
Definition: range.h:37