# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

channel_mixer.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_CHANNEL_MIXER_H
00027 #define NL_CHANNEL_MIXER_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/debug.h"
00031 #include "nel/misc/smart_ptr.h"
00032 #include "nel/3d/animation_time.h"
00033 #include "3d/animation_set.h"
00034 #include <map>
00035 #include <vector>
00036 
00037 namespace NL3D 
00038 {
00039 
00040 class CAnimation;
00041 class IAnimatable;
00042 class IAnimatedValue;
00043 class ITrack;
00044 class CAnimationSet;
00045 
00064 class CChannelMixer : public NLMISC::CRefCount
00065 {
00066 public:
00067 
00069 
00070         enum 
00071         { 
00073                 NumAnimationSlot=8 
00074         };
00075 
00076 private:
00077 
00079 
00081         class CSlot
00082         {
00083                 friend class CChannelMixer;
00084 
00086                 CSlot ()
00087                 {
00088                         // Not modified
00089                         _Dirt=false;
00090 
00091                         // default is 1.
00092                         _Weight= 1.f;
00093 
00094                         // Set it empty
00095                         empty ();
00096                 }
00097 
00099                 void empty ()
00100                 {
00101                         _Animation=NULL;
00102                         _SkeletonWeight=NULL;
00103                         _InvertedSkeletonWeight=false;
00104                 }
00105 
00107                 bool isEmpty ()
00108                 {
00109                         return _Animation==NULL;
00110                 }
00111 
00112         private:
00114                 const CAnimation*       _Animation;
00115 
00117                 const CSkeletonWeight*  _SkeletonWeight;
00118 
00120                 bool                            _InvertedSkeletonWeight;
00121 
00123                 TAnimationTime          _Time;
00124 
00131                 float                           _Weight;
00132 
00134                 bool                            _Dirt;
00135         };
00136 
00145         class CChannel
00146         {
00147                 friend class CChannelMixer;
00148         public:
00149                 enum    {EnableUserFlag= 1, EnableLodFlag= 2, EnableAllFlag= 3};
00150 
00151         public:
00153                 CChannel ()
00154                 {
00155                         // not in the list
00156                         _InTheList=false;
00157                         // enabled by default.
00158                         _EnableFlags= EnableAllFlag;
00159                 }
00160         private:
00162                 bool                            _InTheList;
00163 
00165                 bool                            _Detail;
00166 
00168                 uint8                           _EnableFlags;
00169 
00171                 bool                            _IsQuat;
00172 
00173 
00175                 std::string                     _ChannelName;
00176 
00178                 IAnimatable*            _Object;
00179 
00181                 IAnimatedValue*         _Value;
00182 
00184                 uint32                          _ValueId;
00185 
00187                 uint32                          _OwnerValueId;
00188 
00190                 const ITrack*           _DefaultTracks;
00191 
00196                 const ITrack*           _Tracks[NumAnimationSlot];
00197 
00204                 float                           _Weights[NumAnimationSlot];
00205 
00212                 CChannel*                       _Next;
00213 
00214         };
00215 public:
00217         CChannelMixer();
00218 
00220 
00225         void setAnimationSet (const CAnimationSet* animationSet);
00226 
00231         const CAnimationSet* getAnimationSet () const;
00232 
00248         void eval (bool detail, uint64 evalDetailDate=0);
00249 
00251 
00269         sint addChannel (const std::string& channelName, IAnimatable* animatable, IAnimatedValue* value, ITrack* defaultValue, uint32 valueId, uint32 ownerValueId, bool detail);
00270 
00272         void resetChannels ();
00273 
00274 
00279         void enableChannel (uint channelId, bool enable);
00280 
00284         bool isChannelEnabled (uint channelId) const;
00285 
00291         void lodEnableChannel (uint channelId, bool enable);
00292 
00296         bool isChannelLodEnabled (uint channelId) const;
00297 
00298 
00300 
00314         void setSlotAnimation (uint slot, uint animation);
00315 
00317         const CAnimation        *getSlotAnimation(uint slot) const;
00318 
00331         void setSlotTime (uint slot, TAnimationTime time)
00332         {
00333                 // Check alot arg
00334                 nlassert (slot<NumAnimationSlot);
00335 
00336                 // Set the time
00337                 _SlotArray[slot]._Time=time;
00338         }
00339 
00352         void setSlotWeight (uint slot, float weight)
00353         {
00354                 // Check alot arg
00355                 nlassert (slot<NumAnimationSlot);
00356 
00357                 // Set the time
00358                 _SlotArray[slot]._Weight=weight;
00359         }
00360 
00372         void emptySlot (uint slot);
00373 
00382         void resetSlots ();
00383 
00394         void applySkeletonWeight (uint slot, uint skeleton, bool invert=false);
00395 
00403         void resetSkeletonWeight (uint slot);
00404 
00406         void resetEvalDetailDate();
00407 
00408 private:
00409         
00411         
00413         void cleanAll ();
00414         
00416         void dirtAll ();
00417 
00419         void refreshList ();
00420 
00421         // The slot array
00422         CSlot                                                   _SlotArray[NumAnimationSlot];
00423 
00424         // The animation set
00425         const CAnimationSet*                    _AnimationSet;
00426 
00427         // The set of CChannel infos. Only channels added by addChannel are present.
00428         std::map<uint, CChannel>                _Channels;
00429 
00430         // The first Global channel. If NULL, no channel to animate.  (animed in eval(false))
00431         CChannel*                                               _FirstChannelGlobal;
00432 
00433         // The first dertail channel. If NULL, no channel to animate.  (animed in eval(true))
00434         CChannel*                                               _FirstChannelDetail;
00435 
00436         // last date of evalDetail().
00437         sint64                                                  _LastEvalDetailDate;
00438 
00439         // The channels list is dirty if true.
00440         bool                                                    _Dirt;
00441 
00442         // true if must update animateList. (set in refreshList())
00443         bool                                                    _ListToEvalDirt;
00444 
00445         // Raw lists of channels to animate, acording to _EnableFlags
00446         std::vector<CChannel*>                  _GlobalListToEval;
00447         std::vector<CChannel*>                  _DetailListToEval;
00448 
00450         void                                                    refreshListToEval ();
00451 
00452 
00453 };
00454 
00455 
00456 } // NL3D
00457 
00458 
00459 #endif // NL_CHANNEL_MIXER_H
00460 
00461 /* End of channel_mixer.h */