0025180: Visualization - Homogeneous transformation API in TKV3d
[occt.git] / src / OpenGl / OpenGl_MatrixState.hxx
CommitLineData
825aa485 1// Created on: 2014-09-30
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _OpenGl_MatrixState_H__
17#define _OpenGl_MatrixState_H__
18
19#include <OpenGl_Vec.hxx>
20#include <NCollection_Vector.hxx>
21
22//! Software implementation for OpenGL matrix stack.
23template<class T>
24class OpenGl_MatrixState
25{
26public:
27
28 //! Constructs matrix state object.
29 OpenGl_MatrixState()
30 : myStack (8),
31 myStackHead (-1)
32 {
33 //
34 }
35
36 //! Pushes current matrix into stack.
37 void Push()
38 {
39 if (++myStackHead >= myStack.Size())
40 {
41 myStack.Append (myCurrent);
42 }
43 else
44 {
45 myStack.SetValue (myStackHead, myCurrent);
46 }
47 }
48
49 //! Pops matrix from stack to current.
50 void Pop()
51 {
52 Standard_ASSERT_RETURN (myStackHead != -1, "Matrix stack already empty when MatrixState.Pop() called.", );
53 myCurrent = myStack.Value (myStackHead--);
54 }
55
56 //! @return current matrix.
57 const typename OpenGl::MatrixType<T>::Mat4& Current()
58 {
59 return myCurrent;
60 }
61
62 //! Sets given matrix as current.
63 void SetCurrent (const typename OpenGl::MatrixType<T>::Mat4& theNewCurrent)
64 {
65 myCurrent = theNewCurrent;
66 }
67
1f7f5a90 68 //! Change current matrix.
69 typename OpenGl::MatrixType<T>::Mat4& ChangeCurrent()
70 {
71 return myCurrent;
72 }
73
825aa485 74 //! Sets given matrix as current.
75 template <typename Other_t>
76 void SetCurrent (const typename OpenGl::MatrixType<Other_t>::Mat4& theNewCurrent)
77 {
78 myCurrent.Convert (theNewCurrent);
79 }
80
81 //! Sets current matrix to identity.
82 void SetIdentity()
83 {
84 myCurrent = typename OpenGl::MatrixType<T>::Mat4();
85 }
86
87private:
88
89 NCollection_Vector<typename OpenGl::MatrixType<T>::Mat4> myStack; //!< Collection used to maintenance matrix stack
90 typename OpenGl::MatrixType<T>::Mat4 myCurrent; //!< Current matrix
91 Standard_Integer myStackHead; //!< Index of stack head
92};
93
94#endif // _OpenGl_MatrixState_H__