Gizmo3D

gzTransform.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzTransform.h
00003 // Module       : 
00004 // Description  : Class definition of the gzTransform class
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  981122  Created file    
00020 // LJH  041019  Added online comments
00021 //
00022 //******************************************************************************
00023 #ifndef __GZ_TRANSFORM_H__
00024 #define __GZ_TRANSFORM_H__
00025 
00032 #include "gzGroup.h"
00033 
00034 //******************************************************************************
00035 // Class    : gzTransform
00036 //                                  
00037 // Purpose  : -
00038 //                                  
00039 // Notes    : - 
00040 //                                  
00041 // Revision History...                          
00042 //                                  
00043 // Who  Date    Description                     
00044 //                                  
00045 // AMO  981209  Created 
00046 //                                  
00047 //******************************************************************************
00049 class gzTransform : public gzGroup 
00050 {
00051 public:
00053 
00054     GZ_GRAPH_EXPORT gzTransform(const gzString & name=GZ_EMPTY_STRING);
00056     GZ_GRAPH_EXPORT virtual ~gzTransform(){};
00057 
00058     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00059 
00060 
00061     // ---------- Clone interface ---------------------------------------
00063     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00064 
00065     // ---------- Common Transform functions ----------------------------
00066 
00068 
00072     GZ_GRAPH_EXPORT virtual gzVoid updateNode();
00073 
00075 
00078     GZ_GRAPH_EXPORT gzVoid  reset(gzBool resetTransform=TRUE,gzBool resetAxis=FALSE);   
00079 
00080     
00082 
00085     GZ_GRAPH_EXPORT gzBool  isActive();
00086 
00088 
00092     GZ_GRAPH_EXPORT gzVoid  useAccumulatedTransform(gzBool on);
00093 
00095     GZ_GRAPH_EXPORT gzBool  useAccumulatedTransform() const;
00096 
00103     GZ_GRAPH_EXPORT gzVoid  setBaseID(gzULong id=0);
00107     GZ_GRAPH_EXPORT gzULong getBaseID();
00108 
00109     // ---------- additive commands -------------------------------------
00110 
00111     // Note that additive commands are reset by absolute commands
00112 
00113     //* Rotation about the vector specified in degrees
00116     GZ_GRAPH_EXPORT gzVoid  rotate(const gzVec3 &vector , gzReal rotation); 
00117 
00118     GZ_GRAPH_EXPORT gzVoid  rotateHPR(gzReal heading , gzReal pitch , gzReal roll);
00119 
00125     GZ_GRAPH_EXPORT gzVoid  translate( gzReal dx , gzReal dy , gzReal dz ); 
00131     GZ_GRAPH_EXPORT gzVoid  scale( gzReal sx , gzReal sy , gzReal sz ); 
00137     GZ_GRAPH_EXPORT gzVoid  scale( gzReal s); 
00138     /*
00139     Scale the transform to the unit 1. The bounding sphere gets a radius of size SQRT(2).
00140     */
00141     GZ_GRAPH_EXPORT gzVoid  unitScale();
00142 
00143     // ---------- absolute commands -------------------------------------
00144     
00146 
00150     GZ_GRAPH_EXPORT gzVoid  setDirection(const gzVec3 &targetvector, gzReal roll , const gzVec3 &up=gzVec3(0,1,0));
00152 
00159     GZ_GRAPH_EXPORT gzVoid  setRotation(const gzVec3 &targetvector, gzReal rotation);
00160 
00162 
00166     GZ_GRAPH_EXPORT gzVoid  setHPR( gzReal heading , gzReal pitch , gzReal roll);
00167 
00169 
00176     GZ_GRAPH_EXPORT gzVoid  setTranslation( gzReal dx , gzReal dy , gzReal dz );
00178 
00185     GZ_GRAPH_EXPORT gzVoid  setScale( gzReal sx , gzReal sy , gzReal sz );
00186 
00188     GZ_GRAPH_EXPORT gzVoid  setScale( gzReal s );
00189 
00191 
00195     GZ_GRAPH_EXPORT gzVoid  setOrigin( gzReal ox , gzReal oy , gzReal oz , gzBool updateAbsolute=TRUE);
00196 
00198 
00201     GZ_GRAPH_EXPORT gzVoid  setBaseAxis( const gzVec3 &x_axis , const gzVec3 &y_axis , const gzVec3 &z_axis , gzBool updateAbsolute=TRUE);
00202 
00203     
00204     // ---------- vector variants ---------------------------------------
00205     
00207 
00214     GZ_GRAPH_EXPORT gzVoid  setTranslation( const gzVec3 &xyz_trans );
00216 
00223     GZ_GRAPH_EXPORT gzVoid  setScale(       const gzVec3 &xyz_scale );
00224 
00226 
00230     GZ_GRAPH_EXPORT gzVoid  setOrigin(      const gzVec3 &xyz_origin , gzBool updateAbsolute=TRUE);
00231 
00233 
00237     GZ_GRAPH_EXPORT gzVoid  setHPR(         const gzVec3 &xyz_hpr );
00238 
00239     // ---------- get data commands -------------------------------------
00240 
00246     GZ_GRAPH_EXPORT gzBool  getScale( gzReal &sx , gzReal &sy , gzReal &sz );
00250     GZ_GRAPH_EXPORT gzBool  hasScale();
00251 
00256     GZ_GRAPH_EXPORT gzBool  getHPR(gzReal &heading , gzReal &pitch , gzReal &roll);
00257     
00261     GZ_GRAPH_EXPORT gzBool  hasHPR();
00262 
00268     GZ_GRAPH_EXPORT gzBool  getTranslation( gzReal &dx , gzReal &dy , gzReal &dz );
00272     GZ_GRAPH_EXPORT gzBool  hasTranslation();
00273 
00274     GZ_GRAPH_EXPORT gzBool  getOrigin( gzReal &ox , gzReal &oy , gzReal &oz );
00275     GZ_GRAPH_EXPORT gzBool  hasOrigin();
00276 
00277     GZ_GRAPH_EXPORT gzBool  getBaseAxis( gzVec3 &x_axis , gzVec3 &y_axis , gzVec3 &z_axis );
00278     GZ_GRAPH_EXPORT gzBool  hasBaseAxis();
00279 
00280     // ---------- vector variants ---------------------------------------
00281 
00287     GZ_GRAPH_EXPORT gzBool  getTranslation( gzVec3 &translation );
00288 
00289     // ---------- direct transform manipulation ------------------------
00290 
00292     GZ_GRAPH_EXPORT gzMatrix4 & getTransform();
00294 
00297     GZ_GRAPH_EXPORT gzVoid      setTransform(const gzMatrix4 &transform);
00298 
00300     GZ_GRAPH_EXPORT gzVoid      accumulate(const gzMatrix4 &mulTransform);
00301 
00302 
00303     // ----------- tweak the scale radius for bounding spheres
00304 
00313     GZ_GRAPH_EXPORT gzVoid      setMaxScale(const gzReal &maxScale);
00314     
00316     GZ_GRAPH_EXPORT gzReal      getMaxScale();
00317 
00319 
00322     GZ_GRAPH_EXPORT static gzVoid   setCurrentMaxScale( gzContext *context , gzReal scale );
00323 
00325 
00329     GZ_GRAPH_EXPORT static gzMatrix4 & getCurrentInvertedTransform(gzContext *context);
00330     
00332 
00335     GZ_GRAPH_EXPORT static gzVoid   resetIndex(gzContext *context);
00336 
00338 
00341     GZ_GRAPH_EXPORT static gzVoid   resetPostIndex( gzContext *context );
00342 
00344 
00347     GZ_GRAPH_EXPORT static gzVoid   activateIndex(gzContext *context , gzULong index);
00348 
00350 
00353     GZ_GRAPH_EXPORT static gzVoid   activateCompiledIndex(gzContext *context , gzULong index);
00354 
00355 
00356     // ---------- Action Interface --------------------------------------
00357     
00359     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00360     
00362     GZ_GRAPH_EXPORT virtual gzVoid postTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00363 
00364         // ---------- Serializing -------------------------------------------
00365 
00367     GZ_GRAPH_EXPORT virtual gzVoid write(gzSerializeAdapter *adapter);
00368     
00370     GZ_GRAPH_EXPORT virtual gzVoid read(gzSerializeAdapter *adapter);
00371     
00373 
00376     GZ_GRAPH_EXPORT virtual gzULong getDataSize(gzSerializeAdapter *adapter) const;
00377 
00378     // ---------- Debug function ----------------------------------------
00380 
00383     GZ_GRAPH_EXPORT virtual gzVoid  debugOutput(gzString base , gzString anchor , gzDebugFlags features);
00384 
00385     // --------- Utilties -----------------------------------------------
00387 
00390     GZ_GRAPH_EXPORT static gzTransform * getClosestTransform(gzNode *node);
00391     
00393 
00398     GZ_GRAPH_EXPORT static gzMatrix4 getAccumTransform(gzNode *node);
00399 
00400 
00401 protected:
00402 
00403     GZ_GRAPH_EXPORT gzVoid calculateTransform();
00404     GZ_GRAPH_EXPORT gzVoid calculateMaxScale();
00405 
00406     gzMatrix4               m_transformMatrix;
00407     gzReal                  m_maxScale;
00408 
00409     gzLateBindData<gzVec3>      m_orientation;
00410     gzLateBindData<gzVec3>      m_scale;
00411     gzLateBindData<gzVec3>      m_translation;
00412     gzLateBindData<gzVec3>      m_origo;
00413     gzLateBindData<gzMatrix3>   m_base;
00414 
00415     gzULong                     m_baseID;
00416 
00417     gzUByte                 m_accum:1;
00418     gzUByte                 m_isActive:1;
00419 
00420 };
00421 
00422 // Declare smart pointer type
00423 GZ_DECLARE_REFPTR(gzTransform);
00424 
00425 //******************************************************************************
00426 // Class    : gzFrameTransformKeyTranslation
00427 //                                  
00428 // Purpose  : -
00429 //                                  
00430 // Notes    : - 
00431 //                                  
00432 // Revision History...                          
00433 //                                  
00434 // Who  Date    Description                     
00435 //                                  
00436 // AMO  981209  Created 
00437 //                                  
00438 //******************************************************************************
00440 class gzFrameTransformKeyTranslation : public gzReference
00441 {
00442 public:
00444     GZ_GRAPH_EXPORT gzFrameTransformKeyTranslation();
00445 
00447     GZ_GRAPH_EXPORT virtual ~gzFrameTransformKeyTranslation();
00448     
00449     // ---------- Clone interface ---------------------------------------
00451     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00452 
00453 private:
00454     friend class gzFrameTransform;
00455 
00456     gzULong m_frame;
00457     gzVec3  m_position;
00458 };
00459 
00460 //******************************************************************************
00461 // Class    : gzFrameTransformKeyScale
00462 //                                  
00463 // Purpose  : -
00464 //                                  
00465 // Notes    : - 
00466 //                                  
00467 // Revision History...                          
00468 //                                  
00469 // Who  Date    Description                     
00470 //                                  
00471 // AMO  981209  Created 
00472 //                                  
00473 //******************************************************************************
00475 class gzFrameTransformKeyScale : public gzReference
00476 {
00477 public:
00478 
00480     GZ_GRAPH_EXPORT gzFrameTransformKeyScale();
00481 
00483     GZ_GRAPH_EXPORT virtual ~gzFrameTransformKeyScale();
00484 
00485     // ---------- Clone interface ---------------------------------------
00487     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00488 
00489 private:
00490     friend class gzFrameTransform;
00491 
00492     gzULong m_frame;
00493     gzVec3  m_scale;
00494 };
00495 
00496 //******************************************************************************
00497 // Class    : gzFrameTransformKeyRotation
00498 //                                  
00499 // Purpose  : -
00500 //                                  
00501 // Notes    : - 
00502 //                                  
00503 // Revision History...                          
00504 //                                  
00505 // Who  Date    Description                     
00506 //                                  
00507 // AMO  981209  Created 
00508 //                                  
00509 //******************************************************************************
00511 class gzFrameTransformKeyRotation : public gzReference
00512 {
00513 public:
00515     GZ_GRAPH_EXPORT gzFrameTransformKeyRotation();
00516 
00518     GZ_GRAPH_EXPORT virtual ~gzFrameTransformKeyRotation();
00519 
00520     // ---------- Clone interface ---------------------------------------
00522     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00523 
00524 private:
00525     friend class gzFrameTransform;
00526 
00527     gzULong m_frame;
00528     
00529     gzMatrix4 m_accumRot;
00530 
00531 
00532     gzVec3  m_rotVector;
00533     gzReal  m_angle;
00534 };
00535 
00536 //******************************************************************************
00537 // Class    : gzFrameTransform
00538 //                                  
00539 // Purpose  : Frame programmable transforms
00540 //                                  
00541 // Notes    : - 
00542 //                                  
00543 // Revision History...                          
00544 //                                  
00545 // Who  Date    Description                     
00546 //                                  
00547 // AMO  981209  Created 
00548 //                                  
00549 //******************************************************************************
00551 
00555 class gzFrameTransform : public gzTransform
00556 {
00557 public:
00559 
00566     GZ_GRAPH_EXPORT gzFrameTransform(const gzString & name=GZ_EMPTY_STRING);
00568     GZ_GRAPH_EXPORT virtual ~gzFrameTransform(){};
00569 
00570     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00571 
00573     GZ_GRAPH_EXPORT gzFrameTransform(const gzFrameTransform &copy);
00574     
00576     GZ_GRAPH_EXPORT gzFrameTransform & operator=(const gzFrameTransform &copy);
00577 
00578     // ---------- Common graph functions --------------------------------
00579 
00581 
00585     GZ_GRAPH_EXPORT virtual gzVoid updateNode();
00586 
00587     // ---------- Clone interface ---------------------------------------
00589     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00590 
00591     // ---------- Action Interface --------------------------------------
00592 
00594     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00595 
00596     // ---------- gzFrameTransform Interface ----------------------------
00597     
00599     GZ_GRAPH_EXPORT gzULong getStartFrame();
00601     GZ_GRAPH_EXPORT gzULong getLastFrame();
00603     GZ_GRAPH_EXPORT gzBool  hasFrames();
00604 
00606 
00609     GZ_GRAPH_EXPORT gzMatrix4 getFrameTransform(gzULong frame );
00610 
00612     GZ_GRAPH_EXPORT gzVoid setFrameTranslation(gzULong frame , gzReal x , gzReal y , gzReal z ); 
00613     
00615     GZ_GRAPH_EXPORT gzVoid setFrameScale(gzULong frame , gzReal sx , gzReal sy , gzReal sz ); 
00616     
00618     GZ_GRAPH_EXPORT gzVoid setFrameRotation(gzULong frame , const gzVec3 &vector , gzReal angle); 
00619 
00621 
00627     GZ_GRAPH_EXPORT gzVoid setFrameHPR(gzULong frame , gzReal heading , gzReal pitch , gzReal roll , const gzVec3 &base=GZ_ONE_VEC3);
00628     
00630 
00633     GZ_GRAPH_EXPORT gzVoid setFrameRotateTransform(gzULong frame , const gzMatrix4 & transform);
00634 
00636     GZ_GRAPH_EXPORT gzBool getFrameTranslation(gzULong frame , gzReal &x , gzReal &y , gzReal &z ); 
00637     
00639     GZ_GRAPH_EXPORT gzBool getFrameScale(gzULong frame , gzReal &x , gzReal &y , gzReal &z ); 
00640     
00642     GZ_GRAPH_EXPORT gzBool getFrameRotation(gzULong frame , gzVec3 &vector , gzReal &angle); 
00643 
00645     GZ_GRAPH_EXPORT gzULong getStartTranslationFrame();
00646     
00648     GZ_GRAPH_EXPORT gzULong getLastTranslationFrame();
00649     
00651     GZ_GRAPH_EXPORT gzBool  hasTranslationFrames();
00652 
00653 
00655     GZ_GRAPH_EXPORT gzULong getStartScaleFrame();
00656     
00658     GZ_GRAPH_EXPORT gzULong getLastScaleFrame();
00659     
00661     GZ_GRAPH_EXPORT gzBool  hasScaleFrames();
00662 
00663 
00665     GZ_GRAPH_EXPORT gzULong getStartRotationFrame();
00666     
00668     GZ_GRAPH_EXPORT gzULong getLastRotationFrame();
00669     
00671     GZ_GRAPH_EXPORT gzBool  hasRotationFrames();
00672     
00673 
00675     GZ_GRAPH_EXPORT gzVoid calculateRotations();
00676 
00678 
00681     GZ_GRAPH_EXPORT gzVoid setAccumulativeRotations(gzBool on=TRUE);
00682 
00684     GZ_GRAPH_EXPORT gzVoid enableFrameUpdates(gzBool on=TRUE);
00685 
00686 private:
00687 
00688     gzBoundary getFrameBoundary(gzULong frame);
00689 
00690     gzRefDList<gzFrameTransformKeyTranslation>  m_keyListTranslation;
00691     gzRefDList<gzFrameTransformKeyScale>        m_keyListScale;
00692     gzRefDList<gzFrameTransformKeyRotation>     m_keyListRotation;
00693 
00694     gzDListIterator<gzFrameTransformKeyTranslation> m_currentKeyTranslation;
00695     gzDListIterator<gzFrameTransformKeyScale>       m_currentKeyScale;
00696     gzDListIterator<gzFrameTransformKeyRotation>    m_currentKeyRotation;
00697 
00698     gzDListIterator<gzFrameTransformKeyTranslation> m_currentNextKeyTranslation;
00699     gzDListIterator<gzFrameTransformKeyScale>       m_currentNextKeyScale;
00700     gzDListIterator<gzFrameTransformKeyRotation>    m_currentNextKeyRotation;
00701 
00702 
00703     gzFrameTransformKeyTranslation  *getKeyTranslation(gzULong frame);
00704     gzFrameTransformKeyScale        *getKeyScale(gzULong frame);
00705     gzFrameTransformKeyRotation     *getKeyRotation(gzULong frame);
00706 
00707     gzFrameTransformKeyTranslation  *getNextKeyTranslation(gzULong frame);
00708     gzFrameTransformKeyScale        *getNextKeyScale(gzULong frame);
00709     gzFrameTransformKeyRotation     *getNextKeyRotation(gzULong frame);
00710 
00711     gzBool  m_accumRotations;
00712     gzBool  m_isFrameUpdateEnabled;
00713 };
00714 
00715 
00716 //******************************************************************************
00717 // Class    : gzTransformBase
00718 //                                  
00719 // Purpose  : reset the base id and the base id count for transforms
00720 //                                  
00721 // Notes    : - 
00722 //                                  
00723 // Revision History...                          
00724 //                                  
00725 // Who  Date    Description                     
00726 //                                  
00727 // AMO  040803  Created 
00728 //                                  
00729 //******************************************************************************
00731 
00735 class gzTransformBase : public gzGroup
00736 {
00737 public:
00739 
00742     GZ_GRAPH_EXPORT gzTransformBase(const gzString & name=GZ_EMPTY_STRING);
00744     GZ_GRAPH_EXPORT virtual ~gzTransformBase(){};
00745 
00746     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00747 
00748     // ---------- Clone interface ---------------------------------------
00750     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00751 
00752     // ---------- Action Interface --------------------------------------
00753 
00755     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00756 
00758     GZ_GRAPH_EXPORT virtual gzVoid postTraverseAction( gzTraverseAction *actionclass , gzContext *context);
00759 
00760     // ---------- Render control -----------------------------------------------
00762 
00765     GZ_GRAPH_EXPORT static gzVoid activateIndex( gzContext *context , gzULong index);
00766 
00768 
00771     GZ_GRAPH_EXPORT static gzVoid resetIndex( gzContext *context );
00772 
00773 
00774     // ---------- Interface ----------------------------------------------------
00775 
00777     GZ_GRAPH_EXPORT gzVoid  setNumberOfBases(gzULong count=0);
00778 
00780     GZ_GRAPH_EXPORT gzULong getNumberOfBases();
00781 
00782 private:
00783 
00784     gzULong     m_numberOfBases;
00785 };
00786 
00787 
00788 //******************************************************************************
00789 // Class    : gzTransformID
00790 //                                  
00791 // Purpose  : Used by the gzBaseTransform to keep track of transform IDs
00792 //                                  
00793 // Notes    : - 
00794 //                                  
00795 // Revision History...                          
00796 //                                  
00797 // Who  Date    Description                     
00798 //                                  
00799 // AMO  040803  Created 
00800 //                                  
00801 //******************************************************************************
00803 class gzTransformID
00804 {
00805 public:
00806 
00807     gzTransformID():currentTransformIndex(0),
00808                     numberOfBases(0),
00809                     accumTransformChecksum(0),
00810                     transformChecksum(0),
00811                     currentTransformChecksum(0),
00812                     changedMatrix(TRUE),
00813                     hasNormal(FALSE){};
00814     
00815     gzULong     currentTransformIndex;
00816     gzULong     numberOfBases;
00817     gzULong     accumTransformChecksum;
00818     gzULong     transformChecksum;
00819     gzULong     currentTransformChecksum;
00820 
00821     gzBool      changedMatrix;
00822     gzBool      hasNormal;
00823     
00824 
00825     gzMatrix4   mat;
00826     gzMatrix4   norm;
00827 };
00828 
00829 #endif

Documentation for Gizmo3D generated at Wed Feb 20 11:54:12 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond