- Cal3D 0.11 API Reference -

mixer.h

00001 //****************************************************************************//
00002 // mixer.h                                                                    //
00003 // Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger                       //
00004 // Copyright (C) 2004 Mekensleep <licensing@mekensleep.com>                   //
00005 //****************************************************************************//
00006 // This library is free software; you can redistribute it and/or modify it    //
00007 // under the terms of the GNU Lesser General Public License as published by   //
00008 // the Free Software Foundation; either version 2.1 of the License, or (at    //
00009 // your option) any later version.                                            //
00010 //****************************************************************************//
00011 
00012 #ifndef CAL_MIXER_H
00013 #define CAL_MIXER_H
00014 
00015 //****************************************************************************//
00016 // Includes                                                                   //
00017 //****************************************************************************//
00018 
00019 #include "cal3d/global.h"
00020 #include "cal3d/animation.h"
00021 #include "cal3d/quaternion.h"
00022 
00023 //****************************************************************************//
00024 // Forward declarations                                                       //
00025 //****************************************************************************//
00026 
00027 class CalModel;
00028 class CalAnimation;
00029 class CalAnimationAction;
00030 class CalAnimationCycle;
00031 
00032 struct CalMixerManualAnimationAttributes {
00033   bool on_;
00034   float time_;
00035   float weight_;
00036   float scale_;
00037   float rampValue_;
00038   CalAnimation::CompositionFunction compositionFunction_;
00039 };
00040 
00041 enum CalMixerBoneAdjustmentFlag {
00042   CalMixerBoneAdjustmentFlagPosRot = 1,
00043   CalMixerBoneAdjustmentFlagMeshScale = 2
00044 };
00045 
00046 
00047 struct CalMixerBoneAdjustment {
00048 
00049   // What parts of the adjustment are to be applied?
00050   unsigned int flags_;
00051 
00052   // Relative to the parent frame of reference.
00053   CalVector localPos_;
00054   CalQuaternion localOri_;
00055 
00056   // Scales X, Y, and Z of mesh by these parameters.  The scale parameters are with
00057   // respect to the absolute coordinate space, e.g., Z is up in 3dMax, as opposed
00058   // to the local coordinate space of the bone.
00059   CalVector meshScaleAbsolute_;
00060 
00061   // The adjustment is a highest priority "replace" animation for the bone.  Lower priority
00062   // animations for the bone, including other replace animations, will be attenuated by 1 - rampValue.
00063   float rampValue_;
00064 };
00065 
00066 
00067 struct CalMixerBoneAdjustmentAndBoneId {
00068   CalMixerBoneAdjustment boneAdjustment_;
00069   int boneId_;
00070 };
00071 
00072 // Total number of bone adjustments per mixer.
00073 #define CalMixerBoneAdjustmentsMax ( 20 ) // Arbitrary.
00074 
00075 
00076 /*****************************************************************************/
00140 class CAL3D_API CalAbstractMixer
00141 {
00142 public:
00143   CalAbstractMixer() {}
00144   virtual ~CalAbstractMixer() {}
00145 
00146   /*****************************************************************************/
00154   virtual bool isDefaultMixer() const { return false; }
00155 
00156   /*****************************************************************************/
00173   virtual void updateAnimation(float deltaTime) = 0;
00174 
00175   /*****************************************************************************/
00191   virtual void updateSkeleton() = 0;
00192 };
00193 
00194 
00195 class CAL3D_API CalMixer : public CalAbstractMixer
00196 {
00197 public:
00198   CalMixer(CalModel* pModel);
00199   virtual ~CalMixer();
00200 
00201   virtual bool isDefaultMixer() const { return true; }
00202   bool blendCycle(int id, float weight, float delay);
00203   bool clearCycle(int id, float delay);
00204   bool executeAction(int id, float delayIn, float delayOut, float weightTarget = 1.0f, bool autoLock=false);
00205   bool removeAction(int id);
00206   virtual void updateAnimation(float deltaTime);
00207   virtual void updateSkeleton();
00208   float getAnimationTime() const;
00209   float getAnimationDuration() const;
00210   void setAnimationTime(float animationTime);
00211   void setTimeFactor(float timeFactor);
00212   float getTimeFactor() const;
00213   CalModel *getCalModel();
00214   const CalModel *getCalModel() const;
00215   std::vector<CalAnimation *> &getAnimationVector();
00216   const std::vector<CalAnimation *> &getAnimationVector() const;
00217   std::list<CalAnimationAction *> &getAnimationActionList();
00218   const std::list<CalAnimationAction *> &getAnimationActionList() const;
00219   std::list<CalAnimationCycle *> &getAnimationCycle();
00220   const std::list<CalAnimationCycle *> &getAnimationCycle() const;
00221   bool actionOn( int coreAnimationId );
00222   bool stopAction( int coreAnimationId );
00223   bool addManualAnimation( int coreAnimationId );
00224   bool removeManualAnimation( int coreAnimationId );
00225   bool setManualAnimationOn( int coreAnimationId, bool );
00226   bool setManualAnimationTime( int coreAnimationId, float seconds );
00227   bool setManualAnimationWeight( int coreAnimationId, float );
00228   bool setManualAnimationScale( int coreAnimationId, float p );
00229   bool setManualAnimationRampValue( int coreAnimationId, float p );
00230   bool setManualAnimationCompositionFunction( int coreAnimationId, CalAnimation::CompositionFunction p );
00231   bool setManualAnimationAttributes( int coreAnimationId, CalMixerManualAnimationAttributes const & p );
00232   bool animationDuration( int coreAnimationId, float * result );
00233   bool addBoneAdjustment( int boneId, CalMixerBoneAdjustment const & );
00234   bool removeBoneAdjustment( int boneId );
00235   void removeAllBoneAdjustments();
00236   unsigned int numActiveOneShotAnimations();
00237 protected:
00238   CalModel                       *m_pModel;
00239   std::vector<CalAnimation *>     m_vectorAnimation;
00240   std::list<CalAnimationAction *> m_listAnimationAction;
00241   std::list<CalAnimationCycle *>  m_listAnimationCycle;
00242   float                           m_animationTime;
00243   float                           m_animationDuration;
00244   float                           m_timeFactor;
00245   unsigned int m_numBoneAdjustments;
00246   CalMixerBoneAdjustmentAndBoneId m_boneAdjustmentAndBoneIdArray[ CalMixerBoneAdjustmentsMax ];
00247 
00248 public: // private:
00249 
00250   CalAnimationAction * animationActionFromCoreAnimationId( int coreAnimationId );
00251   CalAnimationAction * newAnimationAction( int coreAnimationId );
00252   bool setManualAnimationCompositionFunction( CalAnimationAction *, CalAnimation::CompositionFunction p );
00253   bool setManualAnimationRampValue( CalAnimationAction *, float p );
00254   bool setManualAnimationScale( CalAnimationAction *, float p );
00255   bool setManualAnimationWeight( CalAnimationAction *, float p );
00256   bool setManualAnimationTime( CalAnimationAction *, float p );
00257   bool setManualAnimationOn( CalAnimationAction *, bool p );
00258   void applyBoneAdjustments();
00259 };
00260 
00261 
00262 #endif
00263 
00264 //****************************************************************************//

Generated by The Cal3D Team with Doxygen 1.7.3