File indexing completed on 2025-01-18 10:04:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _OpenGl_MatrixState_H__
0017 #define _OpenGl_MatrixState_H__
0018
0019 #include <OpenGl_Vec.hxx>
0020 #include <NCollection_Vector.hxx>
0021 #include <Standard_Dump.hxx>
0022
0023
0024 template<class T>
0025 class OpenGl_MatrixState
0026 {
0027 public:
0028
0029
0030 OpenGl_MatrixState()
0031 : myStack (8),
0032 myStackHead (-1)
0033 {
0034
0035 }
0036
0037
0038 void Push()
0039 {
0040 if (++myStackHead >= myStack.Size())
0041 {
0042 myStack.Append (myCurrent);
0043 }
0044 else
0045 {
0046 myStack.SetValue (myStackHead, myCurrent);
0047 }
0048 }
0049
0050
0051 void Pop()
0052 {
0053 Standard_ASSERT_RETURN (myStackHead != -1, "Matrix stack already empty when MatrixState.Pop() called.", );
0054 myCurrent = myStack.Value (myStackHead--);
0055 }
0056
0057
0058 const typename OpenGl::MatrixType<T>::Mat4& Current()
0059 {
0060 return myCurrent;
0061 }
0062
0063
0064 void SetCurrent (const typename OpenGl::MatrixType<T>::Mat4& theNewCurrent)
0065 {
0066 myCurrent = theNewCurrent;
0067 }
0068
0069
0070 typename OpenGl::MatrixType<T>::Mat4& ChangeCurrent()
0071 {
0072 return myCurrent;
0073 }
0074
0075
0076 template <typename Other_t>
0077 void SetCurrent (const typename OpenGl::MatrixType<Other_t>::Mat4& theNewCurrent)
0078 {
0079 myCurrent.Convert (theNewCurrent);
0080 }
0081
0082
0083 void SetIdentity()
0084 {
0085 myCurrent = typename OpenGl::MatrixType<T>::Mat4();
0086 }
0087
0088
0089 void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
0090 {
0091 (void)theDepth;
0092 OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "myCurrent", 16,
0093 myCurrent.GetValue (0, 0), myCurrent.GetValue (0, 1), myCurrent.GetValue (0, 2), myCurrent.GetValue (0, 3),
0094 myCurrent.GetValue (1, 0), myCurrent.GetValue (1, 1), myCurrent.GetValue (1, 2), myCurrent.GetValue (1, 3),
0095 myCurrent.GetValue (2, 0), myCurrent.GetValue (2, 1), myCurrent.GetValue (2, 2), myCurrent.GetValue (2, 3),
0096 myCurrent.GetValue (3, 0), myCurrent.GetValue (3, 1), myCurrent.GetValue (3, 2), myCurrent.GetValue (3, 3))
0097
0098 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myStack.Size())
0099 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myStackHead)
0100 }
0101
0102 private:
0103
0104 NCollection_Vector<typename OpenGl::MatrixType<T>::Mat4> myStack;
0105 typename OpenGl::MatrixType<T>::Mat4 myCurrent;
0106 Standard_Integer myStackHead;
0107 };
0108
0109 #endif