Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HBhvUtility.h
Go to the documentation of this file.
00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc.
00002 //
00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
00004 // and considered a trade secret as defined under civil and criminal statutes.
00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
00006 // unauthorized use or misappropriation of its trade secrets.  Use of this information
00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
00009 
00010 //"Parts of HQuat Copyright (C) Jason Shankel, 2000"
00011 //
00012 //
00013 
00018 #ifndef _H_HBhvUtility_H
00019 #define _H_HBhvUtility_H
00020 
00021 #ifdef H_PACK_8
00022 #pragma pack(push)
00023 #pragma pack(8)
00024 #endif
00025 
00026 #include "HTools.h"
00027 
00028 #ifndef SWIG
00029 #include "BStream.h"
00030 #endif
00031 
00032 class HUtilityXMLTag;
00033 class HUtilityTextParser;
00034 class HBhvTimeline;
00035 class HBaseModel;
00036 class HStreamFileToolkit;
00037 class HBaseView;
00038 class HBaseModel;
00039 class HBhvAnimation;
00040 
00041 #define         BHV_MAX_NAME_LENGTH     256     //!< Maximum Length of "Names" in animations
00042 #define         BHV_MAX_VERSION_LENGTH  256         //!< Maximum Length of "Version" string
00043 #define         BHV_MAX_VENDOR_LENGTH   4096            //!< Maximum Length of "Vendor" string
00044 #define         BHV_MAX_TYPE_LENGTH     4096        //!< Maximum Length of Animation Type string
00045 
00046 
00048 enum HANIKeyframeType {
00049     HANIChannel,            
00050     HANIRotation,           
00051     HANIString,             
00052     HANI3String             
00053 };
00054 
00055 
00057 enum HANIChannelType {
00058     HANILinear,             
00059     HANIHermiteSpline,      
00060     HANIBezierSpline,       
00061     HANIFollowPath,         
00062     HANIDiscrete            
00063 };
00064 
00065 
00067 enum HANIRotationType {     
00068     HANIAxisRotation,       
00069     HANIQuatSlerpRotation,  
00070     HANIQuatSquadRotation,  
00071     HANIEulerRotation       
00072 };
00073 
00074 
00075 
00076                     
00078 
00083 class MVO_API HQuat
00084 {
00085 public:
00086     float x;        
00087     float y;        
00088     float z;        
00089     float w;        
00090     const HQuat &Normalize();  
00092     HQuat() { x=0.0f;y=0.0f;z=0.0f; w=0;};
00094     HQuat(float X,float Y,float Z, float W) { x=X;y=Y;z=Z; w=W;};
00096     HQuat(HQuat const *p) { x=p->x;y=p->y;z=p->z; w=p->w;};
00098     HQuat(const HQuat &p) { x=p.x;y=p.y;z=p.z; w=p.w;};
00099     
00101     void Set(float X,float Y,float Z, float W) { x=X;y=Y;z=Z; w=W; };
00102 
00108     HQuat operator *(const HQuat &q2) const
00109     {
00110         
00111         return HQuat(y*q2.z - z*q2.y + w*q2.x + x*q2.w,
00112                         z*q2.x - x*q2.z + w*q2.y + y*q2.w,
00113                         x*q2.y - y*q2.x + w*q2.z + z*q2.w,
00114                         w*q2.w - x*q2.x - y*q2.y - z*q2.z);
00115     }
00116 
00122     HQuat operator *(float v) const
00123     {
00124         return HQuat(x*v, y*v, z*v, w*v);
00125     }
00126 
00133     friend HQuat operator* (float v, const HQuat& q)
00134     {
00135         return HQuat(v*q.x,v*q.y,v*q.z, v*q.w);
00136     }
00137 
00143     HQuat operator /(float v) const
00144     {
00145         return HQuat(x/v, y/v, z/v, w/v);
00146     }
00147         HQuat operator -(const HQuat &q2) const
00153     {
00154         return HQuat(x-q2.x, y-q2.y, z-q2.z, w-q2.w);
00155     }
00156 
00162     HQuat operator +(const HQuat &q2) const
00163     {
00164         return HQuat(x+q2.x, y+q2.y, z+q2.z, w+q2.w);
00165     }
00166     
00173     static HQuat Qlog(const HQuat &q);
00174  
00179     void ToMatrix(float matrix[16]);
00180     
00181 
00187     static HQuat Qexp(const HQuat &q);  
00195     static HQuat Qlerp(const HQuat &q1,const HQuat &q2,float fraction);
00203     static HQuat Qslerp(const HQuat &q1,const HQuat &q2,float fraction);
00212     static HQuat QslerpNoInvert(const HQuat &q1,const HQuat &q2,float fraction);
00221     static HQuat QslerpNoInvertExtraSpins(const HQuat &q1,const HQuat &q2,float fraction, int ExtraSpins);
00231     static HQuat Qsquad(const HQuat &q1,const HQuat &q2,const HQuat &a,const HQuat &b,float fraction);
00239     static HQuat Qspline(const HQuat &qnm1,const HQuat &qn,const HQuat &qnp1);
00244     static HQuat MatrixToQuaternion(float matrix[]);
00245 
00246 };
00247 
00248  
00249 
00251 
00257 class MVO_API HKeyframe
00258 {
00259 public:
00263     HKeyframe()
00264     {
00265         m_bConstant = false;
00266         m_bEaseInOut = false;
00267     }
00268     virtual ~HKeyframe() {};
00269 
00275     virtual HKeyframe *Clone() { 
00276         HKeyframe *p = new HKeyframe;
00277         *p =  *this;
00278         return p;
00279     }
00280 
00284     virtual void Serialize(HUtilityXMLTag *xmlgen) {
00285         UNREFERENCED(xmlgen);
00286     }
00287  
00293     virtual void SetConstant(bool constant) { m_bConstant = constant; }
00299     virtual void SetEaseInOut(bool easeinout) { m_bEaseInOut = easeinout; }
00301     virtual void SetRelative(bool relative) { m_bRelative = relative; }
00302   
00303     HANIKeyframeType    m_type;         
00304     bool                m_bConstant;    
00305     bool                m_bRelative;    
00306     bool                m_bEaseInOut;   
00307 };
00308 
00309 
00311 
00314 class MVO_API HKeyframeChannel : public HKeyframe
00315 {
00316 public:
00317 
00321     HKeyframeChannel()
00322     {
00323         m_cp.Set(0.0f,0.0f,0.0f);
00324         m_type =  HANIChannel;
00325     }
00326     virtual ~HKeyframeChannel() {};
00327 
00333     virtual HKeyframe *Clone () 
00334     {
00335         HKeyframeChannel *p= new HKeyframeChannel;
00336         *p = *this;
00337         return p;
00338     }
00339 
00348     virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res) {
00349         UNREFERENCED(posarray);
00350         UNREFERENCED(keyframe);
00351         UNREFERENCED(fraction);
00352         UNREFERENCED(length);
00353         UNREFERENCED(res);
00354     }
00355     
00356     HPoint          m_cp;                   
00357     HANIChannelType m_channeltype;          
00358 };
00359 
00360 
00361 
00362  
00364 class MVO_API HKeyframeChannelLinear : public HKeyframeChannel
00365 {
00366 public:
00367  
00371     HKeyframeChannelLinear(float x=0, float y=0,  float z=0) : HKeyframeChannel()
00372     {
00373         m_channeltype = HANILinear;
00374         m_cp.Set(x,y,z);
00375     }
00376     virtual ~HKeyframeChannelLinear() {};
00377 
00383     virtual HKeyframe *Clone () 
00384     {
00385         HKeyframeChannelLinear *p= new HKeyframeChannelLinear;
00386         *p = *this;
00387         return p;
00388     }
00389  
00398     virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res);
00399 
00403     virtual void Serialize(HUtilityXMLTag *xmlgen);
00404 
00405 };
00406 
00408 
00411 class MVO_API HKeyframeChannelDiscrete : public HKeyframeChannel
00412 {
00413 public:
00414  
00418     HKeyframeChannelDiscrete(float x=0, float y=0, float z = 0) : HKeyframeChannel()
00419     {
00420         m_channeltype = HANIDiscrete;
00421         m_cp.Set(x,y,z);
00422 
00423     }
00424     virtual ~HKeyframeChannelDiscrete() {};
00425 
00431     virtual HKeyframe *Clone () 
00432     {
00433         HKeyframeChannelDiscrete *p= new HKeyframeChannelDiscrete;
00434         *p = *this;
00435         return p;
00436     }
00437 
00448     virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res);
00449 
00453     virtual void Serialize(HUtilityXMLTag *xmlgen);
00454  
00455 };
00456 
00457 
00458 
00460 
00462 class MVO_API HKeyframeChannelCurve : public HKeyframeChannel
00463 {
00464 public:
00465 
00469     HKeyframeChannelCurve(float x = 0, float y = 0, float z = 0) : HKeyframeChannel()
00470     {
00471         m_channeltype = HANIHermiteSpline;
00472         m_cp.Set(x,y,z);
00473 
00474     }
00475     virtual ~HKeyframeChannelCurve() {};
00476 
00482     virtual HKeyframe *Clone () 
00483     {
00484         HKeyframeChannelCurve *p= new HKeyframeChannelCurve;
00485         *p = *this;
00486         return p;
00487     }
00488 
00495     void CalculateCurveFactor(HBhvTimeline *timeline, int keyframe);
00496 
00505     void CalculateHermiteTangents(HPoint p0, HPoint p2, HPoint p3, float a = 0.5f); 
00506 
00514     HPoint InterpolateHermiteSpline(float fraction, HPoint p1, HPoint p2);
00515 
00516 //  HPoint InterpolateBezierSpline(float fraction, HPoint p2);
00517 
00518 
00523     void CalculateCurveLength(HPoint p2);
00524 
00530     void DrawTangents(HPoint p2);
00531 
00540     virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res);
00541 
00545     virtual void Serialize(HUtilityXMLTag *xmlgen);
00546     
00547     HPoint      m_tangent1;                     
00548     HPoint      m_tangent2;                     
00549     float       m_factor1;                      
00550     float       m_factor2;                      
00551     HPoint*     control_polygon;                
00552     float       ItemType;                       
00553     float       c;                              
00554     float       b;                              
00555     float       m_curvelength;                  
00557 };
00558 
00560 
00564 class MVO_API HKeyframeChannelFollowPath : public HKeyframeChannelCurve
00565 {
00566 
00567 public:
00568  
00572     HKeyframeChannelFollowPath() 
00573     {
00574         m_channeltype = HANIFollowPath;
00575         m_bLinear = false;
00576     }
00577     virtual ~HKeyframeChannelFollowPath() {};
00578 
00584     virtual HKeyframe *Clone () 
00585     {
00586         HKeyframeChannelFollowPath *p= new HKeyframeChannelFollowPath;
00587         *p = *this;
00588         return p;
00589     }
00590 
00599     virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res);
00600     virtual void Serialize(HUtilityXMLTag *xmlgen);
00601 
00602 //  virtual void Serialize(HUtilityXMLTag *xmlgen);
00603     float tmatrix[16];              
00604     float tmatrix2[16];             
00605     bool m_bLinear;
00606     bool m_bNoRotate;
00607 };
00608 
00609 
00610  
00611 
00613 class MVO_API HKeyframeRotation : public HKeyframe
00614 {
00615 public:
00616  
00620     HKeyframeRotation()
00621     {
00622         m_type = HANIRotation;
00623         m_bLinear = false;
00624     }
00625     virtual ~HKeyframeRotation() {};
00626 
00632     virtual HKeyframe *Clone () 
00633     {
00634         HKeyframeRotation *p= new HKeyframeRotation;
00635         *p = *this;
00636         return p;
00637     } 
00638 
00639     HANIRotationType m_rotationtype;            
00640     bool m_bLinear;                             
00642 };
00643 
00644 
00645 
00647 class MVO_API HKeyframeAxisRotation : public HKeyframeRotation
00648 {
00649 public:
00650 
00651 
00656     HKeyframeAxisRotation(float angle = 0)
00657     {
00658         m_rotationtype = HANIAxisRotation;
00659         m_angle = angle;
00660 
00661     }
00662     virtual ~HKeyframeAxisRotation() {};
00663 
00669     virtual HKeyframe *Clone () 
00670     {
00671         HKeyframeAxisRotation *p= new HKeyframeAxisRotation;
00672         *p = *this;
00673         return p;
00674 
00675     } 
00676 
00680     virtual void Serialize(HUtilityXMLTag *xmlgen);
00681 
00682     float m_angle;              
00683 };
00684 
00685 
00687 class MVO_API HKeyframeQuatSlerp : public HKeyframeRotation
00688 {
00689 public:
00690 
00694     HKeyframeQuatSlerp(float x = 0, float y = 0, float z = 0, float w = 0)
00695     {
00696         m_rotationtype = HANIQuatSlerpRotation;
00697         m_quat.Set(x,y,z,w);
00698     }
00699 
00700     virtual ~HKeyframeQuatSlerp() {};
00701  
00707     virtual HKeyframe *Clone () 
00708     {
00709         HKeyframeQuatSlerp *p= new HKeyframeQuatSlerp;
00710         *p = *this;
00711         return p;
00712     }   
00713     
00714     HQuat m_quat;           
00715 };
00716 
00717 
00718 
00719 
00721 class MVO_API HKeyframeQuatSquad : public HKeyframeRotation
00722 {
00723 public:
00724 
00725  
00729     HKeyframeQuatSquad(float x = 0, float y = 0, float z = 0, float w = 0)
00730     {
00731         m_rotationtype = HANIQuatSquadRotation;
00732         m_quat.Set(x,y,z,w);
00733         m_ExtraSpins = 0;
00734 
00735     }
00736     virtual ~HKeyframeQuatSquad() {};
00737 
00743     virtual HKeyframe *Clone () 
00744     {
00745         HKeyframeQuatSquad *p= new HKeyframeQuatSquad;
00746         *p = *this;
00747         return p;
00748     } 
00749 
00753     virtual void Serialize(HUtilityXMLTag *xmlgen);
00754 
00755     HQuat m_quat;           
00756     int m_ExtraSpins;   
00757 
00758 };
00759 
00760 
00762 class MVO_API HKeyframeMatrix : public HKeyframeRotation
00763 {
00764 public:
00765 
00766  
00770     HKeyframeMatrix(float matrix[] = 0)
00771     {
00772         m_rotationtype = HANIQuatSquadRotation;
00773 
00774         if (matrix)
00775         {       
00776         for (int i=0;i<16;i++)
00777             m_matrix[i] = matrix[i];
00778         }
00779  
00780     }
00781     virtual ~HKeyframeMatrix() {};
00782 
00788     virtual HKeyframe *Clone () 
00789     {
00790         HKeyframeMatrix *p= new HKeyframeMatrix;
00791         *p = *this;
00792         return p;
00793     } 
00794 
00798     virtual void Serialize(HUtilityXMLTag *xmlgen);
00799 
00800     float m_matrix[16];         
00801     int m_ExtraSpins;   
00802 
00803 };
00804 
00805 
00806 
00807 
00808 
00810 
00814 class MVO_API HKeyframeString : public HKeyframe
00815 {
00816 public:
00817     
00821     HKeyframeString();
00822     virtual ~HKeyframeString() {};
00823 
00829     virtual HKeyframe *Clone () 
00830     {
00831         HKeyframeString *p= new HKeyframeString;
00832         *p = *this;
00833         return p;
00834     }
00835 
00839     virtual void Serialize(HUtilityXMLTag *xmlgen);
00840 
00841     
00846     void SetTarget(const char *target);
00847 
00850     char * GetTarget() { return m_target; }
00851 
00852     char m_target[MVO_BUFFER_SIZE];         
00853     bool m_bDiscrete;
00854 
00855 };
00856 
00857 
00859 
00863 class MVO_API HKeyframe3String : public HKeyframe
00864 {
00865 public:
00866     
00870     HKeyframe3String();
00871     virtual ~HKeyframe3String() {};
00872 
00878     virtual HKeyframe *Clone () 
00879     {
00880         HKeyframe3String *p= new HKeyframe3String;
00881         *p = *this;
00882         return p;
00883     }
00884 
00888     virtual void Serialize(HUtilityXMLTag *xmlgen);
00889 
00890     
00895     void SetTarget(const char *t1, const char *t2, const char *t3);
00896 
00899     char * GetTarget1() { return m_t1; }
00900     char * GetTarget2() { return m_t2; }
00901     char * GetTarget3() { return m_t3; }
00902 
00903     char m_t1[255];         
00904     char m_t2[255];         
00905     char m_t3[255];         
00907 };
00908 
00909 
00910 
00911 
00912 
00914 
00918 class MVO_API ShellMorphInfo {
00919 public:
00920 
00924     ShellMorphInfo();
00925     struct vlist_s* arrays_list;            
00926     HC_KEY original_key;                    
00927     HC_KEY temp_key;                        
00929 };
00930 
00931 
00932 
00933 #ifndef SWIG
00934 
00935 class MVO_API TK_Bhv_XML : public TK_XML
00936 {
00937 
00938  
00939 public:
00940 
00945     TK_Bhv_XML(HBaseModel * model) : TK_XML() 
00946     { 
00947         m_pModel = model;
00948     }
00949 
00951     TK_Status   Interpret(BStreamFileToolkit &tk, ID_Key key, int variant);
00953     TK_Status   Execute (BStreamFileToolkit & tk);
00954 
00955 private:
00956     HBaseModel *    m_pModel;   
00957 };
00958 #endif
00959 
00960 
00961 
00963 class MVO_API HBhvUtility
00964 {
00965 public:
00966     
00972     static void GetQuatPoint(HUtilityTextParser *tp, HQuat &quat);
00973     static void GetMatrix(HUtilityTextParser *tp, float matrix[]);
00974 
00975 
00981     static void GetQuatPoint(const char *text, HQuat &quat);
00982 
00983     static void GetMatrix(const char *text, float matrix[]);
00984 
00985 
00991     static void ConvertHSFtoMorph(const char *filename, HBaseModel *model);
00992 
00998     static void ConvertHSFtoSegSwitch(const char *filename, HBaseModel *model); 
00999 
01005     static void SetupAnimationReadFromHSF(HStreamFileToolkit *mytool, HBaseModel *model);
01006     
01012     static void SetupAnimationWriteFromHSF(HStreamFileToolkit *mytool, HBaseModel *model);
01013 
01018     static void ShowModellingMatrix(float *segment_modelling_matrix);
01019 
01020     static void MakeCameraKeyframe(HBaseView *view, float timediff, bool targetmode = false);
01021 
01022     static HBhvAnimation* AddAnimation(HBaseModel *model, char *name, char *targetpath, HPoint *pivot);
01023     static void AddPosKeyframe(HBaseModel *model, char *animname, int tick, HPoint pos, bool linear);
01024     static void AddRotKeyframe(HBaseModel *model, char *animname, int tick, HQuat pos, bool linear);
01025     static void AddPosRotKeyframe(HBaseModel *model, const char *animname, int tick, HPoint pivot, float matrix[]);
01026     static void AddMatrixKeyframe(HBaseModel *model, HBhvAnimation *ani, int tick, float matrix[]);
01027 
01028     static void AddPosRotKeyframe(HBaseModel *model, char *animname, int tick, HPoint pos, bool linear, HQuat quat, bool linear2);
01029     static void AddInstanceCreateKeyframe(HBaseModel *model, char *animname, int tick, char *path, char *include_path, char *color);
01030     static void AddSegmentMoveKeyframe(HBaseModel *model, HBhvAnimation *anim, int tick, char *path);
01031 
01032 
01033 
01034 
01035 
01036 private:        
01037     static void Move_Segments_To_Segment(HC_KEY target, HC_KEY destination);
01038     static void AddShellToMorphList(HC_KEY key, struct vlist_s *morph_data_list);       
01039     static bool KeyExists(HC_KEY key, struct vlist_s *morp_data_list);
01040     static void ResetMorphData(struct vlist_s *morp_data_list);
01041     static void CollectShellMorphData(HC_KEY key, struct vlist_s *morp_data_list);
01042     static void ClearAllAttributes(HC_KEY key);
01043     static int searchcounter;
01044 };
01045 
01046 typedef struct
01047 {
01048     HC_KEY segkey;
01049     float *matrix;
01050     HBhvAnimation *anim;
01051     HBhvAnimation *anim2;
01052     int tick;
01053     int tick2;
01054     char *path;
01055 }segmentanimation;
01056 
01057 
01058 class MVO_API HBhvSegmentTracker
01059 {
01060 public:
01061     HBhvSegmentTracker(HBaseModel *model);
01062     void MakeTreeSnapshotRecursive(HC_KEY segkey, HC_KEY newsegkey, MVO_POINTER_SIZED_INT &uid);
01063     void MakeTreeSnapshot();
01064 
01065     HC_KEY m_TrackerKey;
01066     HBaseModel *m_pModel;
01067     struct vhash_s *        m_NewIncludesHash;
01068 };
01069 
01070 class MVO_API HBhvKeyframeGenerator
01071 {
01072 public:
01073     HBhvKeyframeGenerator(HBaseModel * model);
01074 
01075     void NewFrame();
01076     void StartFrames();
01077     
01078     bool CompareMatrices(float *m1, float *m2);
01079 
01080 private:
01081     HBaseModel *m_pModel;
01082     struct vlist_s *        m_Anims;
01083     struct vhash_s *        m_Segments;
01084     int m_AnimCounter;
01085     int m_Tick;
01086     bool m_bFirstFrame;
01087     HBhvSegmentTracker *m_pSegmentTracker;
01088 };
01089 
01090 
01091     
01092 
01093 
01094 #ifdef H_PACK_8
01095 #pragma pack(pop)
01096 #endif
01097 
01098 #endif
01099 
01100 
01101