# 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  

transform.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 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_TRANSFORM_H
00027 #define NL_TRANSFORM_H
00028 
00029 #include "3d/mot.h"
00030 #include "3d/hrc_trav.h"
00031 #include "3d/track.h"
00032 #include "3d/transformable.h"
00033 #include "3d/animated_value.h"
00034 #include "3d/channel_mixer.h"
00035 #include "nel/misc/matrix.h"
00036 #include "nel/misc/rgba.h"
00037 #include "3d/light_contribution.h"
00038 #include "3d/lighting_manager.h"
00039 
00040 // include base observers
00041 #include "3d/base_clip_obs.h"
00042 #include "3d/base_anim_detail_obs.h"
00043 #include "3d/base_light_obs.h"
00044 #include "3d/base_render_obs.h"
00045 
00046 
00047 namespace       NLMISC
00048 {
00049         class   CAABBox;
00050 };
00051 
00052 
00053 namespace       NL3D
00054 {
00055 
00056 using NLMISC::CRGBA;
00057 
00058 
00059 using NLMISC::CVector;
00060 using NLMISC::CPlane;
00061 using NLMISC::CMatrix;
00062 
00063 
00064 class   CTransformHrcObs;
00065 class   CTransformClipObs;
00066 class   CTransformLightObs;
00067 class   CSkeletonModel;
00068 class   CSkeletonModelAnimDetailObs;
00069 class   CSkeletonModelRenderObs;
00070 class   CInstanceGroup;
00071 class   ILogicInfo;
00072 
00073 // ***************************************************************************
00074 // ClassIds.
00075 const NLMISC::CClassId          TransformId=NLMISC::CClassId(0x174750cb, 0xf952024);
00076 
00077 
00078 // ***************************************************************************
00101 class CTransform : public IModel, public ITransformable
00102 {
00103 public:
00105         static  void    registerBasic();
00106 
00107 public:
00108 
00113         void                    setTransparency(bool v) { setStateFlag(IsTransparent, v); }
00114         void                    setOpacity(bool v) { setStateFlag(IsOpaque, v); }
00115         // return a non-zero value if true
00116         uint32                  isOpaque() { return getStateFlag(IsOpaque); }
00117         uint32                  isTransparent() { return getStateFlag(IsTransparent); }
00118 
00119 
00127         void                    setOrderingLayer(uint layer) { _OrderingLayer = layer; }
00128 
00130         uint                    getOrderingLayer() const { return _OrderingLayer; }
00131 
00133         void                    hide();
00135         void                    show();
00137         void                    heritVisibility();
00139         CHrcTrav::TVisibility   getVisibility() {return Visibility;}
00141         CSkeletonModel*                 getSkeletonModel () const {return _FatherSkeletonModel;}
00142 
00143 
00145         // @{
00147         virtual ITrack* getDefaultTrack (uint valueId);
00151         virtual void    registerToChannelMixer(CChannelMixer *chanMixer, const std::string &prefix);
00152         // @}
00153 
00158         void                    setChannelMixerOwnerShip(bool enable = true)    { setStateFlag(IsDeleteChannelMixer, enable); }
00159         bool                    getChannelMixerOwnerShip() const { return getStateFlag(IsDeleteChannelMixer)!=0; }
00160           
00161 
00169         void                    freeze();
00170         void                    setDontUnfreezeChildren(bool val);
00171 
00172 
00187         void                    freezeHRC();
00188 
00189 
00192         void                    unfreezeHRC();
00193 
00194 
00197         uint32                  isQuadGridClipEnabled() const {return getStateFlag(QuadGridClipEnabled);}
00198 
00202         const CMatrix&  getWorldMatrix();
00203 
00207         bool                    getLastClippedState() const;
00208 
00209 
00210 
00211         void                            setClusterSystem (CInstanceGroup *pIG) { _ClusterSystem = pIG; }
00212         CInstanceGroup*         getClusterSystem () { return _ClusterSystem; }
00213 
00214 
00216         // @{
00222         void                            resetLighting();
00223 
00229         uint32                          isLightable() const {return getStateFlag(IsFinalLightable);}
00230 
00235         void                            setUserLightable(bool enable);
00236 
00239         bool                            getUserLightable() const {return getStateFlag(IsUserLightable)!=0;}
00240 
00245         void                            freezeStaticLightSetup(CPointLight *pointLight[NL3D_MAX_LIGHT_CONTRIBUTION], 
00246                 uint numPointLights, uint8 sunContribution, CPointLight *frozenAmbientlight);
00247 
00252         void                            unfreezeStaticLightSetup();
00253 
00257         uint32                          isBigLightable() const {return getStateFlag(IsBigLightable);}
00258 
00259         // @}
00260 
00261 
00265         void                            setLogicInfo(ILogicInfo *logicInfo) {_LogicInfo= logicInfo;}
00266 
00267 
00270         virtual void            getAABBox(NLMISC::CAABBox &bbox) const;
00271 
00272 
00274         // @{
00275 
00285         void                            setLoadBalancingGroup(const std::string &group);
00286 
00289         const std::string       &getLoadBalancingGroup() const;
00290 
00291         // @}
00292 
00293 
00295         // @{
00297         uint32                          isSkeleton() const {return getStateFlag(IsSkeleton);}
00299         uint32                          isSkinned() const {return getStateFlag(IsSkinned);}
00300         // @}
00301 
00302 
00304         // @{
00305 
00310         void                            setMeanColor(CRGBA color);
00311 
00313         CRGBA                           getMeanColor() const {return _MeanColor;}
00314 
00316         uint32                          isAnimDetailable() const {return getStateFlag(IsAnimDetailable);}
00318         uint32                          isLoadBalancable() const {return getStateFlag(IsLoadBalancable);}
00320         uint32                          isRenderable() const {return getStateFlag(IsRenderable);}
00321 
00323         uint32                          isMeshBaseInstance() const {return getStateFlag(IsMeshBaseInstance);}
00324 
00325         // @}
00326 
00327 
00328 // ********
00329 private:
00330         // Add our own dirty states.
00331         enum    TDirty
00332         {
00333                 TransformDirty= IModel::Last,   // The matrix or the visibility state is modified.
00334                 Last
00335         };
00336 
00337 private:
00338         CHrcTrav::TVisibility   Visibility;
00339 
00340         static  CTrackDefaultVector             DefaultPos;
00341         static  CTrackDefaultVector             DefaultPivot;
00342         static  CTrackDefaultVector             DefaultRotEuler;
00343         static  CTrackDefaultQuat               DefaultRotQuat;
00344         static  CTrackDefaultVector             DefaultScale;
00345 
00346         void    foulTransform()
00347         {
00348                 IModel::foul(TransformDirty);
00349         }
00350 
00351 protected:
00353         CTransform();
00355         virtual ~CTransform();
00356 
00358         virtual void    update();
00359 
00361         virtual void    initModel();
00362 
00364         // @{
00365 
00367         virtual bool                    isSkinnable() const {return false;}
00372         virtual void                    setApplySkin(bool state);
00377         virtual const std::vector<sint32>       *getSkinBoneUsage() const {return NULL;}
00383         virtual void                    renderSkin(float alphaMRM) {}
00384 
00385 
00390         virtual bool                    supportSkinGrouping() const {return false;}
00394         virtual sint                    renderSkinGroupGeom(float alphaMRM, uint remainingVertices, uint8 *dest) {return 0;}
00398         virtual void                    renderSkinGroupPrimitives(uint baseVertex) {}
00399 
00400 
00401         // The SkeletonModel, root of us (skinning or sticked object). NULL , if normal mode.
00402         CSkeletonModel  *_FatherSkeletonModel;
00403         // If sticked object, id of the bone in the _FatherSkeletonModel.
00404         uint                    _FatherBoneId;
00405 
00406         // @}
00407 
00409         // @{
00410 
00412         CLightContribution              _LightContribution;
00413 
00415         uint32                                  isNeedUpdateLighting() const {return getStateFlag(IsNeedUpdateLighting);}
00417         uint32                                  isNeedUpdateFrozenStaticLightSetup() const {return getStateFlag(IsNeedUpdateFrozenStaticLightSetup);}
00418 
00420         CLightingManager::CQGItLightedModel             _LightedModelIt;
00421 
00422         // @}
00423 
00424 
00427         CChannelMixer                   *getChannelMixer() const {return _ChannelMixer;}
00428 
00429 
00431         // @{
00432 
00434         void                            setIsLightable(bool val);
00440         void                            setIsRenderable(bool val);
00442         void                            setIsBigLightable(bool val);
00444         void                            setIsSkeleton(bool val);
00448         void                            setIsForceAnimDetail(bool val);
00450         void                            setIsLoadbalancable(bool val);
00451 
00453         void                            setIsMeshBaseInstance(bool val) {setStateFlag(IsMeshBaseInstance, val);}
00454 
00455         // @}
00456 
00458         bool                            getShowWhenLODSticked() const { return _ForceCLodSticked; }
00459 private:
00460         static IModel   *creator() {return new CTransform;}
00461         friend class    CTransformHrcObs;
00462         friend class    CTransformClipObs;
00463         friend class    CTransformLightObs;
00464         friend class    CTransformAnimDetailObs;
00465         friend class    CSkeletonModel;
00466         friend class    CSkeletonModelAnimDetailObs;
00467         friend class    CSkeletonModelRenderObs;
00468 
00474         void                    updateWorldMatrixFromFather();
00475 
00476 
00477         // For anim detail.
00478         NLMISC::CRefPtr<CChannelMixer>          _ChannelMixer;
00479 
00480         // Last date of ITransformable matrix.
00481         uint64                  _LastTransformableMatrixDate;
00482 
00483         CInstanceGroup* _ClusterSystem;
00484 
00485 
00486         enum    TFreezeHRCState { FreezeHRCStateDisabled=0, FreezeHRCStateRequest, FreezeHRCStateReady, FreezeHRCStateEnabled};
00487         TFreezeHRCState                 _FreezeHRCState;
00488 
00489         uint8                           _OrderingLayer;
00490 
00491         // For stickObjectEx(). with forceCLod==true
00492         bool                            _ForceCLodSticked;
00493 
00494 
00496         ILogicInfo                      *_LogicInfo;
00497 
00498 
00500         CRGBA                           _MeanColor;
00501 
00502 
00504         // @{
00505 
00507         enum    TState  {
00508                 // Post-clipping Traversal flags. If set, then the object is inserted into traversal list.
00509                 IsAnimDetailable=               0x0001,
00510                 IsLoadBalancable=               0x0002,
00511                 IsLightable=                    0x0004,
00512                 IsRenderable=                   0x0008,
00513                 // Transparency Flags.
00514                 IsTransparent=                  0x0010,
00515                 IsOpaque=                               0x0020,
00516                 // For fast clip.
00517                 QuadGridClipEnabled=    0x0040,
00518                 // Lighting.
00519                 IsUserLightable=                0x0080,
00520                 IsFinalLightable=               0x0100,         // IsLightable && IsUserLightable
00521                 IsBigLightable=                 0x0200,
00522                 IsNeedUpdateLighting=   0x0400,
00523                 IsNeedUpdateFrozenStaticLightSetup= 
00524                                                                 0x0800,
00525                 // Skinning
00526                 IsSkeleton=                             0x1000,         // set if the model is a skeleton (faster than dynamic_cast)
00527                 IsSkinned=                              0x2000,         // true if the model is isSkinnable() and if currently skinned
00528                 // Misc
00529                 IsDeleteChannelMixer=   0x4000,
00530                 IsForceAnimDetail=              0x8000,
00531                 IsMeshBaseInstance=             0x10000,
00532 
00533                 // NB: may continue on >=0x20000
00534         };
00535 
00537         uint32                          _StateFlags;
00538 
00540         void                            setStateFlag(uint32 mask, bool val)
00541         {
00542                 // reset the state.
00543                 _StateFlags&= ~mask;
00544                 // set the state
00545                 _StateFlags|= ( 0- ((uint32)val) ) & mask;
00546         }
00547 
00549         uint32                          getStateFlag(uint32 mask) const
00550         {
00551                 return _StateFlags&mask;
00552         }
00553 
00554         // @}
00555 
00556 protected:
00557         // shortcut to the HrcObs.
00558         CTransformHrcObs                        *_HrcObs;
00559         // shortcut to the ClipObs.
00560         CTransformClipObs                       *_ClipObs;
00561         // shortcut to the LightObs.
00562         CTransformLightObs                      *_LightObs;
00563 
00564 
00565 };
00566 
00567 
00568 // ***************************************************************************
00579 class   CTransformHrcObs : public IBaseHrcObs
00580 {
00581 public:
00582         CTransformHrcObs()
00583         {
00584                 Frozen = false;
00585                 DontUnfreezeChildren = false;
00586                 _AncestorSkeletonModel= NULL;
00587                 ClipLinkedInSonsOfAncestorSkeletonModelGroup= false;
00588         }
00589 
00590         virtual void    update();
00591 
00593 
00594 
00595         void    updateWorld(IBaseHrcObs *caller);
00597 
00598 
00600 
00601 
00602         virtual void    traverse(IObs *caller);
00604         static IObs     *creator() {return new CTransformHrcObs;}
00605 
00606 
00607 public:
00608         bool    Frozen;
00609         bool    DontUnfreezeChildren; // Usefull when cluster system move to not test instance again
00610 
00611         bool    ClipLinkedInSonsOfAncestorSkeletonModelGroup;
00612         // !NULL if any skeleton is an ancestor in hierarchy. Updated at each Hrc traversal!!
00613         CSkeletonModel  *_AncestorSkeletonModel;
00614 
00615 private:
00616         // according to _AncestorSkeletonModel, link clipTrav.
00617         void    updateClipTravForAncestorSkeleton();
00618 };
00619 
00620 
00621 // ***************************************************************************
00633 class   CTransformClipObs : public IBaseClipObs
00634 {
00635 
00636 public:
00637 
00638         sint64 Date;
00639 
00640 public:
00641 
00642         CTransformClipObs() : Date(0) {}
00643 
00645         virtual bool    clip(IBaseClipObs *caller) 
00646         {
00647                 return true;
00648         }
00649 
00659         virtual void    traverse(IObs *caller);
00660 
00661         static IObs     *creator() {return new CTransformClipObs;}
00662 };
00663 
00664 
00665 // ***************************************************************************
00676 class   CTransformAnimDetailObs : public IBaseAnimDetailObs
00677 {
00678 public:
00679 
00681         void                    updateWorldMatrixFromFather();
00685         void                    traverseWithoutUpdateWorldMatrix(IObs *caller);
00686 
00688         virtual void    traverse(IObs *caller);
00689 
00690         static IObs     *creator() {return new CTransformAnimDetailObs;}
00691 };
00692 
00693 // ***************************************************************************
00700 class CTransformRenderObs : public IBaseRenderObs
00701 {
00702 public:
00707         virtual void    traverse(IObs *caller)
00708         {
00709         }
00710 
00711         static IObs     *creator() {return new CTransformRenderObs;}
00712 
00713 };
00714 
00715 
00716 // ***************************************************************************
00723 class CTransformLightObs : public IBaseLightObs
00724 {
00725 public:
00726 
00734         virtual void    traverse(IObs *caller);
00735 
00736 
00737         static IObs     *creator() {return new CTransformLightObs;}
00738 
00739 };
00740 
00741 
00742 } // namespace NL3D
00743 
00744 
00745 #endif // NL_TRANSFORM_H
00746 
00747 /* End of transform.h */