Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoMultiTextureMatrixElement.h
1 #ifndef COIN_SOMULTITEXTUREMATRIXELEMENT_H
2 #define COIN_SOMULTITEXTUREMATRIXELEMENT_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/elements/SoAccumulatedElement.h>
37 #include <Inventor/SbMatrix.h>
38 
39 class SoMultiTextureMatrixElementP;
40 
43 
44  SO_ELEMENT_HEADER(SoMultiTextureMatrixElement);
45 public:
46  static void initClass(void);
47 protected:
48  virtual ~SoMultiTextureMatrixElement();
49 
50 public:
51  virtual void init(SoState * state);
52  virtual void push(SoState * state);
53  static void set(SoState * const state, SoNode * const node,
54  const int unit,
55  const SbMatrix & matrix);
56  static void mult(SoState * const state, SoNode * const node,
57  const int unit,
58  const SbMatrix & matrix);
59  static const SbMatrix & get(SoState * const state, const int unit = 0);
60 
61  class UnitData {
62  public:
63  UnitData() : textureMatrix(SbMatrix::identity()) {}
64  UnitData(const UnitData & org) : textureMatrix(org.textureMatrix) {}
65  SbMatrix textureMatrix;
66  };
67 
68 protected:
69  int getNumUnits() const;
70  UnitData & getUnitData(const int unit);
71  const UnitData & getUnitData(const int unit) const;
72 
73  virtual void multElt(const int unit, const SbMatrix & matrix);
74  virtual void setElt(const int unit, const SbMatrix & matrix);
75  virtual const SbMatrix & getElt(const int unit) const;
76 
77 private:
78  SoMultiTextureMatrixElementP * pimpl;
79 
80  public: // Coin-3 support
81  static void makeIdentity(SoState * const state, SoNode * const node, const int unit = 0) {
82  set(state, node, unit, SbMatrix::identity());
83  }
84  static void set(SoState * const state, SoNode * const node,
85  const SbMatrix & matrix) {
86  set(state, node, 0, matrix);
87  }
88  static void mult(SoState * const state, SoNode * const node,
89  const SbMatrix & matrix) {
90  mult(state, node, 0, matrix);
91  }
92  static void translateBy(SoState * const state, SoNode * const node,
93  const SbVec3f & translation) {
94  SbMatrix m;
95  m.setTranslate(translation);
96  mult(state, node, 0, m);
97  }
98  static void rotateBy(SoState * const state, SoNode * const node,
99  const SbRotation & rotation) {
100  SbMatrix m;
101  m.setRotate(rotation);
102  mult(state, node, 0, m);
103  }
104  static void scaleBy(SoState * const state, SoNode * const node,
105  const SbVec3f & scaleFactor) {
106  SbMatrix m;
107  m.setScale(scaleFactor);
108  mult(state, node, 0, m);
109  }
110 };
111 
112 #endif // !COIN_SOTEXTUREMATRIXELEMENT_H
void setTranslate(const SbVec3f &t)
Definition: SbMatrix.cpp:890
virtual void init(SoState *state)
Definition: SoAccumulatedElement.cpp:76
The SoNode class is the base class for nodes used in scene graphs.
Definition: SoNode.h:56
SoElement is the abstract base class for all elements.
Definition: SoElement.h:43
void setScale(const float s)
Definition: SbMatrix.cpp:860
The SoState class manages the Coin scenegraph traversal state data.
Definition: SoState.h:44
The SoMultiTextureMatrixElement class is used to manage the texture matrix stack for texture units > ...
Definition: SoMultiTextureMatrixElement.h:41
Definition: SoMultiTextureMatrixElement.h:61
The SbRotation class represents a rotation in 3D space.
Definition: SbRotation.h:44
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition: SbVec3f.h:51
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition: SbMatrix.h:47
static SbMatrix identity(void)
Definition: SbMatrix.cpp:848
The SoAccumulatedElement class is an abstract class for storing accumulated state.
Definition: SoAccumulatedElement.h:39
virtual void push(SoState *state)
Definition: SoAccumulatedElement.cpp:84
void setRotate(const SbRotation &q)
Definition: SbMatrix.cpp:372