1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.1.0 (2010/04/14)
#ifndef BIPEDMANAGER_H
#define BIPEDMANAGER_H
#include "Wm5Graphics.h"
using namespace Wm5;
class BipedManager
{
public:
// Construction and destruction.
BipedManager (const std::string& rootPath, const std::string& name);
~BipedManager ();
// Member access.
inline Node* GetRoot ();
// Get the extreme times for all the controllers of the animation.
inline void GetIdle (double& minTime, double& maxTime) const;
inline void GetWalk (double& minTime, double& maxTime) const;
inline void GetRun (double& minTime, double& maxTime) const;
// Set time sampler parameters.
inline void SetIdle (double frequency, double phase);
inline void SetWalk (double frequency, double phase);
inline void SetRun (double frequency, double phase);
// Select animations.
inline void DoIdle ();
inline void DoWalk ();
inline void DoRun ();
inline void DoIdleWalk ();
inline void DoWalkRun ();
// Set blending weight.
inline void SetIdleWalk (float weight);
inline void SetWalkRun (float weight);
// Finite state machine for switching and blending among animations.
// The input idleWalkCount is the maximum number of times Update samples
// the blend of idle and walk before transitioning to idle or walk. The
// input walkCount is the maximum number of times Update samples the
// walk when blendWalkToRun is 'true' in the Update function. The input
// walkRunCount is the maximum number of times Update samples the blend
// of walk and run before transitioning to walk or run.
void Initialize (int idleWalkCount, int walkCount, int walkRunCount);
// Select and sample the appropriate animation.
//
// If blendIdleToWalk is 'false', the input blendWalkToRun is ignored.
// The machine transitions from its current animation state (determined
// by count) to the idle animation (count is decremented to zero).
//
// If blendIdleToWalk is 'true' and blendWalkToRun is 'false', then the
// machine transitions from its current animation state (determined by
// count) to the walk-animation state (count is incremented). Once the
// machine enters the walk-animation state, it stays in that state.
//
// If blendIdleToWalk is 'true' and blendWalkToRun is 'true', then the
// machine transitions from its current animation state (determined by
// count) to the run-animation state (count is incremented). Once the
// machine enters the run-animation state, it stays in that state.
void Update (bool blendIdleToWalk, bool blendWalkToRun);
// Get the speed of the biped. This depends on the current animation
// state. The speed here is dimensionless, measured as the ratio
// mCount/mCountMax[ANIM_RUN], which is in [0,1].
float GetSpeed () const;
private:
// Loading support.
typedef std::vector<std::string> StringArray;
typedef std::map<std::string, Spatial*> SpatialMap;
typedef std::pair<Node*, TransformControllerPtr> NodeCtrl;
typedef std::vector<NodeCtrl> NodeCtrlArray;
class PreSpatial
{
public:
Spatial* Associate;
StringArray ChildNames;
};
typedef std::vector<PreSpatial*> PreSpatialArray;
class PreSkin
{
public:
SkinController* Associate;
StringArray BoneNames;
};
typedef std::vector<PreSkin*> PreSkinArray;
PreSpatial* LoadNode (const std::string& rootPath,
const std::string& name);
PreSpatial* LoadMesh (const std::string& rootPath,
const std::string& name, VertexFormat* vformat,
VisualEffectInstance* instance);
PreSkin* LoadSkinController (const std::string& rootPath,
const std::string& name);
TransformController* LoadTransformController (const std::string& rootPath,
const std::string& name, const std::string& animation);
// Run-time support.
void GetAnimation (const NodeCtrlArray& ncArray, double& minTime,
double& maxTime) const;
void SetAnimation (NodeCtrlArray& ncArray, double frequency,
double phase);
void SetBlendAnimation (NodeCtrlArray& ncArray, float weight);
void DoAnimation (NodeCtrlArray& ncArray);
// The biped and animation sequences.
NodePtr mRoot;
NodeCtrlArray mIdleArray, mWalkArray, mRunArray;
NodeCtrlArray mIdleWalkArray, mWalkRunArray;
// Finite state machine.
enum Animation
{
ANIM_IDLE,
ANIM_IDLE_WALK,
ANIM_WALK,
ANIM_WALK_RUN,
ANIM_RUN,
NUM_STATES
};
void ContinueIdleWalk ();
void ContinueWalkRun ();
void ContinueRunWalk ();
void ContinueWalkIdle ();
void TransitionIdleToIdleWalk ();
void TransitionIdleWalkToWalk ();
void TransitionWalkToWalkRun ();
void TransitionWalkRunToRun ();
void TransitionRunToRunWalk ();
void TransitionRunWalkToWalk ();
void TransitionWalkToWalkIdle ();
void TransitionWalkIdleToIdle ();
Animation mState;
int mCount, mCountMax[NUM_STATES];
float mWeight, mDeltaWeight0, mDeltaWeight1;
};
#include "BipedManager.inl"
#endif
|