00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include <stack>
00018 #include "nvmath/Mat44f.h"
00019
00020 namespace nvutil
00021 {
00023
00039 class TransformStack
00040 {
00041 public:
00043
00044 TransformStack();
00045
00046 public:
00048 NVSG_API const nvmath::Mat44f getClipToModel( void ) const;
00049
00051 NVSG_API const nvmath::Mat44f & getClipToView( void ) const;
00052
00054 NVSG_API const nvmath::Mat44f getModelToClip( void ) const;
00055
00057 NVSG_API const nvmath::Mat44f getModelToView( void ) const;
00058
00060 NVSG_API const nvmath::Mat44f & getModelToWorld( void ) const;
00061
00063 NVSG_API const nvmath::Mat44f & getViewToClip( void ) const;
00064
00066 NVSG_API const nvmath::Mat44f getViewToModel( void ) const;
00067
00069 NVSG_API const nvmath::Mat44f & getViewToWorld( void ) const;
00070
00072 NVSG_API const nvmath::Mat44f & getWorldToModel( void ) const;
00073
00075 NVSG_API const nvmath::Mat44f & getWorldToView( void ) const;
00076
00078 NVSG_API size_t getStackDepth( void ) const;
00079
00081 NVSG_API void popModelToWorld( void );
00082
00084
00085 NVSG_API void pushModelToWorld( const nvmath::Mat44f &modelWorld
00086 , const nvmath::Mat44f &worldModel
00087 );
00088
00090
00091 NVSG_API void setViewToClip( const nvmath::Mat44f &viewClip
00092 , const nvmath::Mat44f &clipView
00093 );
00094
00096
00097 NVSG_API void setWorldToView( const nvmath::Mat44f &worldView
00098 , const nvmath::Mat44f &viewWorld
00099 );
00100
00101 private :
00102 std::stack<nvmath::Mat44f> m_modelWorld;
00103 std::stack<nvmath::Mat44f> m_worldModel;
00104 nvmath::Mat44f m_worldView;
00105 nvmath::Mat44f m_viewWorld;
00106 nvmath::Mat44f m_viewClip;
00107 nvmath::Mat44f m_clipView;
00108 };
00109
00110
00111 inline TransformStack::TransformStack()
00112 {
00113 m_modelWorld.push( nvmath::cIdentity44f );
00114 m_worldModel.push( nvmath::cIdentity44f );
00115 }
00116
00117 inline const nvmath::Mat44f TransformStack::getClipToModel( void ) const
00118 {
00119 return( m_worldModel.top() * m_viewWorld * m_clipView );
00120 }
00121
00122 inline const nvmath::Mat44f & TransformStack::getClipToView( void ) const
00123 {
00124 return( m_clipView );
00125 }
00126
00127 inline const nvmath::Mat44f TransformStack::getModelToClip( void ) const
00128 {
00129 return( m_viewClip * m_worldView * m_modelWorld.top() );
00130 }
00131
00132 inline const nvmath::Mat44f TransformStack::getModelToView( void ) const
00133 {
00134 return( m_worldView * m_modelWorld.top() );
00135 }
00136
00137 inline const nvmath::Mat44f & TransformStack::getModelToWorld( void ) const
00138 {
00139 return( m_modelWorld.top() );
00140 }
00141
00142 inline const nvmath::Mat44f & TransformStack::getViewToClip( void ) const
00143 {
00144 return( m_viewClip );
00145 }
00146
00147 inline const nvmath::Mat44f TransformStack::getViewToModel( void ) const
00148 {
00149 return( m_worldModel.top() * m_viewWorld );
00150 }
00151
00152 inline const nvmath::Mat44f & TransformStack::getViewToWorld( void ) const
00153 {
00154 return( m_viewWorld );
00155 }
00156
00157 inline const nvmath::Mat44f & TransformStack::getWorldToModel( void ) const
00158 {
00159 return( m_worldModel.top() );
00160 }
00161
00162 inline const nvmath::Mat44f & TransformStack::getWorldToView( void ) const
00163 {
00164 return( m_worldView );
00165 }
00166
00167 inline size_t TransformStack::getStackDepth( void ) const
00168 {
00169 __ASSERT( m_modelWorld.size() == m_worldModel.size() );
00170 return( m_modelWorld.size() );
00171 }
00172
00173 inline void TransformStack::popModelToWorld( void )
00174 {
00175 m_modelWorld.pop();
00176 m_worldModel.pop();
00177 }
00178
00179 inline void TransformStack::pushModelToWorld( const nvmath::Mat44f &modelWorld, const nvmath::Mat44f &worldModel )
00180 {
00181 m_modelWorld.push( m_modelWorld.top() * modelWorld );
00182 m_worldModel.push( worldModel * m_worldModel.top() );
00183 }
00184
00185 inline void TransformStack::setViewToClip( const nvmath::Mat44f &viewClip, const nvmath::Mat44f &clipView )
00186 {
00187 m_viewClip = viewClip;
00188 m_clipView = clipView;
00189 }
00190
00191 inline void TransformStack::setWorldToView( const nvmath::Mat44f &worldView, const nvmath::Mat44f &viewWorld )
00192 {
00193 m_worldView = worldView;
00194 m_viewWorld = viewWorld;
00195 }
00196 }