eng_object.hh

Go to the documentation of this file.
00001 /*
00008  * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
00009  *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
00010  *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
00011  *****************************************************************************/
00012 
00013 #ifndef ENG_OBJECT_HH
00014 #define ENG_OBJECT_HH 1
00015 
00016 namespace eng {
00017 
00018 #define CHECK_OBJECT() {{ CHECK_TYPESIG(this,TYPESIG_OBJECT); CHECK_TYPESIG(this,TYPESIG_SHARED); }}
00019 
00035 class Object : public Shared
00036 {
00037 
00038 friend class VisitorDraw;
00039 
00040 //------------------------------------------------------------------------------
00041 // Interface:
00042 // Construction, identity:
00043 public:                             Object( SharedPtr<Graph> graph, const WorldVertex& pos, SharedPtr0<Volume> volume = NULL );
00044 protected:                          Object( shptr<Graph> graph );  // doesn't attach to World (limited use)
00045 public:     virtual                 ~Object();
00046 public:     virtual void            PostConstruct( void );
00047 public:     virtual void            SelfDestruct( void );
00048 public:     virtual bool            Reproducible( void ) = 0;
00049 public:     virtual bool            IfTranslucent( void ) { return false; }
00050 public:     virtual const string    GetName( void ) = 0;
00051 
00052 // Drawing:
00053 public:     virtual void            Draw( void );
00054 
00055 // Spatial:
00056 public:     virtual void            SetPosition( const WorldVertex& position )
00057                                     { SetPosition_( position, false ); }
00058 private:    void                    SetPosition_( const WorldVertex& position, const bool initial );
00059 public:     virtual WorldVertex     GetPosition( void )
00060                                     { CHECK_OBJECT(); CHECK_POSITION();
00061                                       return mPosition; }
00062 public:     virtual SharedPtr0<Volume>  GetWorldVolume( void )
00063                                     { CHECK_OBJECT(); return mWorldVolume; }
00064 public:     fp                      GetRadius( void ) { return mRadius; }
00065 private:    void                    ComputeVolume( void );
00066 
00067 // Geometry:
00068 public:     SharedPtr<Graph>            GetGraph( void )
00069                                     { CHECK_OBJECT(); return mGraph; }
00070 
00071 // Transformation:
00072 public:     virtual SharedPtr<const Matrix> GetMatrix( void )
00073                                     { CHECK_OBJECT(); return mTransformNode->GetMatrix().PTR(); }
00074 public:     virtual void            SetMatrix( const Matrix& matrix );
00075 public:     SharedPtr0<TransformNode>   GetTransformNode( void )
00076                                     { CHECK_OBJECT(); return mTransformNode; }
00077 protected:  void                    SetRecomputeNormals( void );
00078 
00079 // Collidable/indestructible:
00080 public:     void                    SetCollidable( bool collidable );
00081 
00082 // Info:
00083 public:     CLASS_METHOD int        GetObjectCnt( void ) { return msObjectCnt; }
00084 private:    CLASS_VAR int           msObjectCnt;
00085 
00086 //------------------------------------------------------------------------------
00087 // Private implementation:
00088 private:
00090     class VisitorComputeVolume : public Visitor
00091     {
00092     public:
00093         VisitorComputeVolume( Graph& graph );
00094         void            Visit( TransformNode& node );
00095         void            Visit( VertexsNode& node );
00096         void            End( void );
00097         // Results from visiting:
00098         SharedPtr0<Volume>  GetWorldVolume( void );
00099         fp              GetRadius( void );
00100     private:
00101         Matrix              mMatrix;
00102         SharedPtr0<BoxVolume>   mBoxVolume;
00103         bool                mVolumeValid;
00104     };
00105 
00106 #if DEBUG
00107     void CHECK_POSITION( void );
00108 #else
00109     void CHECK_POSITION( void ) { }
00110 #endif
00111 
00112 //------------------------------------------------------------------------------
00113 // Data:
00114 //
00115 // Object position:
00116 // Object position is defined across Matrix origin, center of world Volume, and mPosition.
00117 // The true definition of position is the Matrix origin,
00118 // the others should be assigned from it and stay synchronized.
00119 
00120 protected:  SharedPtr<Graph>        mGraph;
00121 protected:  TransformNode::Ptr  mTransformNode;
00122 protected:  shptr0<Volume>      mWorldVolume;  
00123 protected:  fp                  mRadius;
00124 protected:  WorldVertex         mPosition;  
00125 #if DEBUG
00126 private:    bool                mDebugChangingPosition;  
00127 #endif
00128 public:     
00129 };
00130 
00131 } // namespace eng
00132 
00133 #endif // ENG_OBJECT_HH
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:09 2007